From 1db0459ae3a8a2240ffb9585bb1c378d7b17acbb Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Thu, 21 Aug 2008 15:03:30 +0200 Subject: Add apt.Cache.clear() method (taken from GDebi), which re initializes the dependecy cache. --- apt/cache.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt/cache.py') diff --git a/apt/cache.py b/apt/cache.py index bbf2165b..3df2b4a6 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -232,6 +232,10 @@ class Cache(object): fetcher.Shutdown() return (res == pm.ResultCompleted) + def clear(self): + """ Unmark all changes """ + self._depcache.Init() + # cache changes def cachePostChange(self): " called internally if the cache has changed, emit a signal then " -- cgit v1.2.3 From 312c6465f3ac7da68c610a01b4856cb45ae62b34 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Thu, 21 Aug 2008 18:34:41 +0200 Subject: Add apt.cache.Cache.isVirtualPackage() and apt.cache.Cache.getProvidingPackages() - taken from GDebi. --- apt/cache.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'apt/cache.py') diff --git a/apt/cache.py b/apt/cache.py index 3df2b4a6..e59e30c3 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -182,6 +182,51 @@ class Cache(object): finally: os.close(lock) + def isVirtualPackage(self, name): + """ + Return True if the package of the given name is a virtual package + """ + try: + virtual_pkg = self._cache[name] + except KeyError: + return False + if len(virtual_pkg.VersionList) == 0: + return True + return False + + def getProvidingPackages(self, virtual): + """ + Return a list of packages which provide the virtual package of the + specified name + """ + providers = [] + try: + vp = self._cache[virtual] + if len(vp.VersionList) != 0: + return providers + except IndexError: + return providers + for pkg in self: + v = self._depcache.GetCandidateVer(pkg._pkg) + if v == None: + continue + for p in v.ProvidesList: + #print virtual + #print p[0] + if virtual == p[0]: + # we found a pkg that provides this virtual + # pkg, check if the proivdes is any good + providers.append(pkg) + #cand = self._cache[pkg.name] + #candver = self._cache._depcache.GetCandidateVer(cand._pkg) + #instver = cand._pkg.CurrentVer + #res = apt_pkg.CheckDep(candver.VerStr,oper,ver) + #if res == True: + # self._dbg(1,"we can use %s" % pkg.name) + # or_found = True + # break + return providers + def update(self, fetchProgress=None): " run the equivalent of apt-get update " lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" -- cgit v1.2.3 From fcb99cb79276d87ec47dedd7be3b0eefd278a0df Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Thu, 21 Aug 2008 18:36:31 +0200 Subject: Small fix: catch dict exceptions in getProvidingPackages --- apt/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt/cache.py') diff --git a/apt/cache.py b/apt/cache.py index e59e30c3..3fd1e996 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -204,7 +204,7 @@ class Cache(object): vp = self._cache[virtual] if len(vp.VersionList) != 0: return providers - except IndexError: + except KeyError: return providers for pkg in self: v = self._depcache.GetCandidateVer(pkg._pkg) -- cgit v1.2.3