* Add support in dep_getusedeps() and isvalidatom() for comma separated USE
authorZac Medico <zmedico@gentoo.org>
Mon, 28 Jul 2008 01:42:06 +0000 (01:42 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 28 Jul 2008 01:42:06 +0000 (01:42 -0000)
  deps that only have one set of square brackets.
* Add test cases for the new comma separated USE deps syntax.

svn path=/main/trunk/; revision=11229

pym/portage/dep.py
pym/portage/tests/dep/test_isvalidatom.py

index 737c009a94802aaf194d7b07c19710fd6b6bb2ef..15000dd841b883b3e6836ed367828e6805294bac 100644 (file)
@@ -588,16 +588,35 @@ def dep_getusedeps( depend ):
        use_list = []
        open_bracket = depend.find('[')
        # -1 = failure (think c++ string::npos)
+       comma_separated = False
+       bracket_count = 0
        while( open_bracket != -1 ):
+               bracket_count += 1
                close_bracket = depend.find(']', open_bracket )
                if close_bracket == -1:
                        raise InvalidAtom("USE Dependency with no closing bracket: %s" % depend )
                use = depend[open_bracket + 1: close_bracket]
                # foo[1:1] may return '' instead of None, we don't want '' in the result
-               if len(use):
-                       use_list.append(use)
+               if not use:
+                       raise InvalidAtom("USE Dependency with " + \
+                               "no use flag ([]): %s" % depend )
+               if not comma_separated:
+                       comma_separated = "," in use
+
+               if comma_separated and bracket_count > 1:
+                       raise InvalidAtom("USE Dependency contains a mixture of " + \
+                               "comma and bracket separators: %s" % depend )
+
+               if comma_separated:
+                       for x in use.split(","):
+                               if x:
+                                       use_list.append(x)
+                               else:
+                                       raise InvalidAtom("USE Dependency with no use " + \
+                                               "flag next to comma: %s" % depend )
                else:
-                       raise InvalidAtom("USE Dependency with no use flag ([]): %s" % depend )
+                       use_list.append(use)
+
                # Find next use flag
                open_bracket = depend.find( '[', open_bracket+1 )
        return tuple(use_list)
@@ -634,6 +653,12 @@ def isvalidatom(atom, allow_blockers=False):
                return 0
        if allow_blockers and atom.startswith("!"):
                atom = atom[1:]
+
+       try:
+               dep_getusedeps(atom)
+       except InvalidAtom:
+               return 0
+
        cpv = dep_getcpv(atom)
        cpv_catsplit = catsplit(cpv)
        mycpv_cps = None
index dfcf178988517d9e9afa5872938f94a273ad503f..d2210b8e93151cb06fd9e2c0491d202768e27c07 100644 (file)
@@ -26,6 +26,11 @@ class IsValidAtom(TestCase):
                          ( "sys-apps/portage-2.1:foo", False ),
                          ( "sys-apps/portage-2.1:", False ),
                          ( "=sys-apps/portage-2.2*:foo[bar][-baz][doc?][-build?]", True ),
+                         ( "=sys-apps/portage-2.2*:foo[bar,-baz,doc?,-build?]", True ),
+                         ( "=sys-apps/portage-2.2*:foo[bar,-baz,doc?,-build?,]", False ),
+                         ( "=sys-apps/portage-2.2*:foo[,bar,-baz,doc?,-build?]", False ),
+                         ( "=sys-apps/portage-2.2*:foo[bar,-baz][doc?,-build?]", False ),
+                         ( "=sys-apps/portage-2.2*:foo[bar][doc,build]", False ),
                          ( ">~cate-gory/foo-1.0", False ),
                          ( ">~category/foo-1.0", False ),
                          ( "<~category/foo-1.0", False ),