1 |
Signed-off-by: Jesus Rivero <neurogeek@g.o> |
2 |
--- |
3 |
pym/portage/tests/util/make.conf.example.source_test | 6 ++++++ |
4 |
.../tests/util/make.conf.example.source_test_after | 7 +++++++ |
5 |
pym/portage/tests/util/test_getconfig.py | 20 ++++++++++++++++++++ |
6 |
pym/portage/util/__init__.py | 7 ++++++- |
7 |
4 files changed, 39 insertions(+), 1 deletion(-) |
8 |
create mode 100644 pym/portage/tests/util/make.conf.example.source_test |
9 |
create mode 100644 pym/portage/tests/util/make.conf.example.source_test_after |
10 |
|
11 |
diff --git a/pym/portage/tests/util/make.conf.example.source_test b/pym/portage/tests/util/make.conf.example.source_test |
12 |
new file mode 100644 |
13 |
index 0000000..c0b1c16 |
14 |
--- /dev/null |
15 |
+++ b/pym/portage/tests/util/make.conf.example.source_test |
16 |
@@ -0,0 +1,6 @@ |
17 |
+# Copyright 1999-2014 Gentoo Foundation |
18 |
+# Distributed under the terms of the GNU General Public License v2 |
19 |
+# Contains local system settings for Portage system |
20 |
+ |
21 |
+# Test make.conf for variable expansion in source tokens. |
22 |
+source "$PORTAGE_BASE_PATH/make.conf.example.source_test_after" |
23 |
diff --git a/pym/portage/tests/util/make.conf.example.source_test_after b/pym/portage/tests/util/make.conf.example.source_test_after |
24 |
new file mode 100644 |
25 |
index 0000000..e41913e |
26 |
--- /dev/null |
27 |
+++ b/pym/portage/tests/util/make.conf.example.source_test_after |
28 |
@@ -0,0 +1,7 @@ |
29 |
+# Copyright 1999-2014 Gentoo Foundation |
30 |
+# Distributed under the terms of the GNU General Public License v2 |
31 |
+# Contains local system settings for Portage system |
32 |
+ |
33 |
+# Test make.conf for variable expansion in source tokens. |
34 |
+# We should see this variable in getconfig result |
35 |
+PASSES_SOURCING_TEST="True" |
36 |
diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py |
37 |
index c7ab360..bffbc4f 100644 |
38 |
--- a/pym/portage/tests/util/test_getconfig.py |
39 |
+++ b/pym/portage/tests/util/test_getconfig.py |
40 |
@@ -8,6 +8,7 @@ from portage import _unicode_encode |
41 |
from portage.const import PORTAGE_BASE_PATH |
42 |
from portage.tests import TestCase |
43 |
from portage.util import getconfig |
44 |
+from portage.exception import ParseError |
45 |
|
46 |
class GetConfigTestCase(TestCase): |
47 |
""" |
48 |
@@ -31,6 +32,25 @@ class GetConfigTestCase(TestCase): |
49 |
for k, v in self._cases.items(): |
50 |
self.assertEqual(d[k], v) |
51 |
|
52 |
+ def testGetConfigSourceLex(self): |
53 |
+ |
54 |
+ base = os.path.dirname(__file__) |
55 |
+ make_conf_file = os.path.join(base, |
56 |
+ 'make.conf.example.source_test') |
57 |
+ |
58 |
+ d = getconfig(make_conf_file, |
59 |
+ allow_sourcing=True, expand={"PORTAGE_BASE_PATH" : base}) |
60 |
+ |
61 |
+ # PASSES_SOURCING_TEST should exist in getconfig result |
62 |
+ self.assertIsNotNone(d) |
63 |
+ self.assertEqual("True", d['PASSES_SOURCING_TEST']) |
64 |
+ |
65 |
+ # With allow_sourcing : True and empty expand map, this should |
66 |
+ # Throw a FileNotFound exception |
67 |
+ self.assertRaisesMsg("An empty expand map should throw an exception", |
68 |
+ ParseError, getconfig, *(make_conf_file,), |
69 |
+ **{'allow_sourcing' : True, 'expand' : {}}) |
70 |
+ |
71 |
def testGetConfigProfileEnv(self): |
72 |
# Test the mode which is used to parse /etc/env.d and /etc/profile.env. |
73 |
|
74 |
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py |
75 |
index 24553da..0799487 100644 |
76 |
--- a/pym/portage/util/__init__.py |
77 |
+++ b/pym/portage/util/__init__.py |
78 |
@@ -593,8 +593,13 @@ class _getconfig_shlex(shlex.shlex): |
79 |
shlex.shlex.__init__(self, **kwargs) |
80 |
self.__portage_tolerant = portage_tolerant |
81 |
|
82 |
+ def allow_sourcing(self, var_expand_map): |
83 |
+ self.source = portage._native_string("source") |
84 |
+ self.var_expand_map = var_expand_map |
85 |
+ |
86 |
def sourcehook(self, newfile): |
87 |
try: |
88 |
+ newfile = varexpand(newfile, self.var_expand_map) |
89 |
return shlex.shlex.sourcehook(self, newfile) |
90 |
except EnvironmentError as e: |
91 |
if e.errno == PermissionDenied.errno: |
92 |
@@ -694,7 +699,7 @@ def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, |
93 |
string.ascii_letters + "~!@#$%*_\:;?,./-+{}") |
94 |
lex.quotes = portage._native_string("\"'") |
95 |
if allow_sourcing: |
96 |
- lex.source = portage._native_string("source") |
97 |
+ lex.allow_sourcing(expand_map) |
98 |
|
99 |
while True: |
100 |
key = _unicode_decode(lex.get_token()) |
101 |
-- |
102 |
1.8.3.2 |