1 |
commit: 7342ef701af9eae725d89b784410884560793519 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Mar 31 21:17:23 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Mar 31 21:17:23 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7342ef70 |
7 |
|
8 |
getconfig: show error message for varexpand fail |
9 |
|
10 |
--- |
11 |
pym/portage/util/__init__.py | 21 +++++++++++++++++++-- |
12 |
1 files changed, 19 insertions(+), 2 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py |
15 |
index a7bc9bd..3e7187c 100644 |
16 |
--- a/pym/portage/util/__init__.py |
17 |
+++ b/pym/portage/util/__init__.py |
18 |
@@ -636,7 +636,8 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): |
19 |
continue |
20 |
|
21 |
if expand: |
22 |
- mykeys[key] = varexpand(val, expand_map) |
23 |
+ mykeys[key] = varexpand(val, mydict=expand_map, |
24 |
+ error_leader=lex.error_leader) |
25 |
expand_map[key] = mykeys[key] |
26 |
else: |
27 |
mykeys[key] = val |
28 |
@@ -647,8 +648,9 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): |
29 |
return mykeys |
30 |
|
31 |
_varexpand_word_chars = frozenset(string.ascii_letters + string.digits + "_") |
32 |
+_varexpand_unexpected_eof_msg = "unexpected EOF while looking for matching `}'" |
33 |
|
34 |
-def varexpand(mystring, mydict=None): |
35 |
+def varexpand(mystring, mydict=None, error_leader=None): |
36 |
if mydict is None: |
37 |
mydict = {} |
38 |
|
39 |
@@ -720,6 +722,10 @@ def varexpand(mystring, mydict=None): |
40 |
while mystring[pos] in _varexpand_word_chars: |
41 |
if (pos+1)>=len(mystring): |
42 |
if braced: |
43 |
+ msg = _varexpand_unexpected_eof_msg |
44 |
+ if error_leader is not None: |
45 |
+ msg = error_leader() + msg |
46 |
+ writemsg(msg + "\n", noiselevel=-1) |
47 |
return "" |
48 |
else: |
49 |
pos=pos+1 |
50 |
@@ -728,10 +734,21 @@ def varexpand(mystring, mydict=None): |
51 |
myvarname=mystring[myvstart:pos] |
52 |
if braced: |
53 |
if mystring[pos]!="}": |
54 |
+ msg = _varexpand_unexpected_eof_msg |
55 |
+ if error_leader is not None: |
56 |
+ msg = error_leader() + msg |
57 |
+ writemsg(msg + "\n", noiselevel=-1) |
58 |
return "" |
59 |
else: |
60 |
pos=pos+1 |
61 |
if len(myvarname)==0: |
62 |
+ msg = "$" |
63 |
+ if braced: |
64 |
+ msg += "{}" |
65 |
+ msg += ": bad substitution" |
66 |
+ if error_leader is not None: |
67 |
+ msg = error_leader() + msg |
68 |
+ writemsg(msg + "\n", noiselevel=-1) |
69 |
return "" |
70 |
numvars=numvars+1 |
71 |
if myvarname in mydict: |