예제 #1
0
    def search(self,
               words: str,
               disk_loader: DiskCacheLoader,
               limit: int = -1,
               is_url: bool = False) -> SearchResult:
        if is_url or (not snap.is_installed() and not snapd.is_running()):
            return SearchResult([], [], 0)

        snapd_client = SnapdClient(self.logger)
        apps_found = snapd_client.query(words)

        res = SearchResult([], [], 0)

        if apps_found:
            installed = self.read_installed(disk_loader).installed

            for app_json in apps_found:
                already_installed = None

                if installed:
                    already_installed = [
                        i for i in installed if i.id == app_json.get('id')
                    ]
                    already_installed = already_installed[
                        0] if already_installed else None

                if already_installed:
                    res.installed.append(already_installed)
                else:
                    res.new.append(self._map_to_app(app_json, installed=False))

        res.total = len(res.installed) + len(res.new)
        return res
예제 #2
0
    def list_warnings(self, internet_available: bool) -> List[str]:
        if snap.is_installed():
            if not snap.is_snapd_running():
                snap_bold = bold('Snap')
                return [
                    self.i18n['snap.notification.snapd_unavailable'].format(
                        bold('snapd'), snap_bold),
                    self.i18n['snap.notification.snap.disable'].format(
                        snap_bold,
                        bold('{} > {}'.format(
                            self.i18n['settings'].capitalize(),
                            self.i18n['core.config.tab.types'])))
                ]

            elif internet_available:
                available, output = snap.is_api_available()

                if not available:
                    self.logger.warning(
                        'It seems Snap API is not available. Search output: {}'
                        .format(output))
                    return [
                        self.i18n['snap.notifications.api.unavailable'].format(
                            bold('Snaps'), bold('Snap'))
                    ]
예제 #3
0
    def downgrade(self, pkg: SnapApplication, root_password: str,
                  watcher: ProcessWatcher) -> bool:
        if not snap.is_installed():
            watcher.print("'snap' seems not to be installed")
            return False
        if not snapd.is_running():
            watcher.print("'snapd' seems not to be running")
            return False

        return ProcessHandler(watcher).handle_simple(
            snap.downgrade_and_stream(pkg.name, root_password))[0]
예제 #4
0
    def uninstall(self, pkg: SnapApplication, root_password: str,
                  watcher: ProcessWatcher,
                  disk_loader: DiskCacheLoader) -> TransactionResult:
        if snap.is_installed() and snapd.is_running():
            uninstalled = ProcessHandler(watcher).handle_simple(
                snap.uninstall_and_stream(pkg.name, root_password))[0]

            if uninstalled:
                if self.suggestions_cache:
                    self.suggestions_cache.delete(pkg.name)

                return TransactionResult(success=True,
                                         installed=None,
                                         removed=[pkg])

        return TransactionResult.fail()
예제 #5
0
 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_installed() and snapd.is_running():
         snapd_client = SnapdClient(self.logger)
         app_names = {a['snap'] for a in snapd_client.list_only_apps()}
         installed = [
             self._map_to_app(app_json=appjson,
                              installed=True,
                              disk_loader=disk_loader,
                              is_application=app_names
                              and appjson['name'] in app_names)
             for appjson in snapd_client.list_all_snaps()
         ]
         return SearchResult(installed, None, len(installed))
     else:
         return SearchResult([], None, 0)
예제 #6
0
 def can_work(self) -> bool:
     return snap.is_installed()
예제 #7
0
파일: controller.py 프로젝트: jayvdb/bauh
 def list_warnings(self) -> List[str]:
     if snap.is_installed() and not snap.is_snapd_running():
         snap_bold = bold('Snap')
         return [self.i18n['snap.notification.snapd_unavailable'].format(bold('snapd'), snap_bold),
                 self.i18n['snap.notification.snap.disable'].format(snap_bold, bold(self.i18n['manage_window.settings.gems']))]
예제 #8
0
    def install(self, pkg: SnapApplication, root_password: str,
                disk_loader: DiskCacheLoader,
                watcher: ProcessWatcher) -> TransactionResult:
        # retrieving all installed so it will be possible to know the additional installed runtimes after the operation succeeds
        if not snap.is_installed():
            watcher.print("'snap' seems not to be installed")
            return TransactionResult.fail()

        if not snapd.is_running():
            watcher.print("'snapd' seems not to be running")
            return TransactionResult.fail()

        installed_names = {
            s['name']
            for s in SnapdClient(self.logger).list_all_snaps()
        }

        client = SnapdClient(self.logger)
        snap_config = read_config()

        try:
            channel = self._request_channel_installation(
                pkg=pkg,
                snap_config=snap_config,
                snapd_client=client,
                watcher=watcher)
            pkg.channel = channel
        except:
            watcher.print('Aborted by user')
            return TransactionResult.fail()

        res, output = ProcessHandler(watcher).handle_simple(
            snap.install_and_stream(app_name=pkg.name,
                                    confinement=pkg.confinement,
                                    root_password=root_password,
                                    channel=channel))

        if 'error:' in output:
            res = False
            if 'not available on stable' in output:
                channels = RE_AVAILABLE_CHANNELS.findall(output)

                if channels:
                    opts = [
                        InputOption(label=c[0], value=c[1]) for c in channels
                    ]
                    channel_select = SingleSelectComponent(
                        type_=SelectViewType.RADIO,
                        label='',
                        options=opts,
                        default_option=opts[0])
                    body = '<p>{}.</p>'.format(
                        self.i18n['snap.install.available_channels.message'].
                        format(bold(self.i18n['stable']), bold(pkg.name)))
                    body += '<p>{}:</p>'.format(
                        self.i18n['snap.install.available_channels.help'])

                    if watcher.request_confirmation(
                            title=self.
                            i18n['snap.install.available_channels.title'],
                            body=body,
                            components=[channel_select],
                            confirmation_label=self.i18n['continue'],
                            deny_label=self.i18n['cancel']):
                        self.logger.info(
                            "Installing '{}' with the custom command '{}'".
                            format(pkg.name, channel_select.value))
                        res = ProcessHandler(watcher).handle(
                            SystemProcess(
                                new_root_subprocess(
                                    channel_select.value.value.split(' '),
                                    root_password=root_password)))
                        return self._gen_installation_response(
                            success=res,
                            pkg=pkg,
                            installed=installed_names,
                            disk_loader=disk_loader)
                else:
                    self.logger.error(
                        "Could not find available channels in the installation output: {}"
                        .format(output))

        return self._gen_installation_response(success=res,
                                               pkg=pkg,
                                               installed=installed_names,
                                               disk_loader=disk_loader)
예제 #9
0
파일: controller.py 프로젝트: vinifmor/bauh
 def can_work(self) -> Tuple[bool, Optional[str]]:
     return (True, None) if snap.is_installed() else (
         False, self.i18n['missing_dep'].format(dep=bold('snap')))