diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-02-25 20:42:04 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-02-25 20:42:04 +0000 |
commit | 727abd89a87db835906fb53e0455feb75ae323d8 (patch) | |
tree | 248a3ad8ae7d0123c1e5a3d103e91faa9c70395b /pym/portage/__init__.py | |
parent | Fix typo in import. (diff) | |
download | portage-727abd89a87db835906fb53e0455feb75ae323d8.tar.gz portage-727abd89a87db835906fb53e0455feb75ae323d8.tar.bz2 portage-727abd89a87db835906fb53e0455feb75ae323d8.zip |
Move dep_expand and cpv_expand into portage.dbapi submodules.
svn path=/main/trunk/; revision=15460
Diffstat (limited to 'pym/portage/__init__.py')
-rw-r--r-- | pym/portage/__init__.py | 124 |
1 files changed, 2 insertions, 122 deletions
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: |