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 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 main(): apt_pkg.init() cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) depcache.Init() i=0 all=cache.PackageCount print "Running DepCache test on all packages" print "(trying to install each and then mark it keep again):" # first, get all pkgs for pkg in cache.Packages: i += 1 x = pkg.Name # then get each version ver =depcache.GetCandidateVer(pkg) if ver != None: depcache.MarkInstall(pkg) if depcache.BrokenCount > 0: fixer = apt_pkg.GetPkgProblemResolver(depcache) fixer.Clear(pkg) fixer.Protect(pkg) # we first try to resolve the problem # with the package that should be installed # protected try: fixer.Resolve(True) except SystemError: # the pkg seems to be broken, the # returns a exception fixer.Clear(pkg) fixer.Resolve(True) if not depcache.MarkedInstall(pkg): print "broken in archive: %s " % pkg.Name fixer = None if depcache.InstCount == 0: if depcache.IsUpgradable(pkg): print "Error marking %s for install" % x for p in cache.Packages: if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p): depcache.MarkKeep(p) if depcache.InstCount != 0: print "Error undoing the selection for %s" % x print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)), print print "Trying Upgrade:" depcache.Upgrade() print "To install: %s " % depcache.InstCount print "To remove: %s " % depcache.DelCount print "Kept back: %s " % depcache.KeepCount print "Trying DistUpgrade:" depcache.Upgrade(True) print "To install: %s " % depcache.InstCount print "To remove: %s " % depcache.DelCount print "Kept back: %s " % depcache.KeepCount
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 get_updatesApt(self, input_data): import apt_pkg action = input_data['action'] upgrade_list = [] skipped_list = [] upgrade_count = 0 skipped_count = 0 apt_pkg.init() if os.path.exists("/etc/apt/apt.conf"): apt_pkg.read_config_file(apt_pkg.config, "/etc/apt/apt.conf") if os.path.isdir("/etc/apt/apt.conf.d"): apt_pkg.read_config_dir(apt_pkg.config, "/etc/apt/apt.conf.d") apt_pkg.init_system() cache = apt_pkg.GetCache(None) depcache = apt_pkg.GetDepCache(cache) depcache.ReadPinFile() depcache.Init(None) for i in cache.packages: if i.current_state is apt_pkg.CURSTATE_INSTALLED: if depcache.is_upgradable(i): if depcache.marked_keep(i): skipped_list.append(i.name) skipped_count += 1 else: upgrade_list.append(i.name) upgrade_count += 1 return(retval(0, "Package Update List", { "consequences": [ 'attrs.AvailablePackages := %s' % cache.PackageCount, 'attrs.UpgradablePackageCount := %s' % upgrade_count, 'attrs.SkippedPackageCount := %s' % skipped_count, 'attrs.UpgradablePackages := %s' % json.dumps(upgrade_list), 'attrs.SkippedPackageList := %s' % json.dumps(skipped_list)]}))
def main(): apt_pkg.init() cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) depcache.Init() i = 0 all = cache.PackageCount print "Running DepCache test on all packages" print "(trying to install each and then mark it keep again):" # first, get all pkgs for pkg in cache.Packages: i += 1 x = pkg.Name # then get each version ver = depcache.GetCandidateVer(pkg) if ver != None: depcache.MarkInstall(pkg) if depcache.InstCount == 0: if depcache.IsUpgradable(pkg): print "Error marking %s for install" % x for p in cache.Packages: if depcache.MarkedInstall(p): depcache.MarkKeep(p) if depcache.InstCount != 0: print "Error undoing the selection for %s (InstCount: %s)" % ( x, depcache.InstCount) print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)), print print "Trying Upgrade:" depcache.Upgrade() print "To install: %s " % depcache.InstCount print "To remove: %s " % depcache.DelCount print "Kept back: %s " % depcache.KeepCount print "Trying DistUpgrade:" depcache.Upgrade(True) print "To install: %s " % depcache.InstCount print "To remove: %s " % depcache.DelCount print "Kept back: %s " % depcache.KeepCount
def linux_ubuntu_check(package_name): import apt_pkg apt_pkg.init() cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) 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 if type(package_name) == str: return get_single_package(package_name).candidateVersion elif type(package_name) == list: return [ get_single_package(name).candidateVersion for name in package_name ]
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
cache = apt_pkg.GetCache(progress) print "Available packages: %s " % cache.PackageCount print "Fetching" progress = TextFetchProgress() cache.Update(progress) print "Exiting" sys.exit(0) iter = cache["base-config"] print "example package iter: %s" % iter # get depcache print "\n\n depcache" depcache = apt_pkg.GetDepCache(cache, progress) depcache.ReadPinFile() print "got a depcache: %s " % depcache print "Marked for install: %s " % depcache.InstCount print "\n\n Reinit" depcache.Init(progress) #sys.exit() # get a canidate version ver = depcache.GetCandidateVer(iter) print "Candidate version: %s " % ver print "\n\nQuerry interface" print "%s.IsUpgradable(): %s" % (iter.Name, depcache.IsUpgradable(iter))