portage.dep.use_reduce: Add is_src_uri and allow_src_uri_file_renames
authorSebastian Luther <SebastianLuther@gmx.de>
Tue, 10 Aug 2010 19:50:35 +0000 (21:50 +0200)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Aug 2010 05:28:57 +0000 (22:28 -0700)
All checks done by portage.dbapi.porttree._src_uri_validate are now done by use_reduce.

pym/portage/dep/__init__.py
pym/portage/tests/dep/test_use_reduce.py

index 32d3155ab147cdc69496c2f1a2db547292511e1d..8d9d185ad54309757ec2b62cc04b81e5c4b31384 100644 (file)
@@ -214,7 +214,8 @@ def paren_enclose(mylist):
                        mystrparts.append(x)
        return " ".join(mystrparts)
 
-def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
+def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], is_src_uri=False, \
+       allow_src_uri_file_renames=False):
        """
        Takes a dep string and reduces the use? conditionals out, leaving an array
        with subarrays. All redundant brackets are removed.
@@ -261,14 +262,18 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
        level = 0
        stack = [[]]
        need_bracket = False
+       need_simple_token = False
 
        for token in mysplit:
                if token == "(":
+                       if need_simple_token:
+                               raise portage.exception.InvalidDependString(
+                                       _("malformed syntax: '%s'") % depstr)
                        need_bracket = False
                        stack.append([])
                        level += 1
                elif token == ")":
-                       if need_bracket:
+                       if need_bracket or need_simple_token:
                                raise portage.exception.InvalidDependString(
                                        _("malformed syntax: '%s'") % depstr)
                        if level > 0:
@@ -302,22 +307,31 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
                                raise portage.exception.InvalidDependString(
                                        _("malformed syntax: '%s'") % depstr)
                elif token == "||":
-                       if need_bracket:
+                       if need_bracket or is_src_uri:
                                raise portage.exception.InvalidDependString(
                                        _("malformed syntax: '%s'") % depstr)
                        need_bracket = True
                        stack[level].append(token)
+               elif token == "->":
+                       if not allow_src_uri_file_renames or not is_src_uri or need_simple_token:
+                               raise portage.exception.InvalidDependString(
+                                       _("SRC_URI arrow not allowed: '%s'") % depstr)
+                       need_simple_token = True
+                       stack[level].append(token)      
                else:
-                       if need_bracket or "(" in token or ")" in token or "|" in token:
+                       if need_bracket or "(" in token or ")" in token or "|" in token or \
+                               (need_simple_token and "/" in token):
                                raise portage.exception.InvalidDependString(
                                        _("malformed syntax: '%s'") % depstr)
 
                        if token[-1] == "?":
                                need_bracket = True
+                       else:
+                               need_simple_token = False
 
                        stack[level].append(token)
 
-       if level != 0 or need_bracket:
+       if level != 0 or need_bracket or need_simple_token:
                raise portage.exception.InvalidDependString(
                        _("malformed syntax: '%s'") % depstr)
 
index a4a23242d51f4037136b72e2c73d3946192599e1..ed77c40a3493853b40c673d2243aa05c9f3ac6df 100644 (file)
@@ -7,17 +7,20 @@ from portage.dep import use_reduce
 
 class UseReduceTestCase(object):
        def __init__(self, deparray, uselist=[], masklist=[], \
-               matchall=0, excludeall=[], expected_result=None):
+               matchall=0, excludeall=[], is_src_uri=False, \
+               allow_src_uri_file_renames=False, expected_result=None):
                self.deparray = deparray
                self.uselist = uselist
                self.masklist = masklist
                self.matchall = matchall
                self.excludeall = excludeall
+               self.is_src_uri = is_src_uri
+               self.allow_src_uri_file_renames = allow_src_uri_file_renames
                self.expected_result = expected_result
 
        def run(self):
                return use_reduce(self.deparray, self.uselist, self.masklist, \
-                       self.matchall, self.excludeall)
+                       self.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames)
                                
 class UseReduce(TestCase):
 
@@ -202,6 +205,43 @@ class UseReduce(TestCase):
                                "foo? ( A ) foo? ( B )",
                                uselist = ["foo"],
                                expected_result = ["A", "B"]),
+                       
+                       #SRC_URI stuff
+                       UseReduceTestCase(
+                               "http://foo/bar -> blah.tbz2",
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = ["http://foo/bar", "->", "blah.tbz2"]),
+                       UseReduceTestCase(
+                               "foo? ( http://foo/bar -> blah.tbz2 )",
+                               uselist = [],
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = []),
+                       UseReduceTestCase(
+                               "foo? ( http://foo/bar -> blah.tbz2 )",
+                               uselist = ["foo"],
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = ["http://foo/bar", "->", "blah.tbz2"]),
+                       UseReduceTestCase(
+                               "http://foo/bar -> bar.tbz2 foo? ( ftp://foo/a )",
+                               uselist = [],
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = ["http://foo/bar", "->", "bar.tbz2"]),
+                       UseReduceTestCase(
+                               "http://foo/bar -> bar.tbz2 foo? ( ftp://foo/a )",
+                               uselist = ["foo"],
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = ["http://foo/bar", "->", "bar.tbz2", "ftp://foo/a"]),
+                       UseReduceTestCase(
+                               "http://foo.com/foo http://foo/bar -> blah.tbz2",
+                               uselist = ["foo"],
+                               is_src_uri = True,
+                               allow_src_uri_file_renames = True,
+                               expected_result = ["http://foo.com/foo", "http://foo/bar", "->", "blah.tbz2"]),
                )
                
                test_cases_xfail = (
@@ -221,6 +261,17 @@ class UseReduce(TestCase):
                        UseReduceTestCase("a? A"),
                        UseReduceTestCase("( || ( || || ( A ) foo? ( B ) ) )"),
                        UseReduceTestCase("( || ( || bar? ( A ) foo? ( B ) ) )"),
+                       
+                       #SRC_URI stuff
+                       UseReduceTestCase("http://foo/bar -> blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = False),
+                       UseReduceTestCase("|| ( http://foo/bar -> blah.tbz2 )", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("http://foo/bar -> foo? ( ftp://foo/a )", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("http://foo/bar blah.tbz2 ->", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("-> http://foo/bar blah.tbz2 )", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("http://foo/bar ->", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("http://foo/bar -> foo? ( http://foo.com/foo )", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("foo? ( http://foo/bar -> ) blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True),
+                       UseReduceTestCase("http://foo/bar -> foo/blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True),
                )
 
                for test_case in test_cases: