various fixes

This commit is contained in:
JerryXiao 2021-01-16 01:02:37 +08:00
parent 7083d4b41b
commit fc23239e30
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA
4 changed files with 12 additions and 9 deletions

View file

@ -30,7 +30,7 @@ REGEX: Dict[str, Pattern] # get through lint
class checkReport:
def __init__(self, info: List[str] = None, warn: List[str] = None,
crit: List[str] = None, changes: List[Tuple[str]] = None,
date: int = int(time)) -> None:
date: int = int(time())) -> None:
self._info = info or list()
self._warn = warn or list()
self._crit = crit or list()
@ -86,7 +86,7 @@ class checkReport:
ret.append("Package changes:")
ret.extend([" " * indent + i for i in pkg_ret])
if len(ret) == 1:
ret.append('all systems go')
ret.append('nothing to show')
return "\n".join(ret)
def info(self, text: str) -> None:
logger.debug(f'report info {text}')
@ -229,7 +229,7 @@ def _log_parser(log: List[str], report: checkReport) -> None:
report.crit(f'ALPM {line=} is unknown')
elif source == 'ALPM-SCRIPTLET':
(_, _, _pmsg) = _split_log_line(log[ln-1])
if _m := REGEX['s_upgrade_pkg'].match(_pmsg):
if _m := REGEX['l_upgrade'].match(_pmsg):
pkg, *_ = _m.groups()
elif _m := REGEX['l_install'].match(_pmsg):
pkg, *_ = _m.groups()
@ -237,6 +237,8 @@ def _log_parser(log: List[str], report: checkReport) -> None:
pkg, *_ = _m.groups()
else:
report.crit(f'{line=} has unknown SCRIPTLET output')
ln += 1
continue
logger.debug(f'.install start {pkg=}')
while True:
ln += 1

View file

@ -8,9 +8,9 @@
"hold": {
"linux": "(.*)",
"python": "[0-9]+[.]([0-9]+)[.][0-9]+[-][0-9]+"
}
'ignored_pacnew': [
'/etc/locale.gen',
'/etc/pacman.d/mirrorlist'
},
"ignored_pacnew": [
"/etc/locale.gen",
"/etc/pacman.d/mirrorlist"
]
}

View file

@ -27,7 +27,7 @@ EXTRA_SAFE = bool(_config.get('extra_safe', False))
SHELL = str(_config.get('shell', '/bin/bash'))
HOLD = _config.get('hold', dict())
for (k, v) in HOLD:
for (k, v) in HOLD.items():
assert isinstance(k, str) and isinstance(v, str)
IGNORED_PACNEW = _config.get('ignored_pacnew', list())

View file

@ -68,8 +68,8 @@ class alpmCallback:
def upgrade() -> List[str]:
logger.info('upgrade start')
handle = pycman.config.init_with_config(PACMAN_CONFIG)
pycman.config.cb_log = lambda *_: None
handle = pycman.config.init_with_config(PACMAN_CONFIG)
localdb = handle.get_localdb()
alpmCallback().setup_hdl(handle)
t = handle.init_transaction()
@ -77,6 +77,7 @@ def upgrade() -> List[str]:
t.sysupgrade(False) # no downgrade
if len(t.to_add) + len(t.to_remove) == 0:
logger.info('upgrade end, nothing to do')
exit(0)
else:
def examine_upgrade(toadd: List[pyalpm.Package], toremove: List[pyalpm.Package]) -> None:
for pkg in toadd: