From 7afc6a4f99c14a4132f308504b6b4a2645b6f6c6 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 8 Dec 2006 08:08:58 +0000 Subject: [PATCH] Merged from trunkk 5205:5212 Share the same config instance between portagetree and portdbapi instances since clone isn't needed here. Also, trigger population of virtuals prior to cloning in emerge. This reduces the number of times the virtuals are populated from 3 to just 1. Enable FakeVartree to populate the virtuals so that the vdb doesn't have to be scanned separately. portage_versions lacks a header or copyright notice :x Catch an exception instead of using a redundant os.access call. A quick docstring for vercmp. s/zip/izip/ Thanks to Brian Harring for the suggestion. s/zip/izip/ some more svn path=/main/branches/prefix/; revision=5225 --- bin/emerge | 19 +++++++++++++------ pym/portage.py | 20 +++++++++----------- pym/portage_versions.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/bin/emerge b/bin/emerge index a01a21d8e..eb09736ee 100755 --- a/bin/emerge +++ b/bin/emerge @@ -48,6 +48,7 @@ from portage_data import secpass if not hasattr(__builtins__, "set"): from sets import Set as set +from itertools import izip class stdout_spinner(object): scroll_msgs = [ @@ -700,7 +701,7 @@ class DepPriority(object): return "medium" return "soft" -class FakeVartree(object): +class FakeVartree(portage.vartree): """This is implements an in-memory copy of a vartree instance that provides all the interfaces required for use by the depgraph. The vardb is locked during the constructor call just long enough to read a copy of the @@ -719,14 +720,19 @@ class FakeVartree(object): try: if os.access(vdb_path, os.W_OK): vdb_lock = portage_locks.lockdir(vdb_path) - mykeys = ["SLOT", "USE", "IUSE", "DEPEND", "RDEPEND", "PDEPEND"] + mykeys = ["SLOT", "PROVIDE", "USE", "IUSE", + "DEPEND", "RDEPEND", "PDEPEND"] real_dbapi = real_vartree.dbapi for cpv in real_dbapi.cpv_all(): - metadata = dict(zip(mykeys, real_dbapi.aux_get(cpv, mykeys))) + metadata = dict(izip(mykeys, real_dbapi.aux_get(cpv, mykeys))) self.dbapi.cpv_inject(cpv, metadata=metadata) finally: if vdb_lock: portage_locks.unlockdir(vdb_lock) + # Populate the old-style virtuals using the cached values. + if not self.settings.treeVirtuals: + self.settings.treeVirtuals = portage_util.map_dictlist_vals( + portage.getCPFromCPV, self.get_all_provides()) class depgraph: @@ -1357,7 +1363,7 @@ class depgraph: upd_commands = self.global_updates[myroot] aux_keys = ["DEPEND", "RDEPEND", "PDEPEND"] aux_vals = vardb.aux_get(myeb_inst, aux_keys) - aux_dict = dict(zip(aux_keys, aux_vals)) + aux_dict = dict(izip(aux_keys, aux_vals)) updates = update_dbentries(upd_commands, aux_dict) if updates: vardb.aux_update(myeb_inst, updates) @@ -3971,7 +3977,8 @@ def action_depclean(settings, trees, ldpath_mtimes, aux_vals = portdb.aux_get(cpv, fakedb_auxkeys) except KeyError: aux_vals = vardb.aux_get(cpv, fakedb_auxkeys) - fake_vardb.cpv_inject(cpv, metadata=dict(zip(fakedb_auxkeys, aux_vals))) + fake_vardb.cpv_inject( + cpv, metadata=dict(izip(fakedb_auxkeys, aux_vals))) # HACK: Ensure that installed packages are preferenced by dep_check(). trees[settings["ROOT"]]["porttree"].dbapi = fake_vardb @@ -3989,7 +3996,7 @@ def action_depclean(settings, trees, ldpath_mtimes, continue spinner.update() fakedb.cpv_inject(pkg) - myaux = dict(zip(aux_keys, fake_vardb.aux_get(pkg, aux_keys))) + myaux = dict(izip(aux_keys, fake_vardb.aux_get(pkg, aux_keys))) mydeps = [] if myopts.get("--with-bdeps", "y") == "y": mydeps.append((myaux["DEPEND"], soft)) diff --git a/pym/portage.py b/pym/portage.py index 7ab191ce5..00cde15ac 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -30,6 +30,7 @@ try: import UserDict if getattr(__builtins__, "set", None) is None: from sets import Set as set + from itertools import chain, izip except ImportError, e: sys.stderr.write("\n\n") sys.stderr.write("!!! Failed to complete python imports. These are internal modules for\n") @@ -1857,7 +1858,7 @@ class config: self.dirVirtuals[virt].reverse() # Repoman does not use user or tree virtuals. - if self.local_config: + if self.local_config and not self.treeVirtuals: temp_vartree = vartree(myroot, None, categories=self.categories, settings=self) # Reduce the provides into a list by CP. @@ -2674,7 +2675,6 @@ def spawnebuild(mydo,actionmap,mysettings,debug,alwaysdep=0,logfile=None): # automatically mapped to PORTAGE_INST_UID and PORTAGE_INST_GID if # necessary. The chown system call may clear S_ISUID and S_ISGID # bits, so those bits are restored if necessary. - from itertools import chain inst_uid = int(mysettings["PORTAGE_INST_UID"]) inst_gid = int(mysettings["PORTAGE_INST_GID"]) for parent, dirs, files in os.walk(mysettings["D"]): @@ -3743,7 +3743,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): if unreduced[0] != "||": unresolved = [] - for (dep, satisfied) in zip(unreduced, reduced): + for dep, satisfied in izip(unreduced, reduced): if isinstance(dep, list): unresolved += dep_zapdeps(dep, satisfied, myroot, use_binaries=use_binaries, trees=trees) @@ -3773,7 +3773,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): # Sort the deps into preferred (installed) and other # with values of [[required_atom], availablility] - for (dep, satisfied) in zip(deps, satisfieds): + for dep, satisfied in izip(deps, satisfieds): if isinstance(dep, list): atoms = dep_zapdeps(dep, satisfied, myroot, use_binaries=use_binaries, trees=trees) @@ -4271,7 +4271,7 @@ class portagetree: self.portroot=settings["PORTDIR"] self.virtual=virtual self.dbapi = portdbapi( - settings["PORTDIR"], mysettings=config(clone=settings)) + settings["PORTDIR"], mysettings=settings) def dep_bestmatch(self,mydep): "compatibility method" @@ -4802,14 +4802,14 @@ class vardbapi(dbapi): results = [] for x in wants: myfn = self.root+VDB_PATH+"/"+str(mycpv)+"/"+str(x) - if os.access(myfn,os.R_OK): + try: myf = open(myfn, "r") myd = myf.read() myf.close() myd = re.sub("[\n\r\t]+"," ",myd) myd = re.sub(" +"," ",myd) myd = string.strip(myd) - else: + except (IOError, OSError): myd = "" results.append(myd) if "EAPI" in wants: @@ -4937,11 +4937,9 @@ class vartree(packagetree): def get_provide(self,mycpv): myprovides=[] try: - mylines = grabfile(self.root+VDB_PATH+"/"+mycpv+"/PROVIDE") + mylines, myuse = self.dbapi.aux_get(mycpv, ["PROVIDE","USE"]) if mylines: - myuse = grabfile(self.root+VDB_PATH+"/"+mycpv+"/USE") - myuse = string.split(string.join(myuse)) - mylines = string.join(mylines) + myuse = myuse.split() mylines = flatten(portage_dep.use_reduce(portage_dep.paren_reduce(mylines), uselist=myuse)) for myprovide in mylines: mys = catpkgsplit(myprovide) diff --git a/pym/portage_versions.py b/pym/portage_versions.py index 1d9a1972c..8e58c2f47 100644 --- a/pym/portage_versions.py +++ b/pym/portage_versions.py @@ -1,3 +1,8 @@ +# portage_versions.py -- core Portage functionality +# Copyright 1998-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + import re,string ver_regexp = re.compile("^(cvs\\.)?(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$") @@ -16,6 +21,29 @@ def ververify(myver, silent=1): vercmp_cache = {} def vercmp(ver1, ver2, silent=1): + """ + Compare two versions + Example usage: + >>> from portage_versions import vercmp + >>> vercmp('1.0-r1','1.2-r3') + negative number + >>> vercmp('1.3','1.2-r3') + positive number + >>> vercmp('1.0_p3','1.0_p3') + 0 + + @param pkg1: version to compare with (see ver_regexp in portage_versions.py) + @type pkg1: string (example: "2.1.2-r3") + @param pkg2: version to compare againts (see ver_regexp in portage_versions.py) + @type pkg2: string (example: "2.1.2_rc5") + @rtype: None or float + @return: + 1. positive if ver1 is greater than ver2 + 2. negative if ver1 is less than ver2 + 3. 0 if ver1 equals ver2 + 4. None if ver1 or ver2 are invalid (see ver_regexp in portage_versions.py) + """ + if ver1 == ver2: return 0 mykey=ver1+":"+ver2 -- 2.26.2