mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 21:44:16 +02:00
fix: AUR -> makepkg console output
This commit is contained in:
@@ -2,8 +2,9 @@ import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from io import StringIO
|
||||
from subprocess import PIPE
|
||||
from typing import List
|
||||
from typing import List, Tuple
|
||||
|
||||
# default environment variables for subprocesses.
|
||||
from bauh.api.abstract.handler import ProcessWatcher
|
||||
@@ -55,6 +56,18 @@ class SystemProcess:
|
||||
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:
|
||||
|
||||
"""
|
||||
@@ -110,6 +123,23 @@ class ProcessHandler:
|
||||
|
||||
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,
|
||||
cwd: str = '.', global_interpreter: bool = USE_GLOBAL_INTERPRETER) -> str:
|
||||
|
||||
@@ -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.view import MessageType
|
||||
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.aur import AURClient
|
||||
from bauh.gems.arch.mapper import ArchDataMapper
|
||||
@@ -397,7 +398,7 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
# building main package
|
||||
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)
|
||||
|
||||
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:
|
||||
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.get('missing_deps'):
|
||||
|
||||
@@ -1,46 +1,21 @@
|
||||
import re
|
||||
|
||||
from bauh.api.abstract.handler import ProcessWatcher
|
||||
from bauh.commons.system import new_subprocess
|
||||
from bauh.commons.system import SimpleProcess, ProcessHandler
|
||||
|
||||
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
|
||||
RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
|
||||
|
||||
|
||||
def check(pkgdir: str, watcher: ProcessWatcher) -> dict:
|
||||
depcheck = new_subprocess(['makepkg', '-ALcf', '--check', '--noarchive'], cwd=pkgdir)
|
||||
def check(pkgdir: str, handler: ProcessHandler) -> dict:
|
||||
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:
|
||||
if o:
|
||||
line = o.decode().strip()
|
||||
gpg_keys = RE_UNKNOWN_GPG_KEY.findall(output)
|
||||
|
||||
if line:
|
||||
output_lines.append(line)
|
||||
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]
|
||||
if gpg_keys:
|
||||
res['gpg_key'] = gpg_keys[0]
|
||||
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user