fix: AUR -> makepkg console output

This commit is contained in:
Vinicius Moreira
2019-09-23 16:10:34 -03:00
parent e44ce833d5
commit df7227e44b
3 changed files with 43 additions and 37 deletions

View File

@@ -2,8 +2,9 @@ import os
import subprocess import subprocess
import sys import sys
import time import time
from io import StringIO
from subprocess import PIPE from subprocess import PIPE
from typing import List from typing import List, Tuple
# default environment variables for subprocesses. # default environment variables for subprocesses.
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
@@ -55,6 +56,18 @@ class SystemProcess:
self.subproc.wait() self.subproc.wait()
class SimpleProcess:
def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = None, global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG):
self.instance = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=-1,
cwd=cwd,
env=gen_env(global_interpreter, lang))
self.expected_code = expected_code
class ProcessHandler: class ProcessHandler:
""" """
@@ -110,6 +123,23 @@ 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) -> Tuple[bool, str]:
self._notify_watcher(' '.join(proc.instance.args) + '\n')
output = StringIO()
for o in proc.instance.stdout:
if o:
line = o.decode()
output.write(line)
line = line.strip()
if line:
self._notify_watcher(line)
output.seek(0)
return proc.instance.returncode == proc.expected_code, output.read()
def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False, print_error: bool = True, def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False, print_error: bool = True,
cwd: str = '.', global_interpreter: bool = USE_GLOBAL_INTERPRETER) -> str: cwd: str = '.', global_interpreter: bool = USE_GLOBAL_INTERPRETER) -> str:

View File

@@ -13,7 +13,8 @@ from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus
from bauh.api.abstract.view import MessageType from bauh.api.abstract.view import MessageType
from bauh.commons.html import bold from bauh.commons.html import bold
from bauh.commons.system import SystemProcess, ProcessHandler, new_subprocess, run_cmd, new_root_subprocess from bauh.commons.system import SystemProcess, ProcessHandler, new_subprocess, run_cmd, new_root_subprocess, \
SimpleProcess
from bauh.gems.arch import BUILD_DIR, aur, pacman, makepkg, pkgbuild, message, confirmation, disk, git, suggestions, gpg from bauh.gems.arch import BUILD_DIR, aur, pacman, makepkg, pkgbuild, message, confirmation, disk, git, suggestions, gpg
from bauh.gems.arch.aur import AURClient from bauh.gems.arch.aur import AURClient
from bauh.gems.arch.mapper import ArchDataMapper from bauh.gems.arch.mapper import ArchDataMapper
@@ -397,7 +398,7 @@ class ArchManager(SoftwareManager):
# building main package # building main package
handler.watcher.change_substatus(self.i18n['arch.building.package'].format(bold(pkgname))) handler.watcher.change_substatus(self.i18n['arch.building.package'].format(bold(pkgname)))
pkgbuilt = handler.handle(SystemProcess(new_subprocess(['makepkg', '-ALcsmf'], cwd=project_dir, lang=None), check_error_output=False, skip_stdout=True)) pkgbuilt, output = handler.handle_simple(SimpleProcess(['makepkg', '-ALcsmf'], cwd=project_dir, lang=None))
self._update_progress(handler.watcher, 65, change_progress) self._update_progress(handler.watcher, 65, change_progress)
if pkgbuilt: if pkgbuilt:
@@ -423,7 +424,7 @@ class ArchManager(SoftwareManager):
def _install_missings_deps_and_keys(self, pkgname: str, root_password: str, handler: ProcessHandler, pkgdir: str) -> bool: def _install_missings_deps_and_keys(self, pkgname: str, root_password: str, handler: ProcessHandler, pkgdir: str) -> bool:
handler.watcher.change_substatus(self.i18n['arch.checking.deps'].format(bold(pkgname))) handler.watcher.change_substatus(self.i18n['arch.checking.deps'].format(bold(pkgname)))
check_res = makepkg.check(pkgdir, handler.watcher) check_res = makepkg.check(pkgdir, handler)
if check_res: if check_res:
if check_res.get('missing_deps'): if check_res.get('missing_deps'):

View File

@@ -1,46 +1,21 @@
import re import re
from bauh.api.abstract.handler import ProcessWatcher from bauh.commons.system import SimpleProcess, ProcessHandler
from bauh.commons.system import new_subprocess
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n') RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)') RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
def check(pkgdir: str, watcher: ProcessWatcher) -> dict: def check(pkgdir: str, handler: ProcessHandler) -> dict:
depcheck = new_subprocess(['makepkg', '-ALcf', '--check', '--noarchive'], cwd=pkgdir)
res = {} res = {}
success, output = handler.handle_simple(SimpleProcess(['makepkg', '-ALcf', '--check', '--noarchive'], cwd=pkgdir))
output_lines = [] if 'Missing dependencies' in output:
res['missing_deps'] = RE_DEPS_PATTERN.findall(output)
for o in depcheck.stdout: gpg_keys = RE_UNKNOWN_GPG_KEY.findall(output)
if o:
line = o.decode().strip()
if line: if gpg_keys:
output_lines.append(line) res['gpg_key'] = gpg_keys[0]
watcher.print(line)
for s in depcheck.stderr:
if s:
line = s.decode()
if line:
output_lines.append(line)
line_strip = line.strip()
if line_strip:
watcher.print(line_strip)
if output_lines:
error_str = ''.join(output_lines)
if 'Missing dependencies' in error_str:
res['missing_deps'] = RE_DEPS_PATTERN.findall(error_str)
gpg_keys = RE_UNKNOWN_GPG_KEY.findall(error_str)
if gpg_keys:
res['gpg_key'] = gpg_keys[0]
return res return res