diff --git a/bauh/gems/snap/controller.py b/bauh/gems/snap/controller.py index affb7861..220b90e3 100644 --- a/bauh/gems/snap/controller.py +++ b/bauh/gems/snap/controller.py @@ -125,7 +125,12 @@ class SnapManager(SoftwareManager): raise Exception("'get_history' is not supported by {}".format(pkg.__class__.__name__)) def install(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool: - return ProcessHandler(watcher).handle(SystemProcess(subproc=snap.install_and_stream(pkg.name, pkg.confinement, root_password))) + res = ProcessHandler(watcher).handle(SystemProcess(subproc=snap.install_and_stream(pkg.name, pkg.confinement, root_password))) + + if res: + pkg.has_apps_field = snap.has_apps_field(pkg.name, self.ubuntu_distro) + + return res def is_enabled(self) -> bool: return self.enabled diff --git a/bauh/gems/snap/snap.py b/bauh/gems/snap/snap.py index ec645799..77384628 100644 --- a/bauh/gems/snap/snap.py +++ b/bauh/gems/snap/snap.py @@ -98,12 +98,9 @@ def read_installed(ubuntu_distro: bool) -> List[dict]: if idx > 0 and app_str: apps.append(app_str_to_json(app_str)) - if ubuntu_distro: - path = '/snap/{}/current/meta/snap.yaml' - else: - path = '/var/lib/snapd/snap/{}/current/meta/snap.yaml' + info_path = _get_app_info_path(ubuntu_distro) - info_out = new_subprocess(['cat', *[path.format(a['name']) for a in apps]]).stdout + info_out = new_subprocess(['cat', *[info_path.format(a['name']) for a in apps]]).stdout idx = -1 for o in new_subprocess(['grep', '-E', '(summary|apps)', '--colour=never'], stdin=info_out).stdout: @@ -119,6 +116,29 @@ def read_installed(ubuntu_distro: bool) -> List[dict]: return apps +def _get_app_info_path(ubuntu_distro: bool) -> str: + if ubuntu_distro: + return '/snap/{}/current/meta/snap.yaml' + else: + return '/var/lib/snapd/snap/{}/current/meta/snap.yaml' + + +def has_apps_field(name: str, ubuntu_distro: bool) -> bool: + info_path = _get_app_info_path(ubuntu_distro) + + info_out = new_subprocess(['cat', info_path.format(name)]).stdout + + res = False + for o in new_subprocess(['grep', '-E', 'apps', '--colour=never'], stdin=info_out).stdout: + if o: + line = o.decode() + + if line.startswith('apps:'): + res = True + + return res + + def search(word: str, exact_name: bool = False) -> List[dict]: apps = []