summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-05-15 17:06:38 -0700
committerZac Medico <zmedico@gentoo.org>2012-05-15 17:06:38 -0700
commitaa109884a0168656c3548cc90ca5a4854f3928c2 (patch)
tree656818e296f204576f85d8684fb5f269da20dae7
parent999907a64249d9bfd2e42e477bfb9dd9a3cb535a (diff)
downloadportage-aa109884a0168656c3548cc90ca5a4854f3928c2.tar.gz
portage-aa109884a0168656c3548cc90ca5a4854f3928c2.tar.bz2
portage-aa109884a0168656c3548cc90ca5a4854f3928c2.zip
getconfig: use shlex.error_leader() more
This fixes it to show the correct file/line, even when one file sources another.
-rw-r--r--pym/portage/util/__init__.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 57e8c37b7..4797f53e4 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -41,7 +41,7 @@ from portage import _os_merge
from portage import _unicode_encode
from portage import _unicode_decode
from portage.exception import InvalidAtom, PortageException, FileNotFound, \
- OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
+ OperationNotPermitted, ParseError, PermissionDenied, ReadOnlyFileSystem
from portage.localization import _
from portage.proxy.objectproxy import ObjectProxy
from portage.cache.mappings import UserDict
@@ -573,6 +573,7 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
writemsg(("!!! " + _("Please use dos2unix to convert line endings " + \
"in config file: '%s'") + "\n") % mycfg, noiselevel=-1)
+ lex = None
try:
if tolerant:
shlex_class = _tolerant_shlex
@@ -596,43 +597,38 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
break;
equ=lex.get_token()
if (equ==''):
- #unexpected end of file
- #lex.error_leader(self.filename,lex.lineno)
+ msg = lex.error_leader() + _("Unexpected EOF")
if not tolerant:
- writemsg(_("!!! Unexpected end of config file: variable %s\n") % key,
- noiselevel=-1)
- raise Exception(_("ParseError: Unexpected EOF: %s: on/before line %s") % (mycfg, lex.lineno))
+ raise ParseError(msg)
else:
+ writemsg("%s\n" % msg, noiselevel=-1)
return mykeys
elif (equ!='='):
- #invalid token
- #lex.error_leader(self.filename,lex.lineno)
+ msg = lex.error_leader() + \
+ _("Invalid token '%s' (not '=')") % (equ,)
if not tolerant:
- raise Exception(_("ParseError: Invalid token "
- "'%s' (not '='): %s: line %s") % \
- (equ, mycfg, lex.lineno))
+ raise Exception(msg)
else:
+ writemsg("%s\n" % msg, noiselevel=-1)
return mykeys
val=lex.get_token()
if val is None:
- #unexpected end of file
- #lex.error_leader(self.filename,lex.lineno)
+ msg = lex.error_leader() + \
+ _("Unexpected end of config file: variable '%s'") % (key,)
if not tolerant:
- writemsg(_("!!! Unexpected end of config file: variable %s\n") % key,
- noiselevel=-1)
- raise portage.exception.CorruptionError(_("ParseError: Unexpected EOF: %s: line %s") % (mycfg, lex.lineno))
+ raise ParseError(msg)
else:
+ writemsg("%s\n" % msg, noiselevel=-1)
return mykeys
key = _unicode_decode(key)
val = _unicode_decode(val)
if _invalid_var_name_re.search(key) is not None:
+ msg = lex.error_leader() + \
+ _("Invalid variable name '%s'") % (key,)
if not tolerant:
- raise Exception(_(
- "ParseError: Invalid variable name '%s': line %s") % \
- (key, lex.lineno - 1))
- writemsg(_("!!! Invalid variable name '%s': line %s in %s\n") \
- % (key, lex.lineno - 1, mycfg), noiselevel=-1)
+ raise ParseError(msg)
+ writemsg("%s\n" % msg, noiselevel=-1)
continue
if expand:
@@ -644,7 +640,12 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
except SystemExit as e:
raise
except Exception as e:
- raise portage.exception.ParseError(str(e)+" in "+mycfg)
+ if isinstance(e, ParseError) or lex is None:
+ raise
+ msg = _unicode_decode("%s%s") % (lex.error_leader(), e)
+ writemsg("%s\n" % msg, noiselevel=-1)
+ raise
+
return mykeys
_varexpand_word_chars = frozenset(string.ascii_letters + string.digits + "_")