コード例 #1
0
ファイル: worker.py プロジェクト: lavkeshg/bauh
    def run(self):
        if not any([self.aur, self.repositories]):
            return

        ti = time.time()
        self.task_man.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())

        self.logger.info('Pre-caching installed Arch packages data to disk')

        installed = self.controller.read_installed(disk_loader=None, internet_available=self.internet_available,
                                                   only_apps=False, pkg_types=None, limit=-1).installed

        self.task_man.update_progress(self.task_id, 0, self.i18n['arch.task.disk_cache.reading'])

        saved = 0
        pkgs = {p.name: p for p in installed if ((self.aur and p.repository == 'aur') or (self.repositories and p.repository != 'aur')) and not os.path.exists(p.get_disk_cache_path())}

        self.to_index = len(pkgs)
        self.progress = self.to_index * 2
        self.update_prepared(None, add=False)

        saved += disk.save_several(pkgs, when_prepared=self.update_prepared, after_written=self.update_indexed)
        self.task_man.update_progress(self.task_id, 100, None)
        self.task_man.finish_task(self.task_id)

        tf = time.time()
        time_msg = 'Took {0:.2f} seconds'.format(tf - ti)
        self.logger.info('Pre-cached data of {} Arch packages to the disk. {}'.format(saved, time_msg))
コード例 #2
0
    def run(self):
        if self.disk_cache:
            self.logger.info('Pre-caching installed AUR packages data to disk')
            installed = pacman.list_and_map_installed()

            saved = 0
            if installed and installed['not_signed']:
                saved = disk.save_several({app for app in installed['not_signed']}, 'aur', overwrite=False)

            self.logger.info('Pre-cached data of {} AUR packages to the disk'.format(saved))
コード例 #3
0
ファイル: worker.py プロジェクト: Jocix123/bauh
    def run(self):
        if not any([self.aur, self.repositories]):
            return

        ti = time.time()
        self.task_man.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())

        self.task_man.update_progress(self.task_id, 1, '')

        self.logger.info("Checking already cached package data")

        cache_dirs = [fpath for fpath in glob.glob('{}/*'.format(self.installed_cache_dir)) if os.path.isdir(fpath)]

        not_cached_names = None

        if cache_dirs:  # if there are cache data
            installed_names = pacman.list_installed_names()
            cached_pkgs = {cache_dir.split('/')[-1] for cache_dir in cache_dirs}

            not_cached_names = installed_names.difference(cached_pkgs)
            if not not_cached_names:
                self.task_man.update_progress(self.task_id, 100, '')
                self.task_man.finish_task(self.task_id)
                tf = time.time()
                time_msg = '{0:.2f} seconds'.format(tf - ti)
                self.logger.info('Finished: no package data to cache ({})'.format(time_msg))
                return

        self.logger.info('Pre-caching installed Arch packages data to disk')

        installed = self.controller.read_installed(disk_loader=None, internet_available=self.internet_available,
                                                   only_apps=False, pkg_types=None, limit=-1, names=not_cached_names,
                                                   wait_disk_cache=False).installed

        self.task_man.update_progress(self.task_id, 0, self.i18n['arch.task.disk_cache.reading'])

        saved = 0
        pkgs = {p.name: p for p in installed if ((self.aur and p.repository == 'aur') or (self.repositories and p.repository != 'aur')) and not os.path.exists(p.get_disk_cache_path())}

        self.to_index = len(pkgs)
        self.progress = self.to_index * 2
        self.update_prepared(None, add=False)

        # overwrite == True because the verification already happened
        saved += disk.save_several(pkgs, when_prepared=self.update_prepared, after_written=self.update_indexed, overwrite=True)
        self.task_man.update_progress(self.task_id, 100, None)
        self.task_man.finish_task(self.task_id)

        tf = time.time()
        time_msg = '{0:.2f} seconds'.format(tf - ti)
        self.logger.info('Finished: pre-cached data of {} Arch packages to the disk ({})'.format(saved, time_msg))
コード例 #4
0
ファイル: worker.py プロジェクト: johnmcculloch1/bauh
    def run(self):
        if not any([self.aur, self.repositories]):
            return

        ti = time.time()
        self.task_man.register_task(self.task_id,
                                    self.i18n['arch.task.disk_cache'],
                                    get_icon_path())

        self.logger.info('Pre-caching installed Arch packages data to disk')
        installed = pacman.map_installed(repositories=self.repositories,
                                         aur=self.aur)

        self.task_man.update_progress(
            self.task_id, 0, self.i18n['arch.task.disk_cache.reading'])
        for k in ('signed', 'not_signed'):
            installed[k] = {
                p
                for p in installed[k]
                if not os.path.exists(ArchPackage.disk_cache_path(p))
            }

        saved = 0
        pkgs = {*installed['signed'], *installed['not_signed']}

        repo_map = {}

        if installed['not_signed']:
            repo_map.update({p: 'aur' for p in installed['not_signed']})

        if installed['signed']:
            repo_map.update(pacman.map_repositories(installed['signed']))

        self.to_index = len(pkgs)
        self.progress = self.to_index * 2
        self.update_prepared(None, add=False)

        saved += disk.save_several(pkgs,
                                   repo_map,
                                   when_prepared=self.update_prepared,
                                   after_written=self.update_indexed)
        self.task_man.update_progress(self.task_id, 100, None)
        self.task_man.finish_task(self.task_id)

        tf = time.time()
        time_msg = 'Took {0:.2f} seconds'.format(tf - ti)
        self.logger.info(
            'Pre-cached data of {} Arch packages to the disk. {}'.format(
                saved, time_msg))
コード例 #5
0
ファイル: controller.py プロジェクト: jayvdb/bauh
    def _install(self,
                 pkgname: str,
                 maintainer: str,
                 root_password: str,
                 mirror: str,
                 handler: ProcessHandler,
                 install_file: str = None,
                 pkgdir: str = '.',
                 change_progress: bool = True):
        check_install_output = []
        pkgpath = install_file if install_file else pkgname

        handler.watcher.change_substatus(
            self.i18n['arch.checking.conflicts'].format(bold(pkgname)))

        for check_out in SimpleProcess(
            ['pacman', '-U' if install_file else '-S', pkgpath],
                root_password=root_password,
                cwd=pkgdir).instance.stdout:
            check_install_output.append(check_out.decode())

        self._update_progress(handler.watcher, 70, change_progress)
        if check_install_output and 'conflict' in check_install_output[-1]:
            conflicting_apps = [
                w[0] for w in re.findall(r'((\w|\-|\.)+)\s(and|are)',
                                         check_install_output[-1])
            ]
            conflict_msg = ' {} '.format(self.i18n['and']).join(
                [bold(c) for c in conflicting_apps])
            if not handler.watcher.request_confirmation(
                    title=self.i18n['arch.install.conflict.popup.title'],
                    body=self.i18n['arch.install.conflict.popup.body'].format(
                        conflict_msg)):
                handler.watcher.print(self.i18n['action.cancelled'])
                return False
            else:  # uninstall conflicts
                self._update_progress(handler.watcher, 75, change_progress)
                to_uninstall = [
                    conflict for conflict in conflicting_apps
                    if conflict != pkgname
                ]

                for conflict in to_uninstall:
                    handler.watcher.change_substatus(
                        self.i18n['arch.uninstalling.conflict'].format(
                            bold(conflict)))
                    if not self._uninstall(conflict, root_password, handler):
                        handler.watcher.show_message(
                            title=self.i18n['error'],
                            body=self.i18n['arch.uninstalling.conflict.fail'].
                            format(bold(conflict)),
                            type_=MessageType.ERROR)
                        return False

        handler.watcher.change_substatus(
            self.i18n['arch.installing.package'].format(bold(pkgname)))
        self._update_progress(handler.watcher, 80, change_progress)
        installed = handler.handle(
            pacman.install_as_process(pkgpath=pkgpath,
                                      root_password=root_password,
                                      aur=install_file is not None,
                                      pkgdir=pkgdir))
        self._update_progress(handler.watcher, 95, change_progress)

        if installed and self.context.disk_cache:
            handler.watcher.change_substatus(
                self.i18n['status.caching_data'].format(bold(pkgname)))
            if self.context.disk_cache:
                disk.save_several({pkgname},
                                  mirror=mirror,
                                  maintainer=maintainer,
                                  overwrite=True)

            self._update_progress(handler.watcher, 100, change_progress)

        return installed