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-08 20:15:06 +08:00
|
|
|
import re
|
|
|
|
|
|
|
|
ASCII_CRL_REPL = re.compile('\x1B[@-_][0-?]*[ -/]*[@-~]')
|
|
|
|
|
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:
|
2019-10-06 13:21:16 +08:00
|
|
|
ps = ('type', 'cleanbuild', 'timeout', 'priority')
|
2019-09-08 17:07:47 +08:00
|
|
|
hps = ('prebuild', 'postbuild', 'update', 'failure')
|
|
|
|
dps = {p:getattr(pc, p, None) for p in ps}
|
2019-09-10 22:12:44 +08:00
|
|
|
dhps = {p:'\n'.join([str(cmd) for cmd in getattr(pc, p, None)]) for p in hps}
|
2019-09-08 17:07:47 +08:00
|
|
|
# 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)
|
|
|
|
|
2019-09-08 20:15:06 +08:00
|
|
|
def __simpleread(fpath, limit=4096-100, dosub=False):
|
2019-09-08 17:07:47 +08:00
|
|
|
with open(fpath, 'r') as f:
|
|
|
|
c = f.read()
|
2019-09-08 20:15:06 +08:00
|
|
|
if dosub:
|
|
|
|
c = ASCII_CRL_REPL.sub('', c[-2*limit:])
|
2019-09-08 17:07:47 +08:00
|
|
|
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}')
|
2019-09-08 20:15:06 +08:00
|
|
|
return __simpleread(cwd / logfile, dosub=True)
|
2019-09-08 17:07:47 +08:00
|
|
|
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"
|