summaryrefslogtreecommitdiffstats
path: root/pym/portage/dbapi/dep_expand.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-02-25 20:42:04 +0000
committerZac Medico <zmedico@gentoo.org>2010-02-25 20:42:04 +0000
commit727abd89a87db835906fb53e0455feb75ae323d8 (patch)
tree248a3ad8ae7d0123c1e5a3d103e91faa9c70395b /pym/portage/dbapi/dep_expand.py
parent9eb73c4553cb066ed210ab0ffec53028e25b6b09 (diff)
downloadportage-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/dbapi/dep_expand.py')
-rw-r--r--pym/portage/dbapi/dep_expand.py48
1 files changed, 48 insertions, 0 deletions
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))