summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorSebastian Luther <SebastianLuther@gmx.de>2010-08-16 14:28:31 +0200
committerZac Medico <zmedico@gentoo.org>2010-08-16 05:45:09 -0700
commit8662cda45964d0bfeadd5bddf9cbec01af6a205e (patch)
tree6841d78f8247cf0d860037acf0809315caa0cb2f /pym
parentf0afbe6b21c7c960e8ad8cbf981d1004a613151d (diff)
downloadportage-8662cda45964d0bfeadd5bddf9cbec01af6a205e.tar.gz
portage-8662cda45964d0bfeadd5bddf9cbec01af6a205e.tar.bz2
portage-8662cda45964d0bfeadd5bddf9cbec01af6a205e.zip
portage.dep.use_reduce: Better error messages
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dep/__init__.py64
-rw-r--r--pym/portage/tests/dep/test_use_reduce.py7
2 files changed, 50 insertions, 21 deletions
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 7d7800904..d30ccbbff 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -267,11 +267,11 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
if is_valid_flag:
if not is_valid_flag(flag):
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("use flag '%s' is not referencable in conditional '%s' in '%s'") % (flag, conditional, depstr))
else:
if _valid_use_re.match(flag) is None:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("invalid use flag '%s' in conditional '%s' in '%s'") % (flag, conditional, depstr))
if is_negated and flag in excludeall:
return False
@@ -285,24 +285,36 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
return (flag in uselist and not is_negated) or \
(flag not in uselist and is_negated)
+ def invalid_token_check(token, pos):
+ for x in (")", "(", "||"):
+ if token.startswith(x) or token.endswith(x):
+ raise portage.exception.InvalidDependString(
+ _("missing whitespace around '%s' at '%s' in '%s', token %s") % (x, token, depstr, pos+1))
+
+ raise portage.exception.InvalidDependString(
+ _("invalid token '%s' in '%s', token %s") % (token, depstr, pos+1))
+
mysplit = depstr.split()
level = 0
stack = [[]]
need_bracket = False
need_simple_token = False
- for token in mysplit:
+ for pos, token in enumerate(mysplit):
if token == "(":
if need_simple_token:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("expected: file name, got: '%s' in '%s', token %s") % (token, depstr, pos+1))
need_bracket = False
stack.append([])
level += 1
elif token == ")":
- if need_bracket or need_simple_token:
+ if need_bracket:
+ raise portage.exception.InvalidDependString(
+ _("expected: '(', got: '%s' in '%s', token %s") % (token, depstr, pos+1))
+ if need_simple_token:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("expected: file name, got: '%s' in '%s', token %s") % (token, depstr, pos+1))
if level > 0:
level -= 1
l = stack.pop()
@@ -347,31 +359,43 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
stack[level].append(l)
else:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("no matching '%s' for '%s' in '%s', token %s") % ("(", ")", depstr, pos+1))
elif token == "||":
- if need_bracket or is_src_uri:
+ if is_src_uri:
+ raise portage.exception.InvalidDependString(
+ _("any-of dependencies are not allowed in SRC_URI: '%s', token %s") % (depstr, pos+1))
+ if need_bracket:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("expected: '(', got: '%s' in '%s', token %s") % (token, depstr, pos+1))
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:
+ if need_simple_token:
+ raise portage.exception.InvalidDependString(
+ _("expected: file name, got: '%s' in '%s', token %s") % (token, depstr, pos+1))
+ if not is_src_uri:
raise portage.exception.InvalidDependString(
- _("SRC_URI arrow not allowed: '%s'") % depstr)
+ _("SRC_URI arrow are only allowed in SRC_URI: '%s', token %s") % (depstr, pos+1))
+ if not allow_src_uri_file_renames:
+ raise portage.exception.InvalidDependString(
+ _("SRC_URI arrow not allowed in this EAPI: '%s', token %s") % (depstr, pos+1))
need_simple_token = True
stack[level].append(token)
else:
- if need_bracket or "(" in token or ")" in token or "|" in token or \
- (need_simple_token and "/" in token):
- if not (need_bracket or "|" in token or (need_simple_token and "/" in token)):
- #We have '(' and/or ')' in token. Make sure it's not a use dep default
- tmp = token.replace("(+)", "").replace("(-)", "")
- if "(" in tmp or ")" in tmp:
- raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ if need_bracket:
+ if token.startswith("("):
+ raise portage.exception.InvalidDependString(
+ _("missing whitespace around '%s' at '%s' in '%s', token %s") % ("(", token, depstr, pos+1))
else:
raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+ _("expected: '(', got: '%s' in '%s', token %s") % (token, depstr, pos+1))
+
+ if "(" in token or ")" in token or "|" in token:
+ invalid_token_check(token, pos)
+
+ if need_simple_token and "/" in token:
+ raise portage.exception.InvalidDependString(
+ _("expected: file name, got: '%s' in '%s', token %s") % (token, depstr, pos+1))
if token[-1] == "?":
need_bracket = True
diff --git a/pym/portage/tests/dep/test_use_reduce.py b/pym/portage/tests/dep/test_use_reduce.py
index 964081c35..6dffb6107 100644
--- a/pym/portage/tests/dep/test_use_reduce.py
+++ b/pym/portage/tests/dep/test_use_reduce.py
@@ -404,12 +404,12 @@ class UseReduce(TestCase):
flat = True,
expected_result = ["A", "B"]),
+ #use flag validation
UseReduceTestCase(
"foo? ( A )",
uselist = ["foo"],
is_valid_flag = self.always_true,
expected_result = ["A"]),
-
UseReduceTestCase(
"foo? ( A )",
is_valid_flag = self.always_true,
@@ -433,6 +433,7 @@ class UseReduce(TestCase):
UseReduceTestCase("a? A"),
UseReduceTestCase("( || ( || || ( A ) foo? ( B ) ) )"),
UseReduceTestCase("( || ( || bar? ( A ) foo? ( B ) ) )"),
+ UseReduceTestCase("A(B"),
#SRC_URI stuff
UseReduceTestCase("http://foo/bar -> blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = False),
@@ -444,12 +445,16 @@ class UseReduce(TestCase):
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),
+ UseReduceTestCase("http://foo/bar -> -> bar.tbz2 foo? ( ftp://foo/a )", is_src_uri = True, allow_src_uri_file_renames = True),
+
+ UseReduceTestCase("http://foo/bar -> bar.tbz2 foo? ( ftp://foo/a )", is_src_uri = False, allow_src_uri_file_renames = True),
UseReduceTestCase(
"A",
opconvert = True,
flat = True),
+ #use flag validation
UseReduceTestCase("1.0? ( A )"),
UseReduceTestCase("!1.0? ( A )"),
UseReduceTestCase("!? ( A )"),