コード例 #1
0
ファイル: cache.py プロジェクト: xaadim/python-apt
    def open(self, progress):
        """ Open the package cache, after that it can be used like
            a dictionary
        """
        self._runCallbacks("cache_pre_open")
        self._cache = apt_pkg.GetCache(progress)
        self._depcache = apt_pkg.GetDepCache(self._cache)
        self._records = apt_pkg.GetPkgRecords(self._cache)
        self._list = apt_pkg.GetPkgSourceList()
        self._list.ReadMainList()
        self._dict = {}

        # build the packages dict
        if progress != None:
            progress.Op = "Building data structures"
        i = last = 0
        size = len(self._cache.Packages)
        for pkg in self._cache.Packages:
            if progress != None and last + 100 < i:
                progress.update(i / float(size) * 100)
                last = i
            # drop stuff with no versions (cruft)
            if len(pkg.VersionList) > 0:
                self._dict[pkg.Name] = Package(self._cache, self._depcache,
                                               self._records, self._list, self,
                                               pkg)

            i += 1
        if progress != None:
            progress.done()
        self._runCallbacks("cache_post_open")
コード例 #2
0
 def _set_pkg_version(self, package: apt.Package, version: str) -> None:
     # Set cadidate version to a specific version if available
     if version in package.versions:
         version = package.versions.get(version)
         package.candidate = version
     else:
         raise errors.PackageNotFoundError("{}={}".format(package.name, version))
コード例 #3
0
 def _append_to_list(self, pkglist, pkg):
     name = pkg.get_fullname(pretty=True)
     try:
         pkglist.append(self._weakref[name])
     except KeyError:
         package = self._weakref[name] = Package(self, pkg)
         pkglist.append(package)
コード例 #4
0
ファイル: cache.py プロジェクト: pombreda/OnionScraper
 def __getitem__(self, key):
     """ look like a dictionary (get key) """
     try:
         return self._weakref[key]
     except KeyError:
         if key in self._set or key in self._fullnameset:
             key = str(key)
             pkg = self._weakref[key] = Package(self, self._cache[key])
             return pkg
         else:
             raise KeyError('The cache has no package named %r' % key)
コード例 #5
0
    def _rawpkg_to_pkg(self, rawpkg):
        """Returns the apt.Package object for an apt_pkg.Package object.

        .. versionadded:: 1.0.0
        """
        fullname = rawpkg.get_fullname(pretty=False)
        try:
            pkg = self._weakref[fullname]
        except KeyError:
            pkg = Package(self, rawpkg)
            self._weakref[fullname] = pkg
        return pkg
コード例 #6
0
ファイル: cache.py プロジェクト: pombreda/OnionScraper
 def get_changes(self):
     """ Get the marked changes """
     changes = []
     marked_keep = self._depcache.marked_keep
     for pkg in self._cache.packages:
         if not marked_keep(pkg):
             name = pkg.get_fullname(pretty=True)
             try:
                 changes.append(self._weakref[name])
             except KeyError:
                 package = self._weakref[name] = Package(self, pkg)
                 changes.append(package)
     return changes
コード例 #7
0
ファイル: cache.py プロジェクト: Edusantara/python-apt
    def get_providing_packages(self,
                               pkgname,
                               candidate_only=True,
                               include_nonvirtual=False):
        """Return a list of all packages providing a package.

        Return a list of packages which provide the virtual package of the
        specified name.

        If 'candidate_only' is False, return all packages with at
        least one version providing the virtual package. Otherwise,
        return only those packages where the candidate version
        provides the virtual package.

        If 'include_nonvirtual' is True then it will search for all
        packages providing pkgname, even if pkgname is not itself
        a virtual pkg.
        """

        providers = set()
        get_candidate_ver = self._depcache.get_candidate_ver
        try:
            vp = self._cache[pkgname]
            if vp.has_versions and not include_nonvirtual:
                return list(providers)
        except KeyError:
            return list(providers)

        for provides, providesver, version in vp.provides_list:
            pkg = version.parent_pkg
            if not candidate_only or (version == get_candidate_ver(pkg)):
                name = pkg.get_fullname(pretty=True)
                try:
                    providers.add(self._weakref[name])
                except KeyError:
                    package = self._weakref[name] = Package(self, pkg)
                    providers.add(package)
        return list(providers)