[arch] fix -> some environment variables are not available during the common operations (install, upgrade, ...)

This commit is contained in:
Vinicius Moreira
2020-08-19 14:59:14 -03:00
parent e20bfe461b
commit eb1a1520a4
5 changed files with 28 additions and 22 deletions

View File

@@ -64,6 +64,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- info dialog of installed packages displays the latest PKGBUILD file instead of the one used for installation/upgrade/downgrade (the fix will only work for new installed packages) - info dialog of installed packages displays the latest PKGBUILD file instead of the one used for installation/upgrade/downgrade (the fix will only work for new installed packages)
- multi-threaded download: not retrieving correctly some source files URLs (e.g: linux-xanmod-lts) - multi-threaded download: not retrieving correctly some source files URLs (e.g: linux-xanmod-lts)
- importing PGP keys (Generic error). Now the key server is specified: `gpg --keyserver SERVER --recv-key KEYID` (the server address is retrieved from [bauh-files](https://github.com/vinifmor/bauh-files/blob/master/arch/gpgservers.txt)) - importing PGP keys (Generic error). Now the key server is specified: `gpg --keyserver SERVER --recv-key KEYID` (the server address is retrieved from [bauh-files](https://github.com/vinifmor/bauh-files/blob/master/arch/gpgservers.txt))
- some environment variables are not available during the common operations (install, upgrade, downgrade, uninstall, makepkg)
- Flatpak - Flatpak
- downgrading crashing with version 1.8.X - downgrading crashing with version 1.8.X
- history: the top commit is returned as "(null)" in version 1.8.X - history: the top commit is returned as "(null)" in version 1.8.X

View File

@@ -26,20 +26,20 @@ SIZE_MULTIPLIERS = ((0.001, 'Kb'), (0.000001, 'Mb'), (0.000000001, 'Gb'), (0.000
def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG, extra_paths: Set[str] = None) -> dict: def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG, extra_paths: Set[str] = None) -> dict:
res = {} custom_env = dict(os.environ)
if lang: if lang:
res['LANG'] = lang custom_env['LANG'] = lang
if global_interpreter: # to avoid subprocess calls to the virtualenv python interpreter instead of the global one. if global_interpreter: # to avoid subprocess calls to the virtualenv python interpreter instead of the global one.
res['PATH'] = GLOBAL_INTERPRETER_PATH custom_env['PATH'] = GLOBAL_INTERPRETER_PATH
else: else:
res['PATH'] = PATH custom_env['PATH'] = PATH
if extra_paths: if extra_paths:
res['PATH'] = ':'.join(extra_paths) + ':' + res['PATH'] custom_env['PATH'] = ':'.join(extra_paths) + ':' + custom_env['PATH']
return res return custom_env
class SystemProcess: class SystemProcess:
@@ -65,9 +65,11 @@ class SimpleProcess:
def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = 0, def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = 0,
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG, root_password: str = None, global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG, root_password: str = None,
extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None): extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None,
shell: bool = False):
pwdin, final_cmd = None, [] pwdin, final_cmd = None, []
self.shell = shell
if root_password is not None: if root_password is not None:
final_cmd.extend(['sudo', '-S']) final_cmd.extend(['sudo', '-S'])
pwdin = self._new(['echo', root_password], cwd, global_interpreter, lang).stdout pwdin = self._new(['echo', root_password], cwd, global_interpreter, lang).stdout
@@ -86,13 +88,14 @@ class SimpleProcess:
"stderr": subprocess.STDOUT, "stderr": subprocess.STDOUT,
"bufsize": -1, "bufsize": -1,
"cwd": cwd, "cwd": cwd,
"env": gen_env(global_interpreter, lang, extra_paths=extra_paths) "env": gen_env(global_interpreter, lang, extra_paths=extra_paths),
"shell": self.shell
} }
if stdin: if stdin:
args['stdin'] = stdin args['stdin'] = stdin
return subprocess.Popen(cmd, **args) return subprocess.Popen(args=' '.join(cmd) if self.shell else cmd, **args)
class ProcessHandler: class ProcessHandler:
@@ -160,7 +163,7 @@ class ProcessHandler:
return process.subproc.returncode is None or process.subproc.returncode == 0 return process.subproc.returncode is None or process.subproc.returncode == 0
def handle_simple(self, proc: SimpleProcess, output_handler=None) -> Tuple[bool, str]: def handle_simple(self, proc: SimpleProcess, output_handler=None) -> Tuple[bool, str]:
self._notify_watcher(' '.join(proc.instance.args) + '\n') self._notify_watcher((proc.instance.args if proc.shell else ' '.join(proc.instance.args)) + '\n')
output = StringIO() output = StringIO()
for o in proc.instance.stdout: for o in proc.instance.stdout:

View File

@@ -932,8 +932,10 @@ class ArchManager(SoftwareManager):
pkgs_to_remove=len(to_remove)) pkgs_to_remove=len(to_remove))
output_handler.start() output_handler.start()
try: try:
success = handler.handle(pacman.remove_several(pkgnames=to_remove, root_password=root_password, skip_checks=True), success, _ = handler.handle_simple(pacman.remove_several(pkgnames=to_remove,
output_handler=output_handler.handle) root_password=root_password,
skip_checks=True),
output_handler=output_handler.handle)
if not success: if not success:
self.logger.error("Could not remove packages: {}".format(', '.join(to_remove))) self.logger.error("Could not remove packages: {}".format(', '.join(to_remove)))

View File

@@ -28,7 +28,7 @@ def check(pkgdir: str, optimize: bool, missing_deps: bool, handler: ProcessHandl
else: else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE)) handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE))
success, output = handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir)) success, output = handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir, shell=True))
if missing_deps and 'Missing dependencies' in output: if missing_deps and 'Missing dependencies' in output:
res['missing_deps'] = RE_DEPS_PATTERN.findall(output) res['missing_deps'] = RE_DEPS_PATTERN.findall(output)
@@ -54,7 +54,7 @@ def make(pkgdir: str, optimize: bool, handler: ProcessHandler) -> Tuple[bool, st
else: else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE)) handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE))
return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir)) return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir, shell=True))
def update_srcinfo(project_dir: str) -> bool: def update_srcinfo(project_dir: str) -> bool:

View File

@@ -149,7 +149,8 @@ def install_as_process(pkgpaths: Iterable[str], root_password: str, file: bool,
return SimpleProcess(cmd=cmd, return SimpleProcess(cmd=cmd,
root_password=root_password, root_password=root_password,
cwd=pkgdir, cwd=pkgdir,
error_phrases={"error: failed to prepare transaction", 'error: failed to commit transaction', 'error: target not found'}) error_phrases={"error: failed to prepare transaction", 'error: failed to commit transaction', 'error: target not found'},
shell=True)
def list_desktop_entries(pkgnames: Set[str]) -> List[str]: def list_desktop_entries(pkgnames: Set[str]) -> List[str]:
@@ -731,25 +732,24 @@ def upgrade_several(pkgnames: Iterable[str], root_password: str, overwrite_confl
return SimpleProcess(cmd=cmd, return SimpleProcess(cmd=cmd,
root_password=root_password, root_password=root_password,
error_phrases={'error: failed to prepare transaction', 'error: failed to commit transaction', 'error: target not found'}) error_phrases={'error: failed to prepare transaction', 'error: failed to commit transaction', 'error: target not found'},
shell=True)
def download(root_password: str, *pkgnames: str) -> SimpleProcess: def download(root_password: str, *pkgnames: str) -> SimpleProcess:
return SimpleProcess(cmd=['pacman', '-Swdd', *pkgnames, '--noconfirm'], return SimpleProcess(cmd=['pacman', '-Swdd', *pkgnames, '--noconfirm'],
root_password=root_password, root_password=root_password,
error_phrases={'error: failed to prepare transaction', 'error: failed to commit transaction', 'error: target not found'}) error_phrases={'error: failed to prepare transaction', 'error: failed to commit transaction', 'error: target not found'},
shell=True)
def remove_several(pkgnames: Iterable[str], root_password: str, skip_checks: bool = False) -> SystemProcess: def remove_several(pkgnames: Iterable[str], root_password: str, skip_checks: bool = False) -> SimpleProcess:
cmd = ['pacman', '-R', *pkgnames, '--noconfirm'] cmd = ['pacman', '-R', *pkgnames, '--noconfirm']
if skip_checks: if skip_checks:
cmd.append('-dd') cmd.append('-dd')
if root_password: return SimpleProcess(cmd=cmd, root_password=root_password, wrong_error_phrases={'warning:'}, shell=True)
return SystemProcess(new_root_subprocess(cmd, root_password), wrong_error_phrase='warning:')
else:
return SystemProcess(new_subprocess(cmd), wrong_error_phrase='warning:')
def map_optional_deps(names: Iterable[str], remote: bool, not_installed: bool = False) -> Dict[str, Dict[str, str]]: def map_optional_deps(names: Iterable[str], remote: bool, not_installed: bool = False) -> Dict[str, Dict[str, str]]: