def main(): apt_pkg.init() cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) depcache.Init() i = 0 print "Running PkgRecords test on all packages:" for pkg in cache.Packages: i += 1 records = apt_pkg.GetPkgRecords(cache) if len(pkg.VersionList) == 0: #print "no available version, cruft" continue version = depcache.GetCandidateVer(pkg) if not version: continue file, index = version.FileList.pop(0) if records.Lookup((file, index)): #print records.FileName x = records.FileName y = records.LongDesc pass print "\r%i/%i=%.3f%% " % (i, cache.PackageCount, (float(i) / float(cache.PackageCount) * 100)),
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")
def get_single_package(name): if type(package) != str: raise TypeError("Expected string") cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) records = apt_pkg.GetPkgRecords(cache) sourcelist = apt_pkg.GetPkgSourceList() pkg = apt.package.Package(cache, depcache, records, sourcelist, None, cache[sys.argv[1]]) return pkg
def load(self): """ Regenerates the fake configuration and load the packages server. """ if not self.loaded: log.msg("Loading Packages database for "+self.status_dir,'apt_pkg') shutil.rmtree(self.status_dir+'/apt/lists/') os.makedirs(self.status_dir+'/apt/lists/partial') sources = open(self.status_dir+'/'+'apt/etc/sources.list', 'w') for file in self.packages.keys(): # we should probably clear old entries from self.packages and # take into account the recorded mtime as optimization fake_uri='http://apt-proxy:'+file source_line='deb '+dirname(fake_uri)+'/ /' listpath=(self.status_dir+'/apt/lists/' +apt_pkg.URItoFileName(fake_uri)) sources.write(source_line+'\n') try: #we should empty the directory instead os.unlink(listpath) except: pass os.symlink('../../../../../'+file, listpath) sources.close() for key, value in self.local_config.items(): apt_pkg.Config[key] = value apt_pkg.InitSystem() if log.isEnabled('apt'): self.cache = apt_pkg.GetCache() else: # apt_pkg prints progress messages to stdout, disable self.__save_stdout() self.cache = apt_pkg.GetCache() self.__restore_stdout() self.records = apt_pkg.GetPkgRecords(self.cache) self.loaded = 1
import apt_pkg apt_pkg.init() apt_pkg.Config.Set("APT::Acquire::Translation","de") cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) pkg = cache["gcc"] cand = depcache.GetCandidateVer(pkg) print cand desc = cand.TranslatedDescription print desc print desc.FileList (f,index) = desc.FileList.pop(0) records = apt_pkg.GetPkgRecords(cache) records.Lookup((f,index)) desc = records.LongDesc print len(desc) print desc