Move dep_expand and cpv_expand into portage.dbapi submodules.
authorZac Medico <zmedico@gentoo.org>
Thu, 25 Feb 2010 20:42:04 +0000 (20:42 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 25 Feb 2010 20:42:04 +0000 (20:42 -0000)
svn path=/main/trunk/; revision=15460

bin/quickpkg
pym/_emerge/actions.py
pym/_emerge/depgraph.py
pym/_emerge/main.py
pym/portage/__init__.py
pym/portage/dbapi/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/dbapi/cpv_expand.py [new file with mode: 0644]
pym/portage/dbapi/dep_expand.py [new file with mode: 0644]
pym/portage/dbapi/porttree.py
pym/portage/dbapi/vartree.py

index 383fe20fb8cacbb863a02ccc649c827971a1d56c..5d75956cb65cab1f55432986b76c635ca7a1103c 100755 (executable)
@@ -19,7 +19,8 @@ except ImportError:
 from portage import os
 
 def quickpkg_main(options, args, eout):
-       from portage import catsplit, dep_expand, flatten, isvalidatom, xpak
+       from portage import catsplit, flatten, isvalidatom, xpak
+       from portage.dbapi.dep_expand import dep_expand
        from portage.dep import use_reduce, paren_reduce
        from portage.util import ConfigProtect, ensure_dirs
        from portage.exception import InvalidAtom, InvalidData, InvalidDependString
index 702ccff983f80ef530e35feec45a269ac1efc938..b45c95c159ab07ccdb24dd4e193108a46ab862a4 100644 (file)
@@ -27,6 +27,7 @@ from portage import digraph
 from portage import _unicode_decode
 from portage.cache.cache_errors import CacheError
 from portage.const import NEWS_LIB_PATH
+from portage.dbapi.dep_expand import dep_expand
 from portage.output import blue, bold, colorize, create_color_func, darkgreen, \
        red, yellow
 good = create_color_func("GOOD")
@@ -2212,7 +2213,7 @@ def action_uninstall(settings, trees, ldpath_mtimes,
 
                        try:
                                valid_atoms.append(
-                                       portage.dep_expand(x, mydb=vardb, settings=settings))
+                                       dep_expand(x, mydb=vardb, settings=settings))
                        except portage.exception.AmbiguousPackageName as e:
                                msg = "The short ebuild name \"" + x + \
                                        "\" is ambiguous.  Please specify " + \
index 86b4cfccfaf108ab989d701df0424f2b627cf1c3..2ad67713bf17a1e8eb3c13ceffb4a70715c7accf 100644 (file)
@@ -15,6 +15,7 @@ import portage
 from portage import os
 from portage import digraph
 from portage.dbapi import dbapi
+from portage.dbapi.dep_expand import dep_expand
 from portage.dep import Atom
 from portage.output import bold, blue, colorize, create_color_func, darkblue, \
        darkgreen, green, nc_len, red, teal, turquoise, yellow
@@ -4160,7 +4161,7 @@ class depgraph(object):
                                else:
                                        blocker_style = "PKG_BLOCKER"
                                        addl = "%s  %s  " % (colorize(blocker_style, "B"), fetch)
-                               resolved = portage.dep_expand(
+                               resolved = dep_expand(
                                        str(x.atom).lstrip("!"), mydb=vardb, settings=pkgsettings)
                                if "--columns" in self._frozen_config.myopts and "--quiet" in self._frozen_config.myopts:
                                        addl += " " + colorize(blocker_style, str(resolved))
index 3a9990188b44f0a530de9197ca3d91b99f36626a..43655c5b369eaa4c15e07781da6db61949ee7c68 100644 (file)
@@ -32,6 +32,7 @@ import portage.util
 import portage.locks
 import portage.exception
 from portage.data import secpass
+from portage.dbapi.dep_expand import dep_expand
 from portage.util import normalize_path as normpath
 from portage.util import writemsg, writemsg_level, writemsg_stdout
 from portage.sets import SETPREFIX
@@ -1500,7 +1501,7 @@ def emerge_main():
                        if is_valid_package_atom(x):
                                try:
                                        valid_atoms.append(
-                                               portage.dep_expand(x, mydb=vardb, settings=settings))
+                                               dep_expand(x, mydb=vardb, settings=settings))
                                except portage.exception.AmbiguousPackageName as e:
                                        msg = "The short ebuild name \"" + x + \
                                                "\" is ambiguous.  Please specify " + \
index 6f20bb195907ea2d7f0bd6f1e59ff2aa7e0e6304..dbce97bb3feee8170ec218202f7b595de9f69197 100644 (file)
@@ -82,6 +82,8 @@ try:
                        'uid,userland,userpriv_groups,wheelgid',
                'portage.dbapi',
                'portage.dbapi.bintree:bindbapi,binarytree',
+               'portage.dbapi.cpv_expand:cpv_expand',
+               'portage.dbapi.dep_expand:dep_expand',
                'portage.dbapi.porttree:close_portdbapi_caches,FetchlistDict,' + \
                        'portagetree,portdbapi',
                'portage.dbapi.vartree:vardbapi,vartree,dblink',
@@ -1395,42 +1397,6 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None):
 
        assert(False) # This point should not be reachable
 
-def dep_expand(mydep, mydb=None, use_cache=1, settings=None):
-       '''
-       @rtype: Atom
-       '''
-       if not len(mydep):
-               return mydep
-       if mydep[0]=="*":
-               mydep=mydep[1:]
-       orig_dep = mydep
-       if isinstance(orig_dep, dep.Atom):
-               mydep = orig_dep.cp
-       else:
-               mydep = orig_dep
-               has_cat = '/' in orig_dep
-               if not has_cat:
-                       alphanum = re.search(r'\w', orig_dep)
-                       if alphanum:
-                               mydep = orig_dep[:alphanum.start()] + "null/" + \
-                                       orig_dep[alphanum.start():]
-               try:
-                       mydep = dep.Atom(mydep)
-               except exception.InvalidAtom:
-                       # Missing '=' prefix is allowed for backward compatibility.
-                       if not dep.isvalidatom("=" + mydep):
-                               raise
-                       mydep = dep.Atom('=' + mydep)
-                       orig_dep = '=' + orig_dep
-               if not has_cat:
-                       null_cat, pn = catsplit(mydep.cp)
-                       mydep = pn
-               else:
-                       mydep = mydep.cp
-       expanded = cpv_expand(mydep, mydb=mydb,
-               use_cache=use_cache, settings=settings)
-       return portage.dep.Atom(orig_dep.replace(mydep, expanded, 1))
-
 def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
        use_cache=1, use_binaries=0, myroot="/", trees=None):
        """Takes a depend string and parses the condition."""
@@ -1564,92 +1530,6 @@ def dep_wordreduce(mydeplist,mysettings,mydbapi,mode,use_cache=1):
                                        return None
        return deplist
 
-def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None):
-       """Given a string (packagename or virtual) expand it into a valid
-       cat/package string. Virtuals use the mydb to determine which provided
-       virtual is a valid choice and defaults to the first element when there
-       are no installed/available candidates."""
-       myslash=mycpv.split("/")
-       mysplit = versions._pkgsplit(myslash[-1])
-       if settings is None:
-               settings = globals()["settings"]
-       virts = settings.getvirtuals()
-       virts_p = settings.get_virts_p()
-       if len(myslash)>2:
-               # this is illegal case.
-               mysplit=[]
-               mykey=mycpv
-       elif len(myslash)==2:
-               if mysplit:
-                       mykey=myslash[0]+"/"+mysplit[0]
-               else:
-                       mykey=mycpv
-               if mydb and virts and mykey in virts:
-                       writemsg("mydb.__class__: %s\n" % (mydb.__class__), 1)
-                       if hasattr(mydb, "cp_list"):
-                               if not mydb.cp_list(mykey, use_cache=use_cache):
-                                       writemsg("virts[%s]: %s\n" % (str(mykey),virts[mykey]), 1)
-                                       mykey_orig = mykey[:]
-                                       for vkey in virts[mykey]:
-                                               # The virtuals file can contain a versioned atom, so
-                                               # it may be necessary to remove the operator and
-                                               # version from the atom before it is passed into
-                                               # dbapi.cp_list().
-                                               if mydb.cp_list(vkey.cp):
-                                                       mykey = str(vkey)
-                                                       writemsg(_("virts chosen: %s\n") % (mykey), 1)
-                                                       break
-                                       if mykey == mykey_orig:
-                                               mykey = str(virts[mykey][0])
-                                               writemsg(_("virts defaulted: %s\n") % (mykey), 1)
-                       #we only perform virtual expansion if we are passed a dbapi
-       else:
-               #specific cpv, no category, ie. "foo-1.0"
-               if mysplit:
-                       myp=mysplit[0]
-               else:
-                       # "foo" ?
-                       myp=mycpv
-               mykey=None
-               matches=[]
-               if mydb and hasattr(mydb, "categories"):
-                       for x in mydb.categories:
-                               if mydb.cp_list(x+"/"+myp,use_cache=use_cache):
-                                       matches.append(x+"/"+myp)
-               if len(matches) > 1:
-                       virtual_name_collision = False
-                       if len(matches) == 2:
-                               for x in matches:
-                                       if not x.startswith("virtual/"):
-                                               # Assume that the non-virtual is desired.  This helps
-                                               # avoid the ValueError for invalid deps that come from
-                                               # installed packages (during reverse blocker detection,
-                                               # for example).
-                                               mykey = x
-                                       else:
-                                               virtual_name_collision = True
-                       if not virtual_name_collision:
-                               # AmbiguousPackageName inherits from ValueError,
-                               # for backward compatibility with calling code
-                               # that already handles ValueError.
-                               raise portage.exception.AmbiguousPackageName(matches)
-               elif matches:
-                       mykey=matches[0]
-
-               if not mykey and not isinstance(mydb, list):
-                       if myp in virts_p:
-                               mykey=virts_p[myp][0]
-                       #again, we only perform virtual expansion if we have a dbapi (not a list)
-               if not mykey:
-                       mykey="null/"+myp
-       if mysplit:
-               if mysplit[2]=="r0":
-                       return mykey+"-"+mysplit[1]
-               else:
-                       return mykey+"-"+mysplit[1]+"-"+mysplit[2]
-       else:
-               return mykey
-
 def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False):
        from portage.util import grablines
        if settings is None:
index c758491f1e3e18fb89f9184f36b881bfe6405bd4..dcd933f623b78ce2054a691c18eda6961e0ff676 100644 (file)
@@ -8,6 +8,7 @@ import re
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.dbapi.dep_expand:dep_expand',
        'portage.dep:match_from_list',
        'portage.locks:unlockfile',
        'portage.output:colorize',
@@ -16,7 +17,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
 )
 
 from portage import os
-from portage import auxdbkeys, dep_expand
+from portage import auxdbkeys
 from portage.localization import _
 
 class dbapi(object):
index b5e371b59a5d24c546c66d116b54c4d712452ead..fa68ba7d7b17a592d7a779163a640dcdc9165aef 100644 (file)
@@ -8,6 +8,7 @@ __all__ = ["bindbapi", "binarytree"]
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.dbapi.dep_expand:dep_expand',
        'portage.dep:dep_getkey,isjustname,match_from_list',
        'portage.output:EOutput,colorize',
        'portage.package.ebuild.doebuild:_vdb_use_conditional_atoms',
@@ -23,7 +24,7 @@ from portage.exception import InvalidPackageName, \
        PermissionDenied, PortageException
 from portage.localization import _
 
-from portage import dep_expand, _movefile
+from portage import _movefile
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode
diff --git a/pym/portage/dbapi/cpv_expand.py b/pym/portage/dbapi/cpv_expand.py
new file mode 100644 (file)
index 0000000..587f237
--- /dev/null
@@ -0,0 +1,96 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ["cpv_expand"]
+
+from portage.exception import AmbiguousPackageName
+from portage.localization import _
+from portage.util import writemsg
+from portage.versions import _pkgsplit
+
+def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None):
+       """Given a string (packagename or virtual) expand it into a valid
+       cat/package string. Virtuals use the mydb to determine which provided
+       virtual is a valid choice and defaults to the first element when there
+       are no installed/available candidates."""
+       myslash=mycpv.split("/")
+       mysplit = _pkgsplit(myslash[-1])
+       if settings is None:
+               settings = globals()["settings"]
+       virts = settings.getvirtuals()
+       virts_p = settings.get_virts_p()
+       if len(myslash)>2:
+               # this is illegal case.
+               mysplit=[]
+               mykey=mycpv
+       elif len(myslash)==2:
+               if mysplit:
+                       mykey=myslash[0]+"/"+mysplit[0]
+               else:
+                       mykey=mycpv
+               if mydb and virts and mykey in virts:
+                       writemsg("mydb.__class__: %s\n" % (mydb.__class__), 1)
+                       if hasattr(mydb, "cp_list"):
+                               if not mydb.cp_list(mykey, use_cache=use_cache):
+                                       writemsg("virts[%s]: %s\n" % (str(mykey),virts[mykey]), 1)
+                                       mykey_orig = mykey[:]
+                                       for vkey in virts[mykey]:
+                                               # The virtuals file can contain a versioned atom, so
+                                               # it may be necessary to remove the operator and
+                                               # version from the atom before it is passed into
+                                               # dbapi.cp_list().
+                                               if mydb.cp_list(vkey.cp):
+                                                       mykey = str(vkey)
+                                                       writemsg(_("virts chosen: %s\n") % (mykey), 1)
+                                                       break
+                                       if mykey == mykey_orig:
+                                               mykey = str(virts[mykey][0])
+                                               writemsg(_("virts defaulted: %s\n") % (mykey), 1)
+                       #we only perform virtual expansion if we are passed a dbapi
+       else:
+               #specific cpv, no category, ie. "foo-1.0"
+               if mysplit:
+                       myp=mysplit[0]
+               else:
+                       # "foo" ?
+                       myp=mycpv
+               mykey=None
+               matches=[]
+               if mydb and hasattr(mydb, "categories"):
+                       for x in mydb.categories:
+                               if mydb.cp_list(x+"/"+myp,use_cache=use_cache):
+                                       matches.append(x+"/"+myp)
+               if len(matches) > 1:
+                       virtual_name_collision = False
+                       if len(matches) == 2:
+                               for x in matches:
+                                       if not x.startswith("virtual/"):
+                                               # Assume that the non-virtual is desired.  This helps
+                                               # avoid the ValueError for invalid deps that come from
+                                               # installed packages (during reverse blocker detection,
+                                               # for example).
+                                               mykey = x
+                                       else:
+                                               virtual_name_collision = True
+                       if not virtual_name_collision:
+                               # AmbiguousPackageName inherits from ValueError,
+                               # for backward compatibility with calling code
+                               # that already handles ValueError.
+                               raise AmbiguousPackageName(matches)
+               elif matches:
+                       mykey=matches[0]
+
+               if not mykey and not isinstance(mydb, list):
+                       if myp in virts_p:
+                               mykey=virts_p[myp][0]
+                       #again, we only perform virtual expansion if we have a dbapi (not a list)
+               if not mykey:
+                       mykey="null/"+myp
+       if mysplit:
+               if mysplit[2]=="r0":
+                       return mykey+"-"+mysplit[1]
+               else:
+                       return mykey+"-"+mysplit[1]+"-"+mysplit[2]
+       else:
+               return mykey
diff --git a/pym/portage/dbapi/dep_expand.py b/pym/portage/dbapi/dep_expand.py
new file mode 100644 (file)
index 0000000..53a666e
--- /dev/null
@@ -0,0 +1,48 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ["dep_expand"]
+
+import re
+
+from portage.dbapi.cpv_expand import cpv_expand
+from portage.dep import Atom, isvalidatom
+from portage.exception import InvalidAtom
+from portage.versions import catsplit
+
+def dep_expand(mydep, mydb=None, use_cache=1, settings=None):
+       '''
+       @rtype: Atom
+       '''
+       if not len(mydep):
+               return mydep
+       if mydep[0]=="*":
+               mydep=mydep[1:]
+       orig_dep = mydep
+       if isinstance(orig_dep, Atom):
+               mydep = orig_dep.cp
+       else:
+               mydep = orig_dep
+               has_cat = '/' in orig_dep
+               if not has_cat:
+                       alphanum = re.search(r'\w', orig_dep)
+                       if alphanum:
+                               mydep = orig_dep[:alphanum.start()] + "null/" + \
+                                       orig_dep[alphanum.start():]
+               try:
+                       mydep = Atom(mydep)
+               except InvalidAtom:
+                       # Missing '=' prefix is allowed for backward compatibility.
+                       if not isvalidatom("=" + mydep):
+                               raise
+                       mydep = Atom('=' + mydep)
+                       orig_dep = '=' + orig_dep
+               if not has_cat:
+                       null_cat, pn = catsplit(mydep.cp)
+                       mydep = pn
+               else:
+                       mydep = mydep.cp
+       expanded = cpv_expand(mydep, mydb=mydb,
+               use_cache=use_cache, settings=settings)
+       return Atom(orig_dep.replace(mydep, expanded, 1))
index 7dd81f7b5f62fb184a4c8a5adb63b2a24f42723c..39dd6eb8ced0d2f4e26bf757f1bb52a4a9e3269a 100644 (file)
@@ -11,6 +11,7 @@ __all__ = [
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.checksum',
+       'portage.dbapi.dep_expand:dep_expand',
        'portage.dep:dep_getkey,flatten,match_from_list,paren_reduce,use_reduce',
        'portage.env.loaders:KeyValuePairFileLoader',
        'portage.package.ebuild.doebuild:doebuild',
@@ -30,7 +31,7 @@ from portage.localization import _
 from portage.manifest import Manifest
 
 from portage import eclass_cache, auxdbkeys, \
-       dep_expand, eapi_is_supported, dep_check, \
+       eapi_is_supported, dep_check, \
        _eapi_is_deprecated
 from portage import os
 from portage import _encodings
index 80ae5bebe2f89f0fd27ec94dbe3bb1a761815097..7eb3a702453326511dfec28e8424997b2def0d4e 100644 (file)
@@ -11,6 +11,7 @@ __all__ = ["PreservedLibsRegistry", "LinkageMap",
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.checksum:_perform_md5_merge@perform_md5',
+       'portage.dbapi.dep_expand:dep_expand',
        'portage.dep:dep_getkey,isjustname,flatten,match_from_list,' + \
                'use_reduce,paren_reduce,_slot_re',
        'portage.elog:elog_process',
@@ -39,8 +40,7 @@ from portage.exception import CommandNotFound, \
        FileNotFound, PermissionDenied, UnsupportedAPIException
 from portage.localization import _
 
-from portage import dep_expand, \
-       abssymlink, movefile, _movefile, bsd_chflags
+from portage import abssymlink, movefile, _movefile, bsd_chflags
 
 # This is a special version of the os module, wrapped for unicode support.
 from portage import os