コード例 #1
0
    def __fill_provided_map(self, context: UpdateRequirementsContext):
        ti = time.time()
        self.logger.info("Filling provided names")
        context.installed_names = pacman.list_installed_names()
        installed_to_ignore = set()

        for pkgname in context.to_update:
            pacman.fill_provided_map(pkgname, pkgname, context.provided_map)
            installed_to_ignore.add(pkgname)

            pdata = context.pkgs_data.get(pkgname)
            if pdata and pdata['p']:
                pacman.fill_provided_map('{}={}'.format(pkgname, pdata['v']), pkgname, context.provided_map)
                for p in pdata['p']:
                    pacman.fill_provided_map(p, pkgname, context.provided_map)
                    split_provided = p.split('=')

                    if len(split_provided) > 1 and split_provided[0] != p:
                        pacman.fill_provided_map(split_provided[0], pkgname, context.provided_map)

        if installed_to_ignore:  # filling the provided names of the installed
            installed_to_query = context.installed_names.difference(installed_to_ignore)

            if installed_to_query:
                context.provided_map.update(pacman.map_provided(remote=False, pkgs=installed_to_query))

        tf = time.time()
        self.logger.info("Filling provided names took {0:.2f} seconds".format(tf - ti))
コード例 #2
0
    def __fill_provided_map(self,
                            context: UpdateRequirementsContext,
                            pkgs: Dict[str, ArchPackage],
                            fill_installed: bool = True):
        if pkgs:
            ti = time.time()
            self.logger.info("Filling provided names")

            if not context.installed_names:
                context.installed_names = pacman.list_installed_names()

            installed_to_ignore = set()

            for pkgname in pkgs:
                pacman.fill_provided_map(pkgname, pkgname,
                                         context.provided_map)

                if fill_installed:
                    installed_to_ignore.add(pkgname)

                pdata = context.pkgs_data.get(pkgname)
                if pdata and pdata['p']:
                    pacman.fill_provided_map(
                        '{}={}'.format(pkgname, pdata['v']), pkgname,
                        context.provided_map)

                    ver_split = pdata['v'].split('-')

                    if len(ver_split) > 1:
                        pacman.fill_provided_map(
                            '{}={}'.format(pkgname, '-'.join(ver_split[0:-1])),
                            pkgname, context.provided_map)

                    for p in pdata['p']:
                        pacman.fill_provided_map(p, pkgname,
                                                 context.provided_map)
                        split_provided = p.split('=')

                        if len(split_provided) > 1 and split_provided[0] != p:
                            pacman.fill_provided_map(split_provided[0],
                                                     pkgname,
                                                     context.provided_map)

            if installed_to_ignore:  # filling the provided names of the installed
                installed_to_query = context.installed_names.difference(
                    installed_to_ignore)

                if installed_to_query:
                    context.provided_map.update(
                        pacman.map_provided(remote=False,
                                            pkgs=installed_to_query))

            tf = time.time()
            self.logger.info(
                "Filling provided names took {0:.2f} seconds".format(tf - ti))
コード例 #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 プロジェクト: marciopocebon/bauh
    def run(self):
        ti = time.time()
        self.taskman.update_progress(
            self.task_id, 0, self.i18n['task.waiting_task'].format(
                self.create_config.task_name))
        self.create_config.join()

        config = self.create_config.config
        aur_supported, repositories = aur.is_supported(
            config), config['repositories']

        self.taskman.update_progress(self.task_id, 1, None)
        if not any([aur_supported, repositories]):
            self.taskman.update_progress(self.task_id, 100,
                                         self.i18n['arch.task.disabled'])
            self.taskman.finish_task(self.task_id)
            return

        self.logger.info("Checking already cached package data")
        self._update_progress(1, self.i18n['arch.task.disk_cache.checking'])

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

        not_cached_names = None

        self._update_progress(15, self.i18n['arch.task.disk_cache.checking'])
        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)
            self._update_progress(20,
                                  self.i18n['arch.task.disk_cache.checking'])

            if not not_cached_names:
                self.taskman.update_progress(self.task_id, 100, '')
                self.taskman.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')

        if aur_supported and self.aur_indexer:
            self.taskman.update_progress(
                self.task_id, 20,
                self.i18n['arch.task.disk_cache.waiting_aur_index'].format(
                    bold(self.i18n['arch.task.aur.index.status'])))
            self.aur_indexer.join()

        self._update_progress(21, self.i18n['arch.task.disk_cache.checking'])
        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._update_progress(35, self.i18n['arch.task.disk_cache.checking'])

        saved = 0

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

        # overwrite == True because the verification already happened
        self._update_progress(40,
                              self.i18n['arch.task.disk_cache.reading_files'])
        saved += disk.write_several(
            pkgs=pkgs,
            after_desktop_files=self._notify_reading_files,
            after_written=self.update_indexed,
            overwrite=True)
        self.taskman.update_progress(self.task_id, 100, None)
        self.taskman.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))