[debian] fix: hanging when packages require manual configuration (install/upgrade)

This commit is contained in:
Vinicius Moreira
2022-04-12 17:23:38 -03:00
parent e40fe27bd1
commit 6937be8cb9
3 changed files with 19 additions and 10 deletions

View File

@@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- uninstall and downgrade logs are not available [#255](https://github.com/vinifmor/bauh/issues/255)
- Debian
- install/upgrade: hanging when packages require manual configuration
- info: crashing when the package size has unexpected symbols [#251](https://github.com/vinifmor/bauh/issues/251)
- displaying wrong symbols among numbers in install/uninstall/upgrade outputs for systems without english encoding installed
- removing unused packages on any type of transaction (this is the default behaviour for aptitude)

View File

@@ -71,7 +71,7 @@ class SimpleProcess:
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: Optional[str] = DEFAULT_LANG, root_password: Optional[str] = None,
extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None,
shell: bool = False, success_phrases: Set[str] = None, extra_env: Optional[Dict[str, str]] = None,
custom_user: Optional[str] = None):
custom_user: Optional[str] = None, preserve_env: Optional[Set] = None):
pwdin, final_cmd = None, []
self.shell = shell
@@ -80,6 +80,11 @@ class SimpleProcess:
final_cmd.extend(['runuser', '-u', custom_user, '--'])
elif isinstance(root_password, str):
final_cmd.extend(['sudo', '-S'])
if preserve_env:
for var in preserve_env:
final_cmd.append(f'--preserve-env={var}')
pwdin = self._new(['echo', root_password], cwd, global_interpreter, lang).stdout
final_cmd.extend(cmd)

View File

@@ -46,7 +46,8 @@ class Aptitude:
self._default_lang = ''
self._ignored_fields: Optional[Set[str]] = None
self._re_none: Optional[Pattern] = None
self._vars_encoding_fix: Optional[Dict[str, str]] = None
self._vars_fixes: Optional[Dict[str, str]] = None
self._preserve_env = {'DEBIAN_FRONTEND'}
def show(self, pkgs: Iterable[str], attrs: Optional[Collection[str]] = None, verbose: bool = False) \
-> Optional[Dict[str, Dict[str, object]]]:
@@ -129,7 +130,8 @@ class Aptitude:
def upgrade(self, packages: Iterable[str], root_password: Optional[str]) -> SimpleProcess:
cmd = self.gen_transaction_cmd('upgrade', packages).split(' ')
return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_encoding_fix)
return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_fixes,
preserve_env=self._preserve_env)
def update(self, root_password: Optional[str]) -> SimpleProcess:
return SimpleProcess(('aptitude', 'update'), root_password=root_password, shell=True)
@@ -143,7 +145,8 @@ class Aptitude:
def install(self, packages: Iterable[str], root_password: Optional[str]) -> SimpleProcess:
cmd = self.gen_transaction_cmd('install', packages).split(' ')
return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_encoding_fix)
return SimpleProcess(cmd=cmd, root_password=root_password, extra_env=self.vars_fixes,
preserve_env=self._preserve_env)
def read_installed(self) -> Generator[DebianPackage, None, None]:
yield from self.search(query='~i')
@@ -200,7 +203,7 @@ class Aptitude:
def remove(self, packages: Iterable[str], root_password: Optional[str], purge: bool = False) -> SimpleProcess:
return SimpleProcess(cmd=self.gen_remove_cmd(packages, purge).split(' '), shell=True,
root_password=root_password, extra_env=self.vars_encoding_fix)
root_password=root_password, extra_env=self.vars_fixes, preserve_env=self._preserve_env)
def read_installed_names(self) -> Generator[str, None, None]:
code, output = system.execute("aptitude search ~i -q -F '%p' --disable-columns",
@@ -279,11 +282,11 @@ class Aptitude:
return self._re_none
@property
def vars_encoding_fix(self) -> Dict[str, str]:
if self._vars_encoding_fix is None:
self._vars_encoding_fix = {'LC_NUMERIC': ''}
def vars_fixes(self) -> Dict[str, str]:
if self._vars_fixes is None:
self._vars_fixes = {'LC_NUMERIC': '', 'DEBIAN_FRONTEND': 'noninteractive'}
return self._vars_encoding_fix
return self._vars_fixes
class AptitudeOutputHandler(Thread):