mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
refactoring: distro check for arch and snap gems
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user