diff --git a/bauh/api/abstract/context.py b/bauh/api/abstract/context.py index 581fa40a..056998f5 100644 --- a/bauh/api/abstract/context.py +++ b/bauh/api/abstract/context.py @@ -12,7 +12,7 @@ class ApplicationContext: def __init__(self, disk_cache: bool, download_icons: bool, http_client: HttpClient, app_root_dir: str, i18n: dict, cache_factory: MemoryCacheFactory, disk_loader_factory: DiskCacheLoaderFactory, - logger: logging.Logger, file_downloader: FileDownloader): + logger: logging.Logger, file_downloader: FileDownloader, distro: str): """ :param disk_cache: if package data should be cached to disk :param download_icons: if packages icons should be downloaded @@ -22,7 +22,8 @@ class ApplicationContext: :param cache_factory: :param disk_loader_factory: :param logger: a logger instance - :param file_downloader: + :param file_downloader + :param distro """ self.disk_cache = disk_cache self.download_icons = download_icons @@ -34,6 +35,7 @@ class ApplicationContext: self.logger = logger self.file_downloader = file_downloader self.arch_x86_64 = sys.maxsize > 2**32 + self.distro = distro def is_system_x86_64(self): return self.arch_x86_64 diff --git a/bauh/app.py b/bauh/app.py index bb04c655..d33e07d0 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -32,6 +32,7 @@ def main(): icon_cache = cache_factory.new(args.icon_exp) http_client = HttpClient(logger) + context = ApplicationContext(i18n=i18n, http_client=http_client, disk_cache=args.disk_cache, @@ -40,6 +41,7 @@ def main(): cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache, logger=logger), logger=logger, + distro=util.get_distro(), file_downloader=AdaptableFileDownloader(logger, bool(args.download_mthread), i18n, http_client)) user_config = config.read() diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index 7d73e1a3..40623c39 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -50,7 +50,7 @@ class ArchManager(SoftwareManager): self.comp_optimizer = ArchCompilationOptimizer(context.logger) self.logger = context.logger self.enabled = True - self.arch_distro = os.path.exists('/etc/arch-release') + self.arch_distro = context.distro == 'arch' def _upgrade_search_result(self, apidata: dict, installed_pkgs: dict, downgrade_enabled: bool, res: SearchResult, disk_loader: DiskCacheLoader): app = self.mapper.map_api_data(apidata, installed_pkgs['not_signed']) diff --git a/bauh/gems/snap/controller.py b/bauh/gems/snap/controller.py index c16eaa46..0527605c 100644 --- a/bauh/gems/snap/controller.py +++ b/bauh/gems/snap/controller.py @@ -26,6 +26,7 @@ class SnapManager(SoftwareManager): self.enabled = True self.http_client = context.http_client self.logger = context.logger + self.ubuntu_distro = context.distro == 'ubuntu' def map_json(self, app_json: dict, installed: bool, disk_loader: DiskCacheLoader, internet: bool = True) -> SnapApplication: app = SnapApplication(publisher=app_json.get('publisher'), @@ -83,7 +84,7 @@ class SnapManager(SoftwareManager): def read_installed(self, disk_loader: DiskCacheLoader, limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult: if snap.is_snapd_running(): - installed = [self.map_json(app_json, installed=True, disk_loader=disk_loader, internet=internet_available) for app_json in snap.read_installed()] + installed = [self.map_json(app_json, installed=True, disk_loader=disk_loader, internet=internet_available) for app_json in snap.read_installed(self.ubuntu_distro)] return SearchResult(installed, None, len(installed)) else: return SearchResult([], None, 0) diff --git a/bauh/gems/snap/snap.py b/bauh/gems/snap/snap.py index 4b87fcf2..ec645799 100644 --- a/bauh/gems/snap/snap.py +++ b/bauh/gems/snap/snap.py @@ -9,7 +9,6 @@ from bauh.gems.snap.model import SnapApplication BASE_CMD = 'snap' RE_SNAPD_STATUS = re.compile('\s+') SNAPD_RUNNING_STATUS = {'listening', 'running'} -UBUNTU_DISTRO = 'ubuntu' in run_cmd('cat /proc/version').lower() def is_installed(): @@ -86,7 +85,7 @@ def get_info(app_name: str, attrs: tuple = None): return data -def read_installed() -> List[dict]: +def read_installed(ubuntu_distro: bool) -> List[dict]: res = run_cmd('{} list'.format(BASE_CMD), print_error=False) apps = [] @@ -99,7 +98,7 @@ def read_installed() -> List[dict]: if idx > 0 and app_str: apps.append(app_str_to_json(app_str)) - if UBUNTU_DISTRO: + if ubuntu_distro: path = '/snap/{}/current/meta/snap.yaml' else: path = '/var/lib/snapd/snap/{}/current/meta/snap.yaml' diff --git a/bauh/view/util/util.py b/bauh/view/util/util.py index 8c96029b..f4f3efc7 100644 --- a/bauh/view/util/util.py +++ b/bauh/view/util/util.py @@ -8,6 +8,7 @@ from typing import Tuple from PyQt5.QtCore import QCoreApplication from bauh import __app_name__ +from bauh.commons.system import run_cmd from bauh.view.util import resource @@ -62,3 +63,13 @@ def restart_app(show_panel: bool): subprocess.Popen(restart_cmd) QCoreApplication.exit() + +def get_distro(): + if os.path.exists('/etc/arch-release'): + return 'arch' + + if os.path.exists('/proc/version'): + if 'ubuntu' in run_cmd('cat /proc/version').lower(): + return 'ubuntu' + + return 'unknown'