From 2e187a8f58ad6c487c5d0fc67fcbc323caf4492c Mon Sep 17 00:00:00 2001 From: eatradish Date: Wed, 15 Mar 2023 14:35:49 +0800 Subject: [PATCH] pm: adapt oma package manager If oma install has failed, fallback to apt --- acbs/pm.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/acbs/pm.py b/acbs/pm.py index 98f24e6..afe5bb7 100644 --- a/acbs/pm.py +++ b/acbs/pm.py @@ -121,16 +121,31 @@ def check_if_available(name: str) -> bool: def install_from_repo(packages: List[str]): - logging.debug('Installing %s' % packages) - escaped = [] - for package in packages: - escaped.append(escape_package_name_install(package)) - command = ['apt-get', 'install', '-y', '-o', 'Dpkg::Options::=--force-confnew'] - command.extend(escaped) + oma_is_success = install_from_repo_oma(packages) + + if not oma_is_success: + logging.debug('Installing %s' % packages) + escaped = [] + for package in packages: + escaped.append(escape_package_name_install(package)) + command = ['apt-get', 'install', '-y', '-o', 'Dpkg::Options::=--force-confnew'] + command.extend(escaped) + try: + subprocess.check_call(command, env={'DEBIAN_FRONTEND': 'noninteractive'}) + except subprocess.CalledProcessError: + logging.warning( + 'Failed to install dependencies, attempting to correct issues...') + fix_pm_states(escaped) + return + +def install_from_repo_oma(packages: List[str]) -> bool: + logging.debug('Installing %s from oma' % packages) + command = ['oma', 'install', '-y', '--force-confnew', '--no-progress'] + command.extend(packages) try: - subprocess.check_call(command, env={'DEBIAN_FRONTEND': 'noninteractive'}) - except subprocess.CalledProcessError: + subprocess.check_call(command) + except: logging.warning( - 'Failed to install dependencies, attempting to correct issues...') - fix_pm_states(escaped) - return + 'Failed to use oma install dependencies, fallbacking to apt...') + return False + return True