From 727abd89a87db835906fb53e0455feb75ae323d8 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 25 Feb 2010 20:42:04 +0000 Subject: Move dep_expand and cpv_expand into portage.dbapi submodules. svn path=/main/trunk/; revision=15460 --- bin/quickpkg | 3 +- pym/_emerge/actions.py | 3 +- pym/_emerge/depgraph.py | 3 +- pym/_emerge/main.py | 3 +- pym/portage/__init__.py | 124 +--------------------------------------- pym/portage/dbapi/__init__.py | 3 +- pym/portage/dbapi/bintree.py | 3 +- pym/portage/dbapi/cpv_expand.py | 96 +++++++++++++++++++++++++++++++ pym/portage/dbapi/dep_expand.py | 48 ++++++++++++++++ pym/portage/dbapi/porttree.py | 3 +- pym/portage/dbapi/vartree.py | 4 +- 11 files changed, 162 insertions(+), 131 deletions(-) create mode 100644 pym/portage/dbapi/cpv_expand.py create mode 100644 pym/portage/dbapi/dep_expand.py diff --git a/bin/quickpkg b/bin/quickpkg index 383fe20fb..5d75956cb 100755 --- a/bin/quickpkg +++ b/bin/quickpkg @@ -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 diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 702ccff98..b45c95c15 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -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 " + \ diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 86b4cfccf..2ad67713b 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -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)) diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index 3a9990188..43655c5b3 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -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 " + \ diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 6f20bb195..dbce97bb3 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -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: diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index c758491f1..dcd933f62 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -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): diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index b5e371b59..fa68ba7d7 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -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 index 000000000..587f2372c --- /dev/null +++ b/pym/portage/dbapi/cpv_expand.py @@ -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 index 000000000..53a666ee0 --- /dev/null +++ b/pym/portage/dbapi/dep_expand.py @@ -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)) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 7dd81f7b5..39dd6eb8c 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -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 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 80ae5bebe..7eb3a7024 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -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 -- cgit v1.2.3-1-g7c22