2019-09-05 22:42:08 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2019-09-08 17:07:47 +08:00
|
|
|
# extra.py: Automatic management tool for an arch repo.
|
|
|
|
# This file is part of Buildbot by JerryXiao
|
|
|
|
|
2019-09-05 22:42:08 +08:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
2019-09-08 17:07:47 +08:00
|
|
|
from pathlib import Path
|
2019-09-05 22:42:08 +08:00
|
|
|
from utils import print_exc_plus
|
|
|
|
|
2019-09-08 17:07:47 +08:00
|
|
|
from config import PKGBUILD_DIR, MAIN_LOGFILE, CONSOLE_LOGFILE, \
|
|
|
|
PKG_UPDATE_LOGFILE, MAKEPKG_LOGFILE
|
|
|
|
|
2019-09-05 22:42:08 +08:00
|
|
|
logger = logging.getLogger(f'buildbot.{__name__}')
|
|
|
|
|
|
|
|
abspath=os.path.abspath(__file__)
|
|
|
|
abspath=os.path.dirname(abspath)
|
|
|
|
os.chdir(abspath)
|
2019-09-08 17:07:47 +08:00
|
|
|
|
|
|
|
REPO_ROOT = Path(PKGBUILD_DIR)
|
|
|
|
|
|
|
|
# generate package list
|
|
|
|
def gen_pkglist(pkgconfigs, pkgvers, pkgerrs):
|
|
|
|
# pkgall contains details
|
|
|
|
# namelist is a list of pkgnames
|
|
|
|
pkgall = dict()
|
|
|
|
for pc in pkgconfigs:
|
|
|
|
ps = ('type', 'cleanbuild', 'timeout')
|
|
|
|
hps = ('prebuild', 'postbuild', 'update', 'failure')
|
|
|
|
dps = {p:getattr(pc, p, None) for p in ps}
|
|
|
|
dhps = {p:'\n'.join(str(getattr(pc, p, None))) for p in hps}
|
|
|
|
# additional package details
|
|
|
|
ves = {'version': pkgvers.get(pc.dirname, None), 'errors': pkgerrs.get(pc.dirname, None)}
|
|
|
|
pkgall[pc.dirname] = {**dps, **dhps, **ves}
|
|
|
|
namelist = [k for k in pkgall]
|
|
|
|
return (namelist, pkgall)
|
|
|
|
|
|
|
|
def __simpleread(fpath, limit=4096-100):
|
|
|
|
with open(fpath, 'r') as f:
|
|
|
|
c = f.read()
|
|
|
|
if len(c) > limit:
|
|
|
|
c = c[-limit:]
|
|
|
|
return c
|
|
|
|
# read logs
|
|
|
|
def readpkglog(pkgdirname, update=False):
|
|
|
|
cwd = REPO_ROOT / pkgdirname
|
|
|
|
logfile = PKG_UPDATE_LOGFILE if update else MAKEPKG_LOGFILE
|
|
|
|
if cwd.exists() and (cwd / logfile).exists():
|
|
|
|
logger.debug(f'formatting {"update" if update else "build"} logs in {pkgdirname}')
|
|
|
|
return __simpleread(cwd / logfile)
|
|
|
|
else:
|
|
|
|
logger.debug(f'not found: {"update" if update else "build"} log in dir {pkgdirname}')
|
|
|
|
return f"{cwd / logfile} cannot be found"
|
|
|
|
def readmainlog(debug=False):
|
|
|
|
logfile = MAIN_LOGFILE if debug else CONSOLE_LOGFILE
|
2019-09-08 19:05:09 +08:00
|
|
|
if (Path('.') / logfile).exists():
|
2019-09-08 17:07:47 +08:00
|
|
|
logger.debug(f'formatting buildbot{" debug" if debug else ""} logs')
|
2019-09-08 19:05:09 +08:00
|
|
|
return __simpleread(Path('.') / logfile)
|
2019-09-08 17:07:47 +08:00
|
|
|
else:
|
|
|
|
logger.debug(f'not found: buildbot{" debug" if debug else ""} log')
|
2019-09-08 19:05:09 +08:00
|
|
|
return f"{Path('.') / logfile} cannot be found"
|