def main(): apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.Init() i = 0 print "Running PkgRecords test on all packages:" for pkg in cache.Packages: i += 1 records = apt_pkg.PackageRecords(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.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() i = 0 print "Running PkgRecords test on all packages:" for pkg in cache.packages: i += 1 records = apt_pkg.PackageRecords(cache) if len(pkg.version_list) == 0: #print "no available version, cruft" continue version = depcache.get_candidate_ver(pkg) if not version: continue file, index = version.file_list.pop(0) if records.lookup((file, index)): #print records.filename x = records.filename y = records.long_desc pass print "\r%i/%i=%.3f%% " % (i, cache.package_count, (float(i) / float(cache.package_count) * 100)),
def updateCache(self): self.logger.verbose("Updating cache...") self.cache.update() self.logger.verbose("Opening cache...") self.cache.open(None) self.pkgCache = apt_pkg.Cache(progress=None) self.depCache = apt_pkg.DepCache(self.pkgCache)
class PkgManager(apt_pkg.PackageManager): parent = apt_pkg.PackageManager depcache = apt_pkg.DepCache(apt_pkg.Cache()) installionplan = [] def install(self, pkg, file): # print "Installing", pkg.get_fullname(True) self.installionplan.append((pkg, "Inst")) return True def configure(self, pkg): # print "Configuring", pkg.get_fullname(True) self.installionplan.append((pkg, "Conf")) return True def remove(self, pkg, purge): # print "Removing", pkg.get_fullname(True) self.installionplan.append((pkg, "Rem")) return True def go(self, fd): for (p, a) in self.installionplan: if a == "Inst" or a == "Conf": ver = self.depcache.get_candidate_ver(p) else: ver = p.current_ver print a, p.name, ver.ver_str, ver.arch return True
def main(): apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() i = 0 all = cache.package_count 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.get_candidate_ver(pkg) if ver is not None: depcache.mark_install(pkg) if depcache.broken_count > 0: fixer = apt_pkg.ProblemResolver(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.marked_install(pkg): print "broken in archive: %s " % pkg.name fixer = None if depcache.inst_count == 0: if depcache.is_upgradable(pkg): print "Error marking %s for install" % x for p in cache.packages: if depcache.marked_install(p) or depcache.marked_upgrade(p): depcache.mark_keep(p) if depcache.inst_count != 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.inst_count print "To remove: %s " % depcache.del_count print "Kept back: %s " % depcache.keep_count print "Trying DistUpgrade:" depcache.upgrade(True) print "To install: %s " % depcache.inst_count print "To remove: %s " % depcache.del_count print "Kept back: %s " % depcache.keep_count
def get_update_packages(): """ Return a list of dict about package updates """ pkgs = [] apt_pkg.init() # force apt to build its caches in memory for now to make sure # that there is no race when the pkgcache file gets re-generated apt_pkg.config.set("Dir::Cache::pkgcache", "") try: cache = apt_pkg.Cache(apt.progress.base.OpProgress()) except SystemError as e: sys.stderr.write("Error: Opening the cache (%s)" % e) sys.exit(-1) depcache = apt_pkg.DepCache(cache) # read the pin files depcache.read_pinfile() # read the synaptic pins too if os.path.exists(SYNAPTIC_PINFILE): depcache.read_pinfile(SYNAPTIC_PINFILE) # init the depcache depcache.init() try: saveDistUpgrade(cache, depcache) except SystemError as e: sys.stderr.write("Error: Marking the upgrade (%s)" % e) sys.exit(-1) for pkg in cache.packages: if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)): continue inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if cand_ver == inst_ver: # Package does not have available update continue if not inst_ver or not cand_ver: # Some packages are not installed(i.e. linux-headers-3.2.0-77) # skip these updates continue if pkg.name in BLACKLIST: # skip the package in blacklist continue record = { "name": pkg.name, "security": isSecurityUpgrade(cand_ver), "current_version": inst_ver.ver_str, "candidate_version": cand_ver.ver_str } pkgs.append(record) return pkgs
def restore_pkg_load_from_file(self, widget=None): # Load package list into treeview self.builder.get_object("button_forward").hide() self.builder.get_object("button_apply").show() self.builder.get_object("button_apply").set_sensitive(True) model = Gtk.ListStore(bool, str, bool, str) self.treeview_package_list.set_model(model) try: with open(self.package_source, "r") as f: source = f.readlines() apt_pkg.init() cache = apt_pkg.Cache() package_records = apt_pkg.PackageRecords(cache) depcache = apt_pkg.DepCache(cache) for line in source: try: if not line.strip() or line.startswith("#"): continue name = line.strip().replace(" install", "").replace("\tinstall", "") if not name: continue error = "%s\n<small>%s</small>" % ( name, _("Could not locate the package.")) if name in cache: pkg = cache[name] if not pkg.current_ver: candidate = depcache.get_candidate_ver(pkg) if candidate and candidate.downloadable: package_records.lookup( candidate.translated_description. file_list[0]) summary = package_records.short_desc status = "%s\n<small>%s</small>" % ( name, GLib.markup_escape_text(summary)) model.append([True, status, True, pkg.name]) else: model.append([False, error, False, pkg.name]) else: model.append([False, error, False, error]) except Exception as inner_detail: print("Error while reading '%s'." % line.strip()) print(inner_detail) except Exception as detail: self.show_message(_("An error occurred while reading the file.")) print(detail) if len(model) == 0: self.builder.get_object("button_forward").hide() self.builder.get_object("button_back").hide() self.builder.get_object("button_apply").hide() self.notebook.set_current_page(TAB_PKG_RESTORE_3) else: self.notebook.set_current_page(TAB_PKG_RESTORE_2) self.builder.get_object("button_forward").set_sensitive(True)
def test_apt_policy_lowlevel_files(self): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) policy = cache.policy dpolicy = depcache.policy self.assertNotEqual(policy, None) self.assertNotEqual(dpolicy, None) for f in cache.file_list: policy.get_priority(f) dpolicy.get_priority(f)
def get_update_packages(): """ Return a list of dict about package updates """ pkgs = [] apt_pkg.init() # force apt to build its caches in memory for now to make sure # that there is no race when the pkgcache file gets re-generated apt_pkg.config.set("Dir::Cache::pkgcache", "") try: cache = apt_pkg.Cache(apt.progress.base.OpProgress()) except SystemError as e: sys.stderr.write("Error: Opening the cache (%s)" % e) sys.exit(-1) depcache = apt_pkg.DepCache(cache) # read the pin files depcache.read_pinfile() # read the synaptic pins too if os.path.exists(SYNAPTIC_PINFILE): depcache.read_pinfile(SYNAPTIC_PINFILE) # init the depcache depcache.init() try: saveDistUpgrade(cache, depcache) except SystemError as e: sys.stderr.write("Error: Marking the upgrade (%s)" % e) sys.exit(-1) # use assignment here since apt.Cache() doesn't provide a __exit__ method # on Ubuntu 12.04 it looks like # aptcache = apt.Cache() for pkg in cache.packages: if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)): continue inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if cand_ver == inst_ver: continue record = { "name": pkg.name, "security": isSecurityUpgrade(pkg, depcache), "section": pkg.section, "current_version": inst_ver.ver_str if inst_ver else '-', "candidate_version": cand_ver.ver_str if cand_ver else '-', "priority": cand_ver.priority_str } pkgs.append(record) return pkgs
def test_apt_policy_lowlevel_versions(self): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) policy = cache.policy dpolicy = depcache.policy self.assertNotEqual(policy, None) self.assertNotEqual(dpolicy, None) for pkg in cache.packages: for ver in pkg.version_list: policy.get_priority(ver) dpolicy.get_priority(ver)
def apt_check(): apt_pkg.init() cache = apt_pkg.Cache(apt.progress.base.OpProgress()) depcache = apt_pkg.DepCache(cache) if depcache.broken_count > 0: raise SystemExit("Error: BrokenCount > 0") try: from UpdateManager.Core.UpdateList import UpdateList ul = UpdateList(None) except ImportError: ul = None # This mimics an upgrade but will never remove anything depcache.upgrade(True) if depcache.del_count > 0: # Unmark (clean) all changes from the given depcache depcache.init() depcache.upgrade() with apt.Cache() as aptcache: for pkg in cache.packages: if not depcache.marked_install(pkg) and \ not depcache.marked_upgrade(pkg): continue inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if cand_ver == inst_ver: continue security = False phased = False if isSecurityUpgrade(cand_ver): security = True elif inst_ver: # Check for security updates that are masked by a candidate # version from another repo (-proposed or -updates) for ver in pkg.version_list: if apt_pkg.version_compare(ver.ver_str, inst_ver.ver_str) \ > 0 and isSecurityUpgrade(ver): security = True break if ul is not None and \ ul._is_ignored_phased_update(aptcache[pkg.name]): phased = True yield Upgrade( package=pkg.name, installed=inst_ver.ver_str if inst_ver else None, candidate=cand_ver.ver_str, security=security, phased=phased, )
def get_update_packages(): pkgs = [] apt_pkg.init() # Força ´apt to build´ para os caches em memória apt_pkg.config.set("Dir::Cache::pkgcache", "") try: cache = apt_pkg.Cache(apt.progress.base.OpProgress()) except SystemError as e: sys.stderr.write("Error: Opening the cache (%s)" % e) sys.exit(-1) depcache = apt_pkg.DepCache(cache) # Lê os arquivos pin depcache.read_pinfile() # Lê os arquvios synaptic pin if os.path.exists(SYNAPTIC_PINFILE): depcache.read_pinfile(SYNAPTIC_PINFILE) depcache.init() try: saveDistUpgrade(cache, depcache) except SystemError as e: sys.stderr.write("Error: Marking the upgrade (%s)" % e) sys.exit(-1) # Usa os atributos devido o ´apt.Cache()´ não force o método __exit__ # no Ubuntu 12.04 aparece que aptcache = apt.Cache() for pkg in cache.packages: if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)): continue inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if cand_ver == inst_ver: continue record = { "name": pkg.name, "security": isSecurityUpgrade(pkg, depcache), ##"section": pkg.section, "current_version": inst_ver.ver_str if inst_ver else '-', "candidate_version": cand_ver.ver_str if cand_ver else '-', "priority": cand_ver.priority_str } pkgs.append(record) return pkgs
def fetchPackages(self, prefix, installedOnlyPrefix=None): apt_pkg.init_config() apt_pkg.init_system() cache = apt_pkg.Cache(progress=None) depcache = apt_pkg.DepCache(cache) rt = {} for pkg in cache.packages: if pkg.name.startswith(prefix): cand = depcache.get_candidate_ver(pkg) candVersion = None current = pkg.current_ver.ver_str if pkg.current_ver else '' if cand and cand.ver_str != current: candVersion = cand.ver_str nv = NV(name=pkg.name, state=self.state_str(pkg.current_state), version=current, candidate=candVersion) last = rt.get(pkg.name) if last is not None: if last.state != 'installed' and nv.state == 'installed': last.state = 'installed' if last.candidate is None and nv.candidate is not None: last.candidate = nv.candidate elif last.candidate is not None and nv.candidate is not None: if last.candidate != nv.candidate: logging.info( "found 2 candidate versions for %s: %s and %s", pkg.name, last.candidate, nv.candidate) try: if nv.candidate > last.candidate: last.candidate = nv.candidate except Exception as e: pass if last.version == last.candidate: last.candidate = None else: rt[pkg.name] = nv rtlist = [] for k, pkg in rt.items(): if installedOnlyPrefix is not None and k.startswith( installedOnlyPrefix): if pkg.version is None or pkg.version == '': continue rtlist.append(pkg.dict()) logging.debug("fetchPackageList: %s", str(rtlist)) return rtlist
def __init__(self, config_dir, state_dir): super().__init__(None) config = apt_pkg.config config["Dir::Etc"] = os.path.realpath(config_dir) config["Dir::State"] = os.path.join(os.path.realpath(state_dir), "state") config["Dir::Cache"] = os.path.join(os.path.realpath(state_dir), "cache") apt_pkg.init_config() apt_pkg.init_system() lists = apt_pkg.config.find_dir("Dir::State::Lists") os.makedirs(lists, exist_ok=True) os.makedirs(config["Dir::Cache"], exist_ok=True) self.cache = apt_pkg.Cache(None) self.depcache = apt_pkg.DepCache(self.cache) self.source_list = apt_pkg.SourceList() self.source_list.read_main_list()
def install(self, pkg_names): if self.opts.fix_broken: depcache = apt_pkg.DepCache(apt_pkg.Cache(apt.progress.text.OpProgress())) depcache.read_pinfile() try: depcache.fix_broken() except OSError as e: print("apt can't fix this broken installation.") exit(1) for pkg_name in pkg_names: if pkg_name in self.cache: pkg = self.cache[pkg_name] if not pkg.installed: pkg.mark_install() elif pkg.is_upgradable: pkg.mark_upgrade() else: raise Exception('{0} is not found'.format(pkg_name)) self._get_changes()
def get_upgradeable_esm_package_count(): import apt_pkg apt_pkg.init() cache = apt_pkg.Cache(None) dependencyCache = apt_pkg.DepCache(cache) upgrade_count = 0 for package in cache.packages: if not package.current_ver: continue upgrades = [v for v in package.version_list if v > package.current_ver] for upgrade in upgrades: for package_file, _idx in upgrade.file_list: if dependencyCache.policy.get_priority(package_file) == -32768: upgrade_count += 1 break return upgrade_count
def __init__(self, upgrades, security_upgrades, reboot_required, upg_path): QWidget.__init__(self) self.upgrades = upgrades self.security_upgrades = security_upgrades self.upg_path = upg_path self.reboot_required = reboot_required apt_pkg.init() try: self.cache = apt_pkg.Cache() except SystemError as e: sys.stderr.write(_("Error: Opening the cache (%s)") % e) sys.exit(-1) self.depcache = apt_pkg.DepCache(self.cache) self.records = apt_pkg.PackageRecords(self.cache) self.initUI() self.buttonBox.rejected.connect(self.call_reject) self.buttonBox.clicked.connect(self.call_upgrade)
def main(): apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() i = 0 all = cache.package_count 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.get_candidate_ver(pkg) if ver is not None: depcache.mark_install(pkg) if depcache.inst_count == 0: if depcache.is_upgradable(pkg): print "Error marking %s for install" % x for p in cache.packages: if depcache.marked_install(p): depcache.mark_keep(p) if depcache.inst_count != 0: print "Error undoing the selection for %s (inst_count: %s)" % ( x, depcache.inst_count) print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)), print print "Trying upgrade:" depcache.upgrade() print "To install: %s " % depcache.inst_count print "To remove: %s " % depcache.del_count print "Kept back: %s " % depcache.keep_count print "Trying DistUpgrade:" depcache.upgrade(True) print "To install: %s " % depcache.inst_count print "To remove: %s " % depcache.del_count print "Kept back: %s " % depcache.keep_count
def open(self, progress=None): """ Open the package cache, after that it can be used like a dictionary """ if progress is None: progress = apt.progress.base.OpProgress() # close old cache on (re)open self.close() self.op_progress = progress self._run_callbacks("cache_pre_open") self._cache = apt_pkg.Cache(progress) self._depcache = apt_pkg.DepCache(self._cache) self._records = apt_pkg.PackageRecords(self._cache) self._list = apt_pkg.SourceList() self._list.read_main_list() self._set.clear() self._fullnameset.clear() self._sorted_set = None self._weakref.clear() self._have_multi_arch = len(apt_pkg.get_architectures()) > 1 progress.op = _("Building data structures") i = last = 0 size = len(self._cache.packages) for pkg in self._cache.packages: if progress is not None and last + 100 < i: progress.update(i / float(size) * 100) last = i # drop stuff with no versions (cruft) if pkg.has_versions: self._set.add(pkg.get_fullname(pretty=True)) if self._have_multi_arch: self._fullnameset.add(pkg.get_fullname(pretty=False)) i += 1 progress.done() self._run_callbacks("cache_post_open")
def main(): apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(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 is not 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 refresh_system_call(self): '''Call the refresh of the app''' apt_pkg.init() self.cache = apt_pkg.Cache() if self.action_group is not None: self.action_group.release() self.depcache = apt_pkg.DepCache(self.cache) self.action_group = apt_pkg.ActionGroup(self.depcache) control.__init__() self.aid = control.controller.app_install_directory self.marked_as_install = [] self.theme = Gtk.IconTheme.get_default() self.theme.append_search_path("/usr/share/app-install/icons/") self.current_apps_model = self.ui.apps_all.model self.current_installed_model = self.ui.apps_installed.model self.refresh_app_basket() self.ui.apps_all.set_model(self.ui.apps_all.model) self.ui.apps_installed.set_model(self.ui.apps_installed.model) self.ui.apps_message.set_visible(False) self.ui.installed_message.set_visible(False) if self.ui.toolbar.__class__.__name__ == "Toolbar": self.ui.toolbar.set_style(3) self.packages = [] if (not self.startup) and (self.ui.pages.get_page() in [1, 2]): if self.ui.pages.get_page() == 1: self.get_func() if self.choosed_category == "fonts": showboth = True else: showboth = False self.append_packages_call(self.choosed_category, [], self.ui.apps_all.model, showboth) if self.ui.pages.get_page() == 2: self.installed_func() elif self.startup: self.back_home(None) if control.controller.check_internet: self.check_internet() self.startup = False
def open(self, progress=None): """ Open the package cache, after that it can be used like a dictionary """ if progress is None: progress = apt.progress.base.OpProgress() # close old cache on (re)open self.close() self.op_progress = progress self._run_callbacks("cache_pre_open") self._cache = apt_pkg.Cache(progress) self._depcache = apt_pkg.DepCache(self._cache) self._records = apt_pkg.PackageRecords(self._cache) self._list = apt_pkg.SourceList() self._list.read_main_list() self._sorted_set = None self.__remap() self._have_multi_arch = len(apt_pkg.get_architectures()) > 1 progress.done() self._run_callbacks("cache_post_open")
def main(): apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() i=0 all=cache.package_count print "Running Cache test on all packages:" # first, get all pkgs for pkg in cache.packages: i += 1 x = pkg.name # then get each version for ver in pkg.version_list: # get some version information a = ver.file_list b = ver.ver_str c = ver.arch d = ver.depends_listStr dl = ver.depends_list # get all dependencies (a dict of string->list, # e.g. "depends:" -> [ver1,ver2,..] for dep in dl.keys(): # get the list of each dependency object for depVerList in dl[dep]: for z in depVerList: # get all TargetVersions of # the dependency object for j in z.all_targets(): f = j.file_list g = ver.ver_str h = ver.arch k = ver.depends_listStr j = ver.depends_list pass print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)),
def get_uri(self, target_pkg, incl_deps=False): d = apt_pkg.DepCache(self.cache) if not incl_deps: return [lookup_uri(self, d, target_pkg)] deps = [lookup_uri(self, d, target_pkg)] togo = [target_pkg] while togo: pp = togo.pop() try: pkg = self.cache[pp] c = d.get_candidate_ver(pkg) except KeyError: pkg = None c = None if not c: # pylint: disable=E1133 for p in self.cache.packages: for x in p.provides_list: if pp == x[0]: pkg = self.cache[x[2].parent_pkg.name] c = d.get_candidate_ver(pkg) if not c: print("couldnt get candidate: %s" % pkg) else: for p in getdeps(c): if [y for y in deps if y[0] == p]: continue if p != target_pkg and p == pp: continue deps.append(lookup_uri(self, d, p)) togo.append(p) return list(set(deps))
def get_deb_versions_info(apt_pkg=None) -> Optional[DebVersionsInfo]: """Return versions information for Debian-based MAAS.""" if apt_pkg is None: import apt_pkg apt_pkg.init() try: cache = apt_pkg.Cache(None) except SystemError: maaslog.error( "Installed version could not be determined. Ensure " "/var/lib/dpkg/status is valid." ) return None depcache = apt_pkg.DepCache(cache) sources = apt_pkg.SourceList() sources.read_main_list() policy = apt_pkg.Policy(cache) policy.init_defaults() current, update, = ( None, None, ) for package in MAAS_PACKAGES: current, update = _get_deb_current_and_update( cache, depcache, sources, policy, package ) if current: break else: return None return DebVersionsInfo(current=current, update=update)
version = depcache.GetCandidateVer(pkg) if not version: return None file, index = version.FileList.pop(0) records.Lookup((file, index)) if records.SourcePkg != "": srcpkg = records.SourcePkg else: srcpkg = pkg.Name return srcpkg # main apt_pkg.init() cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.Init() records = apt_pkg.PackageRecords(cache) srcrecords = apt_pkg.SourceRecords() # base package that we use for build-depends calculation if len(sys.argv) < 2: print "need a package name as argument" sys.exit(1) try: pkg = base = cache[sys.argv[1]] except KeyError: print "No package %s found" % sys.argv[1] sys.exit(1) all_build_depends = set()
def __init__(self, xml): # pylint: disable=too-many-statements self.xml = xml arch = xml.text("project/buildimage/arch", key="arch") suite = xml.text("project/suite") self.basefs = TmpdirFilesystem() self.initialize_dirs() create_apt_prefs(self.xml, self.basefs) mirror = self.xml.create_apt_sources_list(build_sources=True, initvm=False) self.basefs.write_file("etc/apt/sources.list", 0o644, mirror) self.setup_gpg() self.import_keys() apt_pkg.config.set("APT::Architecture", arch) apt_pkg.config.set("APT::Architectures", arch) apt_pkg.config.set("Acquire::http::Proxy::127.0.0.1", "DIRECT") apt_pkg.config.set("APT::Install-Recommends", "0") apt_pkg.config.set("Dir::Etc", self.basefs.fname('/')) apt_pkg.config.set("Dir::Etc::Trusted", self.basefs.fname('/etc/apt/trusted.gpg')) apt_pkg.config.set("Dir::Etc::TrustedParts", self.basefs.fname('/etc/apt/trusted.gpg.d')) apt_pkg.config.set("APT::Cache-Limit", "0") apt_pkg.config.set("APT::Cache-Start", "32505856") apt_pkg.config.set("APT::Cache-Grow", "2097152") apt_pkg.config.set("Dir::State", self.basefs.fname("state")) apt_pkg.config.set("Dir::State::status", self.basefs.fname("state/status")) apt_pkg.config.set("Dir::Cache", self.basefs.fname("cache")) apt_pkg.config.set("Dir::Cache::archives", self.basefs.fname("cache/archives")) apt_pkg.config.set("Dir::Etc", self.basefs.fname("etc/apt")) apt_pkg.config.set("Dir::Log", self.basefs.fname("log")) if self.xml.has('project/noauth'): apt_pkg.config.set("APT::Get::AllowUnauthenticated", "1") apt_pkg.config.set("Acquire::AllowInsecureRepositories", "1") else: apt_pkg.config.set("APT::Get::AllowUnauthenticated", "0") apt_pkg.config.set("Acquire::AllowInsecureRepositories", "0") apt_pkg.init_system() self.source = apt_pkg.SourceList() self.source.read_main_list() self.cache = apt_pkg.Cache() try: self.cache.update(self, self.source) except BaseException as e: print(e) apt_pkg.config.set("APT::Default-Release", suite) self.cache = apt_pkg.Cache() try: self.cache.update(self, self.source) except BaseException as e: print(e) try: self.depcache = apt_pkg.DepCache(self.cache) prefs_name = self.basefs.fname("/etc/apt/preferences") self.depcache.read_pinfile(prefs_name) except BaseException as e: print(e) self.downloads = {} self.acquire = apt_pkg.Acquire(self)
def test_proper_invocation(self): """cache_invocation: Test correct invocation.""" apt_cache = apt_pkg.Cache(progress=None) apt_depcache = apt_pkg.DepCache(apt_cache) self.assertNotEqual(apt_depcache, None)
def fget(self): if self._depcache is None: self._depcache = apt_pkg.DepCache(self.cache) return self._depcache
def listUpdates(self): SYNAPTIC_PINFILE = "/var/lib/synaptic/preferences" DISTRO = 'bionic' def clean(cache, depcache): """ unmark (clean) all changes from the given depcache """ # mvo: looping is too inefficient with the new auto-mark code # for pkg in cache.Packages: # depcache.MarkKeep(pkg) depcache.init() def saveDistUpgrade(cache, depcache): """ this functions mimics a upgrade but will never remove anything """ depcache.upgrade(True) if depcache.del_count > 0: clean(cache, depcache) depcache.upgrade() def isSecurityUpgrade(pkg, depcache): def isSecurityUpgrade_helper(ver): """ check if the given version is a security update (or masks one) """ security_pockets = [("Ubuntu", "%s-security" % DISTRO), ("gNewSense", "%s-security" % DISTRO), ("Debian", "%s-updates" % DISTRO)] for (file, index) in ver.file_list: for origin, archive in security_pockets: if ( file.archive == archive and file.origin == origin): return True return False inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if isSecurityUpgrade_helper(cand_ver): return True # now check for security updates that are masked by a # canidate version from another repo (-proposed or -updates) for ver in pkg.version_list: if (inst_ver and apt_pkg.version_compare(ver.ver_str, inst_ver.ver_str) <= 0): # print "skipping '%s' " % ver.VerStr continue if isSecurityUpgrade_helper(ver): return True return False """ Return a list of dict about package updates """ appstream_cpts = [] app_updates = [] system_updates = [] security_updates = [] for i in self.pool.get_components(): appstream_cpts.append(self.appSummery(i.props.id)) apt_pkg.init() # force apt to build its caches in memory for now to make sure # that there is no race when the pkgcache file gets re-generated apt_pkg.config.set("Dir::Cache::pkgcache", "") try: cache = apt_pkg.Cache(apt.progress.base.OpProgress()) except SystemError as e: sys.stderr.write("Error: Opening the cache (%s)" % e) sys.exit(-1) depcache = apt_pkg.DepCache(cache) # read the pin files depcache.read_pinfile() # read the synaptic pins too if os.path.exists(SYNAPTIC_PINFILE): depcache.read_pinfile(SYNAPTIC_PINFILE) # init the depcache depcache.init() try: saveDistUpgrade(cache, depcache) except SystemError as e: sys.stderr.write("Error: Marking the upgrade (%s)" % e) sys.exit(-1) # use assignment here since apt.Cache() doesn't provide a __exit__ method # on Ubuntu 12.04 it looks like # aptcache = apt.Cache() for pkg in cache.packages: if not (depcache.marked_install( pkg) or depcache.marked_upgrade(pkg)): continue inst_ver = pkg.current_ver cand_ver = depcache.get_candidate_ver(pkg) if cand_ver == inst_ver: continue if isSecurityUpgrade(pkg, depcache): security_updates.append(pkg.name) else: system_updates.append(pkg.name) appstream_pkgs = [] for i in appstream_cpts: try: as_pkg = i['pkg'][0] except IndexError: pass for package in system_updates + security_updates: if package == as_pkg: app_updates.append(i) appstream_pkgs.append(as_pkg) for i in list(set(appstream_pkgs).intersection(system_updates)): system_updates.remove(i) for i in list(set(appstream_pkgs).intersection(security_updates)): security_updates.remove(i) app_updates = sorted(app_updates, key=itemgetter('name')) system_updates = sorted(system_updates) security_updates = sorted(security_updates) return app_updates, system_updates, security_updates