drop pyalpm

This commit is contained in:
JerryXiao 2021-06-02 14:31:09 +08:00
parent 5de6e6455e
commit e6a39f0cec
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 46 additions and 52 deletions

View file

@ -266,7 +266,7 @@ def _log_parser(log: List[str], report: checkReport) -> None:
def sync_err_is_net(output: str) -> bool: def sync_err_is_net(output: str) -> bool:
''' check if a sync failure is caused by network ''' ''' check if a sync failure is caused by network '''
output = output.strip().split('\n') output = output.strip().split('\n')
if 'error: failed to synchronize all databases' in output: if 'error: failed to synchronize all databases (download library error)' in output:
return True return True
else: else:
return False return False

View file

@ -8,8 +8,6 @@ import json
from os import environ, getuid, isatty from os import environ, getuid, isatty
import traceback import traceback
from datetime import datetime from datetime import datetime
import pyalpm
import pycman
from typing import List, Iterator from typing import List, Iterator
from pacroller.utils import execute_with_io, UnknownQuestionError, back_readline, ask_interactive_question from pacroller.utils import execute_with_io, UnknownQuestionError, back_readline, ask_interactive_question
from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport
@ -66,52 +64,50 @@ def sync() -> None:
logger.debug(f'sync {p.stdout=}') logger.debug(f'sync {p.stdout=}')
logger.info('sync end') logger.info('sync end')
class alpmCallback:
@staticmethod
def noop() -> None:
pass
def setup_hdl(self, handle: pyalpm.Handle) -> None:
handle.dlcb = self.noop
handle.eventcb = self.noop
handle.questioncb = self.noop
handle.progresscb = self.noop
def upgrade(interactive=False) -> List[str]: def upgrade(interactive=False) -> List[str]:
logger.info('upgrade start') logger.info('upgrade start')
pycman.config.cb_log = lambda *_: None check_upgrade_cmd = ['pacman', '-Qu', '--color', 'never']
handle = pycman.config.init_with_config(PACMAN_CONFIG) p = subprocess.run(
localdb = handle.get_localdb() check_upgrade_cmd,
alpmCallback().setup_hdl(handle) stdin=subprocess.DEVNULL,
t = handle.init_transaction() stdout=subprocess.PIPE,
try: stderr=subprocess.STDOUT,
t.sysupgrade(False) # no downgrade encoding='utf-8',
if len(t.to_add) + len(t.to_remove) == 0: timeout=TIMEOUT,
check=False
)
if p.returncode != 1:
p.check_returncode()
upgrade_pkgs = list()
for line in filter(None, p.stdout.split('\n')):
pkgname, over, _ar, nver, *ignored = line.split()
assert _ar == '->'
assert not ignored or (len(ignored) == 1 and ignored[0] == "[ignored]")
if ignored:
logger.debug(f"upgrade ignored: {pkgname} {over} -> {nver}")
else:
logger.debug(f"upgrade: {pkgname} {over} -> {nver}")
upgrade_pkgs.append((pkgname, over, nver))
if not upgrade_pkgs:
logger.info('upgrade end, nothing to do') logger.info('upgrade end, nothing to do')
exit(0) exit(0)
else: else:
def examine_upgrade(toadd: List[pyalpm.Package], toremove: List[pyalpm.Package]) -> None: try:
errors = list() errors = list()
for pkg in toadd: for pkgname, over, nver in upgrade_pkgs:
localpkg: pyalpm.Package = localdb.get_pkg(pkg.name) if _testreg := HOLD.get(pkgname):
localver = localpkg.version if localpkg else "" _m_old = match(_testreg, over)
logger.debug(f"will upgrade {pkg.name} from {localver} to {pkg.version}") _m_new = match(_testreg, nver)
if _testreg := HOLD.get(pkg.name):
_m_old = match(_testreg, localver)
_m_new = match(_testreg, pkg.version)
if _m_old and _m_new: if _m_old and _m_new:
if (o := _m_old.groups()) != (n := _m_new.groups()): if (o := _m_old.groups()) != (n := _m_new.groups()):
errors.append(f"hold package {pkg.name} is going to be upgraded from {o=} to {n=}") errors.append(f"hold package {pkgname} is going to be upgraded from {o=} to {n=}")
if not o or not n:
errors.append(f"hold package {pkgname}: version regex missing matching groups {o=} {n=}")
else: else:
errors.append(f"cannot match version regex for hold package {pkg.name}") errors.append(f"cannot match version regex for hold package {pkgname}")
for pkg in toremove:
logger.debug(f"will remove {pkg.name} version {pkg.version}")
if pkg.name in HOLD:
errors.append(f"attempt to remove {pkg.name} which is set to hold")
if errors: if errors:
raise PackageHold(errors) raise PackageHold(errors)
try: except PackageHold as e:
examine_upgrade(t.to_add, t.to_remove)
except Exception as e:
if interactive: if interactive:
if ask_interactive_question(f"{e}, continue?"): if ask_interactive_question(f"{e}, continue?"):
logger.warning("user determined to continue") logger.warning("user determined to continue")
@ -119,8 +115,6 @@ def upgrade(interactive=False) -> List[str]:
raise raise
else: else:
raise raise
finally:
t.release()
pacman_output = execute_with_io(['pacman', '-Su', '--noprogressbar', '--color', 'never'], UPGRADE_TIMEOUT, interactive=interactive) pacman_output = execute_with_io(['pacman', '-Su', '--noprogressbar', '--color', 'never'], UPGRADE_TIMEOUT, interactive=interactive)
logger.info('upgrade end') logger.info('upgrade end')
return pacman_output return pacman_output