refactoring: distro check for arch and snap gems

This commit is contained in:
Vinicius Moreira
2019-10-09 18:14:54 -03:00
parent dd56a515fb
commit 69dd9b9396
6 changed files with 22 additions and 7 deletions

View File

@@ -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'])

View File

@@ -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)

View File

@@ -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'