mirror of
https://github.com/isjerryxiao/pacroller.git
synced 2024-11-22 07:40:43 +08:00
drop pyalpm
This commit is contained in:
parent
5de6e6455e
commit
e6a39f0cec
2 changed files with 46 additions and 52 deletions
|
@ -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
|
||||||
|
|
|
@ -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,61 +64,57 @@ 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,
|
||||||
logger.info('upgrade end, nothing to do')
|
check=False
|
||||||
exit(0)
|
)
|
||||||
|
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:
|
else:
|
||||||
def examine_upgrade(toadd: List[pyalpm.Package], toremove: List[pyalpm.Package]) -> None:
|
logger.debug(f"upgrade: {pkgname} {over} -> {nver}")
|
||||||
errors = list()
|
upgrade_pkgs.append((pkgname, over, nver))
|
||||||
for pkg in toadd:
|
if not upgrade_pkgs:
|
||||||
localpkg: pyalpm.Package = localdb.get_pkg(pkg.name)
|
logger.info('upgrade end, nothing to do')
|
||||||
localver = localpkg.version if localpkg else ""
|
exit(0)
|
||||||
logger.debug(f"will upgrade {pkg.name} from {localver} to {pkg.version}")
|
else:
|
||||||
if _testreg := HOLD.get(pkg.name):
|
try:
|
||||||
_m_old = match(_testreg, localver)
|
errors = list()
|
||||||
_m_new = match(_testreg, pkg.version)
|
for pkgname, over, nver in upgrade_pkgs:
|
||||||
if _m_old and _m_new:
|
if _testreg := HOLD.get(pkgname):
|
||||||
if (o := _m_old.groups()) != (n := _m_new.groups()):
|
_m_old = match(_testreg, over)
|
||||||
errors.append(f"hold package {pkg.name} is going to be upgraded from {o=} to {n=}")
|
_m_new = match(_testreg, nver)
|
||||||
else:
|
if _m_old and _m_new:
|
||||||
errors.append(f"cannot match version regex for hold package {pkg.name}")
|
if (o := _m_old.groups()) != (n := _m_new.groups()):
|
||||||
for pkg in toremove:
|
errors.append(f"hold package {pkgname} is going to be upgraded from {o=} to {n=}")
|
||||||
logger.debug(f"will remove {pkg.name} version {pkg.version}")
|
if not o or not n:
|
||||||
if pkg.name in HOLD:
|
errors.append(f"hold package {pkgname}: version regex missing matching groups {o=} {n=}")
|
||||||
errors.append(f"attempt to remove {pkg.name} which is set to hold")
|
|
||||||
if errors:
|
|
||||||
raise PackageHold(errors)
|
|
||||||
try:
|
|
||||||
examine_upgrade(t.to_add, t.to_remove)
|
|
||||||
except Exception as e:
|
|
||||||
if interactive:
|
|
||||||
if ask_interactive_question(f"{e}, continue?"):
|
|
||||||
logger.warning("user determined to continue")
|
|
||||||
else:
|
else:
|
||||||
raise
|
errors.append(f"cannot match version regex for hold package {pkgname}")
|
||||||
|
if errors:
|
||||||
|
raise PackageHold(errors)
|
||||||
|
except PackageHold as e:
|
||||||
|
if interactive:
|
||||||
|
if ask_interactive_question(f"{e}, continue?"):
|
||||||
|
logger.warning("user determined to continue")
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
finally:
|
else:
|
||||||
t.release()
|
raise
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue