mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
refactoring: distro check for arch and snap gems
This commit is contained in:
@@ -12,7 +12,7 @@ class ApplicationContext:
|
|||||||
|
|
||||||
def __init__(self, disk_cache: bool, download_icons: bool, http_client: HttpClient, app_root_dir: str, i18n: dict,
|
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,
|
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 disk_cache: if package data should be cached to disk
|
||||||
:param download_icons: if packages icons should be downloaded
|
:param download_icons: if packages icons should be downloaded
|
||||||
@@ -22,7 +22,8 @@ class ApplicationContext:
|
|||||||
:param cache_factory:
|
:param cache_factory:
|
||||||
:param disk_loader_factory:
|
:param disk_loader_factory:
|
||||||
:param logger: a logger instance
|
:param logger: a logger instance
|
||||||
:param file_downloader:
|
:param file_downloader
|
||||||
|
:param distro
|
||||||
"""
|
"""
|
||||||
self.disk_cache = disk_cache
|
self.disk_cache = disk_cache
|
||||||
self.download_icons = download_icons
|
self.download_icons = download_icons
|
||||||
@@ -34,6 +35,7 @@ class ApplicationContext:
|
|||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.file_downloader = file_downloader
|
self.file_downloader = file_downloader
|
||||||
self.arch_x86_64 = sys.maxsize > 2**32
|
self.arch_x86_64 = sys.maxsize > 2**32
|
||||||
|
self.distro = distro
|
||||||
|
|
||||||
def is_system_x86_64(self):
|
def is_system_x86_64(self):
|
||||||
return self.arch_x86_64
|
return self.arch_x86_64
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ def main():
|
|||||||
icon_cache = cache_factory.new(args.icon_exp)
|
icon_cache = cache_factory.new(args.icon_exp)
|
||||||
|
|
||||||
http_client = HttpClient(logger)
|
http_client = HttpClient(logger)
|
||||||
|
|
||||||
context = ApplicationContext(i18n=i18n,
|
context = ApplicationContext(i18n=i18n,
|
||||||
http_client=http_client,
|
http_client=http_client,
|
||||||
disk_cache=args.disk_cache,
|
disk_cache=args.disk_cache,
|
||||||
@@ -40,6 +41,7 @@ def main():
|
|||||||
cache_factory=cache_factory,
|
cache_factory=cache_factory,
|
||||||
disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache, logger=logger),
|
disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache, logger=logger),
|
||||||
logger=logger,
|
logger=logger,
|
||||||
|
distro=util.get_distro(),
|
||||||
file_downloader=AdaptableFileDownloader(logger, bool(args.download_mthread),
|
file_downloader=AdaptableFileDownloader(logger, bool(args.download_mthread),
|
||||||
i18n, http_client))
|
i18n, http_client))
|
||||||
user_config = config.read()
|
user_config = config.read()
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class ArchManager(SoftwareManager):
|
|||||||
self.comp_optimizer = ArchCompilationOptimizer(context.logger)
|
self.comp_optimizer = ArchCompilationOptimizer(context.logger)
|
||||||
self.logger = context.logger
|
self.logger = context.logger
|
||||||
self.enabled = True
|
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):
|
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'])
|
app = self.mapper.map_api_data(apidata, installed_pkgs['not_signed'])
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class SnapManager(SoftwareManager):
|
|||||||
self.enabled = True
|
self.enabled = True
|
||||||
self.http_client = context.http_client
|
self.http_client = context.http_client
|
||||||
self.logger = context.logger
|
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:
|
def map_json(self, app_json: dict, installed: bool, disk_loader: DiskCacheLoader, internet: bool = True) -> SnapApplication:
|
||||||
app = SnapApplication(publisher=app_json.get('publisher'),
|
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:
|
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():
|
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))
|
return SearchResult(installed, None, len(installed))
|
||||||
else:
|
else:
|
||||||
return SearchResult([], None, 0)
|
return SearchResult([], None, 0)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from bauh.gems.snap.model import SnapApplication
|
|||||||
BASE_CMD = 'snap'
|
BASE_CMD = 'snap'
|
||||||
RE_SNAPD_STATUS = re.compile('\s+')
|
RE_SNAPD_STATUS = re.compile('\s+')
|
||||||
SNAPD_RUNNING_STATUS = {'listening', 'running'}
|
SNAPD_RUNNING_STATUS = {'listening', 'running'}
|
||||||
UBUNTU_DISTRO = 'ubuntu' in run_cmd('cat /proc/version').lower()
|
|
||||||
|
|
||||||
|
|
||||||
def is_installed():
|
def is_installed():
|
||||||
@@ -86,7 +85,7 @@ def get_info(app_name: str, attrs: tuple = None):
|
|||||||
return data
|
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)
|
res = run_cmd('{} list'.format(BASE_CMD), print_error=False)
|
||||||
|
|
||||||
apps = []
|
apps = []
|
||||||
@@ -99,7 +98,7 @@ def read_installed() -> List[dict]:
|
|||||||
if idx > 0 and app_str:
|
if idx > 0 and app_str:
|
||||||
apps.append(app_str_to_json(app_str))
|
apps.append(app_str_to_json(app_str))
|
||||||
|
|
||||||
if UBUNTU_DISTRO:
|
if ubuntu_distro:
|
||||||
path = '/snap/{}/current/meta/snap.yaml'
|
path = '/snap/{}/current/meta/snap.yaml'
|
||||||
else:
|
else:
|
||||||
path = '/var/lib/snapd/snap/{}/current/meta/snap.yaml'
|
path = '/var/lib/snapd/snap/{}/current/meta/snap.yaml'
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from typing import Tuple
|
|||||||
from PyQt5.QtCore import QCoreApplication
|
from PyQt5.QtCore import QCoreApplication
|
||||||
|
|
||||||
from bauh import __app_name__
|
from bauh import __app_name__
|
||||||
|
from bauh.commons.system import run_cmd
|
||||||
from bauh.view.util import resource
|
from bauh.view.util import resource
|
||||||
|
|
||||||
|
|
||||||
@@ -62,3 +63,13 @@ def restart_app(show_panel: bool):
|
|||||||
subprocess.Popen(restart_cmd)
|
subprocess.Popen(restart_cmd)
|
||||||
QCoreApplication.exit()
|
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'
|
||||||
|
|||||||
Reference in New Issue
Block a user