This commit is contained in:
Vinícius Moreira
2021-06-16 10:06:50 -03:00
committed by GitHub
15 changed files with 44 additions and 39 deletions

View File

@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.9.17] 2021-06-16
### Improvements
- general: replacing subprocess commands to detect installed CLIs by Python faster calls (**shutil.which**)
### Fixes
- Arch
- skipping the package version epoch when checking the updates requirements
## [0.9.16] 2021-04-06 ## [0.9.16] 2021-04-06
### Fixes ### Fixes
- Arch - Arch

View File

@@ -1,4 +1,4 @@
__version__ = '0.9.16' __version__ = '0.9.17'
__app_name__ = 'bauh' __app_name__ = 'bauh'
import os import os

View File

@@ -606,9 +606,8 @@ class AppImageManager(SoftwareManager):
def set_enabled(self, enabled: bool): def set_enabled(self, enabled: bool):
self.enabled = enabled self.enabled = enabled
def _is_sqlite3_available(self): def _is_sqlite3_available(self) -> bool:
res = run_cmd('which sqlite3') return bool(shutil.which('sqlite3'))
return res and not res.strip().startswith('which ')
def can_work(self) -> bool: def can_work(self) -> bool:
return self._is_sqlite3_available() and self.file_downloader.can_work() return self._is_sqlite3_available() and self.file_downloader.can_work()

View File

@@ -2649,9 +2649,8 @@ class ArchManager(SoftwareManager):
return res return res
def _is_wget_available(self): def _is_wget_available(self) -> bool:
res = run_cmd('which wget') return bool(shutil.which('wget'))
return res and not res.strip().startswith('which ')
def is_enabled(self) -> bool: def is_enabled(self) -> bool:
return self.enabled return self.enabled

View File

@@ -1,3 +1,4 @@
import shutil
from datetime import datetime from datetime import datetime
from typing import List, Tuple, Optional from typing import List, Tuple, Optional
@@ -6,8 +7,7 @@ from bauh.commons.system import new_subprocess, SimpleProcess
def is_installed() -> bool: def is_installed() -> bool:
code, _ = system.execute(cmd='which git', output=False) return bool(shutil.which('git'))
return code == 0
def list_commits(proj_dir: str) -> List[dict]: def list_commits(proj_dir: str) -> List[dict]:

View File

@@ -1,6 +1,7 @@
import logging import logging
import os import os
import re import re
import shutil
from threading import Thread from threading import Thread
from typing import List, Set, Tuple, Dict, Iterable, Optional from typing import List, Set, Tuple, Dict, Iterable, Optional
@@ -26,8 +27,7 @@ RE_DESKTOP_FILES = re.compile(r'\n?([\w\-_]+)\s+(/usr/share/.+\.desktop)')
def is_available() -> bool: def is_available() -> bool:
res = run_cmd('which pacman', print_error=False) return bool(shutil.which('pacman'))
return res and not res.strip().startswith('which ')
def get_repositories(pkgs: Iterable[str]) -> dict: def get_repositories(pkgs: Iterable[str]) -> dict:
@@ -463,8 +463,7 @@ def get_databases() -> Set[str]:
def can_refresh_mirrors() -> bool: def can_refresh_mirrors() -> bool:
output = run_cmd('which pacman-mirrors', print_error=False) return is_mirrors_available()
return True if output else False
def refresh_mirrors(root_password: str) -> SimpleProcess: def refresh_mirrors(root_password: str) -> SimpleProcess:
@@ -497,8 +496,7 @@ def get_current_mirror_countries() -> List[str]:
def is_mirrors_available() -> bool: def is_mirrors_available() -> bool:
code, _ = system.execute(cmd='which pacman-mirrors', output=False) return bool(shutil.which('pacman-mirrors'))
return code == 0
def map_update_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes: def map_update_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
@@ -674,7 +672,7 @@ def map_updates_data(pkgs: Iterable[str], files: bool = False) -> dict:
if val == 'None': if val == 'None':
data['d'] = None data['d'] = None
else: else:
data['d'] = {w.strip().split(':')[0].strip() for w in val.split(' ') if w} data['d'] = {w.strip() for w in val.split(' ') if w}
latest_field = 'd' latest_field = 'd'
elif field == 'Conflicts With': elif field == 'Conflicts With':
if val == 'None': if val == 'None':

View File

@@ -1,4 +1,5 @@
import os import os
import shutil
from pathlib import Path from pathlib import Path
from typing import Set from typing import Set
@@ -7,7 +8,7 @@ from bauh.gems.arch import IGNORED_REBUILD_CHECK_FILE
def is_installed() -> bool: def is_installed() -> bool:
return system.execute(cmd='which checkrebuild', output=False)[0] == 0 return bool(shutil.which('checkrebuild'))
def list_required_rebuild() -> Set[str]: def list_required_rebuild() -> Set[str]:

View File

@@ -2,6 +2,7 @@ import glob
import logging import logging
import os import os
import re import re
import shutil
import time import time
import traceback import traceback
from datetime import datetime, timedelta from datetime import datetime, timedelta
@@ -13,7 +14,6 @@ import requests
from bauh.api.abstract.context import ApplicationContext from bauh.api.abstract.context import ApplicationContext
from bauh.api.abstract.handler import TaskManager from bauh.api.abstract.handler import TaskManager
from bauh.commons import system
from bauh.commons.boot import CreateConfigFile from bauh.commons.boot import CreateConfigFile
from bauh.commons.html import bold from bauh.commons.html import bold
from bauh.commons.system import new_root_subprocess, ProcessHandler from bauh.commons.system import new_root_subprocess, ProcessHandler
@@ -259,8 +259,7 @@ class ArchCompilationOptimizer(Thread):
self.taskman.register_task(self.task_id, self.i18n['arch.task.optimizing'].format(bold('makepkg.conf')), get_icon_path()) self.taskman.register_task(self.task_id, self.i18n['arch.task.optimizing'].format(bold('makepkg.conf')), get_icon_path())
def _is_ccache_installed(self) -> bool: def _is_ccache_installed(self) -> bool:
code, _ = system.execute(cmd='which ccache', output=False) return bool(shutil.which('ccache'))
return code == 0
def optimize(self): def optimize(self):
ti = time.time() ti = time.time()

View File

@@ -1,15 +1,16 @@
import os import os
import shutil
import subprocess import subprocess
from io import StringIO from io import StringIO
from typing import Tuple, Optional from typing import Tuple, Optional
from bauh.commons.system import run_cmd, SimpleProcess from bauh.commons.system import SimpleProcess
BASE_CMD = 'snap' BASE_CMD = 'snap'
def is_installed() -> bool: def is_installed() -> bool:
return bool(run_cmd('which {}'.format(BASE_CMD), print_error=False)) return bool(shutil.which(BASE_CMD))
def uninstall_and_stream(app_name: str, root_password: str) -> SimpleProcess: def uninstall_and_stream(app_name: str, root_password: str) -> SimpleProcess:

View File

@@ -1,3 +1,4 @@
import shutil
from typing import List, Optional from typing import List, Optional
from bauh.commons.system import SimpleProcess, run_cmd from bauh.commons.system import SimpleProcess, run_cmd
@@ -18,8 +19,7 @@ def install(url: str, name: str, output_dir: str, electron_version: Optional[str
def is_available() -> bool: def is_available() -> bool:
res = run_cmd('which nativefier', print_error=False) return bool(shutil.which('nativefier'))
return res and not res.strip().startswith('which ')
def get_version() -> str: def get_version() -> str:

View File

@@ -1,6 +1,5 @@
from bauh.commons.system import run_cmd import shutil
def is_available() -> bool: def is_available() -> bool:
res = run_cmd('which npm', print_error=False) return bool(shutil.which('npm'))
return res and not res.strip().startswith('which ')

View File

@@ -1,5 +1,6 @@
import re import re
import re import re
import shutil
import time import time
import traceback import traceback
from subprocess import Popen, STDOUT from subprocess import Popen, STDOUT
@@ -16,7 +17,6 @@ from bauh.api.abstract.view import ViewComponent, TabGroupComponent, MessageType
from bauh.api.exception import NoInternetException from bauh.api.exception import NoInternetException
from bauh.commons.boot import CreateConfigFile from bauh.commons.boot import CreateConfigFile
from bauh.commons.html import bold from bauh.commons.html import bold
from bauh.commons.system import run_cmd
from bauh.view.core.config import CoreConfigManager from bauh.view.core.config import CoreConfigManager
from bauh.view.core.settings import GenericSettingsManager from bauh.view.core.settings import GenericSettingsManager
from bauh.view.core.update import check_for_update from bauh.view.core.update import check_for_update
@@ -71,7 +71,7 @@ class GenericSoftwareManager(SoftwareManager):
refresh=False): self.is_backups_action_available} refresh=False): self.is_backups_action_available}
def _is_timeshift_launcher_available(self) -> bool: def _is_timeshift_launcher_available(self) -> bool:
return bool(run_cmd('which timeshift-launcher', print_error=False)) return bool(shutil.which('timeshift-launcher'))
def is_backups_action_available(self, app_config: dict) -> bool: def is_backups_action_available(self, app_config: dict) -> bool:
return bool(app_config['backup']['enabled']) and self._is_timeshift_launcher_available() return bool(app_config['backup']['enabled']) and self._is_timeshift_launcher_available()

View File

@@ -1,6 +1,7 @@
import logging import logging
import os import os
import re import re
import shutil
import time import time
import traceback import traceback
from math import floor from math import floor
@@ -29,15 +30,15 @@ class AdaptableFileDownloader(FileDownloader):
@staticmethod @staticmethod
def is_aria2c_available() -> bool: def is_aria2c_available() -> bool:
return bool(run_cmd('which aria2c', print_error=False)) return bool(shutil.which('aria2c'))
@staticmethod @staticmethod
def is_axel_available() -> bool: def is_axel_available() -> bool:
return bool(run_cmd('which axel', print_error=False)) return bool(shutil.which('axel'))
@staticmethod @staticmethod
def is_wget_available() -> bool: def is_wget_available() -> bool:
return bool(run_cmd('which wget', print_error=False)) return bool(shutil.which('wget'))
def _get_aria2c_process(self, url: str, output_path: str, cwd: str, root_password: str, threads: int) -> SimpleProcess: def _get_aria2c_process(self, url: str, output_path: str, cwd: str, root_password: str, threads: int) -> SimpleProcess:
cmd = ['aria2c', url, cmd = ['aria2c', url,

View File

@@ -1,8 +1,10 @@
from bauh.commons.system import run_cmd, SimpleProcess import shutil
from bauh.commons.system import SimpleProcess
def is_available() -> bool: def is_available() -> bool:
return bool(run_cmd('which timeshift', print_error=False)) return bool(shutil.which('timeshift'))
def delete_all_snapshots(root_password: str) -> SimpleProcess: def delete_all_snapshots(root_password: str) -> SimpleProcess:

View File

@@ -1,6 +1,7 @@
import json import json
import logging import logging
import os import os
import shutil
import sys import sys
import traceback import traceback
from io import StringIO from io import StringIO
@@ -15,7 +16,6 @@ from PyQt5.QtWidgets import QSystemTrayIcon, QMenu
from bauh import __app_name__, ROOT_DIR from bauh import __app_name__, ROOT_DIR
from bauh.api.abstract.model import PackageUpdate from bauh.api.abstract.model import PackageUpdate
from bauh.api.http import HttpClient from bauh.api.http import HttpClient
from bauh.commons import system
from bauh.commons.system import run_cmd from bauh.commons.system import run_cmd
from bauh.context import generate_i18n from bauh.context import generate_i18n
from bauh.view.core.tray_client import TRAY_CHECK_FILE from bauh.view.core.tray_client import TRAY_CHECK_FILE
@@ -40,10 +40,7 @@ def get_cli_path() -> str:
if os.path.exists(cli_path): if os.path.exists(cli_path):
return cli_path return cli_path
else: else:
cli_path = system.run_cmd('which bauh-cli', print_error=False) return shutil.which('bauh-cli')
if cli_path:
return cli_path.strip()
def list_updates(logger: logging.Logger) -> List[PackageUpdate]: def list_updates(logger: logging.Logger) -> List[PackageUpdate]: