mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 13:14:17 +02:00
improvement: replacing subprocess commands to detected installed CLIs by Python faster native calls (shutil.which)
This commit is contained in:
@@ -5,6 +5,9 @@ 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]
|
## [0.9.17]
|
||||||
|
### Improvements
|
||||||
|
- general: replacing subprocess commands to detected installed CLIs by Python faster native calls (**shutil.which**)
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Arch
|
- Arch
|
||||||
- skipping the package version epoch when checking the updates requirements
|
- skipping the package version epoch when checking the updates requirements
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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]:
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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]:
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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 ')
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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,11 +40,8 @@ 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]:
|
||||||
cli_path = get_cli_path()
|
cli_path = get_cli_path()
|
||||||
|
|||||||
Reference in New Issue
Block a user