Gentoo Archives: gentoo-commits

From: Jesus Rivero <neurogeek@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/tests/util/, pym/portage/util/
Date: Wed, 22 Jan 2014 04:49:19
Message-Id: 1390350571.dece844592b73a84330024bcf81fdcebcb6ff1c3.neurogeek@gentoo
1 commit: dece844592b73a84330024bcf81fdcebcb6ff1c3
2 Author: Jesus Rivero <neurogeek <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jan 22 00:29:31 2014 +0000
4 Commit: Jesus Rivero <neurogeek <AT> gentoo <DOT> org>
5 CommitDate: Wed Jan 22 00:29:31 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=dece8445
7
8 Added support for variable expansion in source command argument in make.conf
9
10 ---
11 .../tests/util/make.conf.example.source_test | 6 ++++++
12 .../tests/util/make.conf.example.source_test_after | 7 +++++++
13 pym/portage/tests/util/test_getconfig.py | 22 +++++++++++++++++++++-
14 pym/portage/util/__init__.py | 9 +++++++--
15 4 files changed, 41 insertions(+), 3 deletions(-)
16
17 diff --git a/pym/portage/tests/util/make.conf.example.source_test b/pym/portage/tests/util/make.conf.example.source_test
18 new file mode 100644
19 index 0000000..c0b1c16
20 --- /dev/null
21 +++ b/pym/portage/tests/util/make.conf.example.source_test
22 @@ -0,0 +1,6 @@
23 +# Copyright 1999-2014 Gentoo Foundation
24 +# Distributed under the terms of the GNU General Public License v2
25 +# Contains local system settings for Portage system
26 +
27 +# Test make.conf for variable expansion in source tokens.
28 +source "$PORTAGE_BASE_PATH/make.conf.example.source_test_after"
29
30 diff --git a/pym/portage/tests/util/make.conf.example.source_test_after b/pym/portage/tests/util/make.conf.example.source_test_after
31 new file mode 100644
32 index 0000000..e41913e
33 --- /dev/null
34 +++ b/pym/portage/tests/util/make.conf.example.source_test_after
35 @@ -0,0 +1,7 @@
36 +# Copyright 1999-2014 Gentoo Foundation
37 +# Distributed under the terms of the GNU General Public License v2
38 +# Contains local system settings for Portage system
39 +
40 +# Test make.conf for variable expansion in source tokens.
41 +# We should see this variable in getconfig result
42 +PASSES_SOURCING_TEST="True"
43
44 diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py
45 index c7ab360..e7b638f 100644
46 --- a/pym/portage/tests/util/test_getconfig.py
47 +++ b/pym/portage/tests/util/test_getconfig.py
48 @@ -1,4 +1,4 @@
49 -# Copyright 2010-2012 Gentoo Foundation
50 +# Copyright 2010-2014 Gentoo Foundation
51 # Distributed under the terms of the GNU General Public License v2
52
53 import tempfile
54 @@ -8,6 +8,7 @@ from portage import _unicode_encode
55 from portage.const import PORTAGE_BASE_PATH
56 from portage.tests import TestCase
57 from portage.util import getconfig
58 +from portage.exception import ParseError
59
60 class GetConfigTestCase(TestCase):
61 """
62 @@ -31,6 +32,25 @@ class GetConfigTestCase(TestCase):
63 for k, v in self._cases.items():
64 self.assertEqual(d[k], v)
65
66 + def testGetConfigSourceLex(self):
67 +
68 + base = os.path.dirname(__file__)
69 + make_conf_file = os.path.join(base,
70 + 'make.conf.example.source_test')
71 +
72 + d = getconfig(make_conf_file,
73 + allow_sourcing=True, expand={"PORTAGE_BASE_PATH" : base})
74 +
75 + # PASSES_SOURCING_TEST should exist in getconfig result
76 + self.assertIsNotNone(d)
77 + self.assertEqual("True", d['PASSES_SOURCING_TEST'])
78 +
79 + # With allow_sourcing : True and empty expand map, this should
80 + # Throw a FileNotFound exception
81 + self.assertRaisesMsg("An empty expand map should throw an exception",
82 + ParseError, getconfig, *(make_conf_file,),
83 + **{'allow_sourcing' : True, 'expand' : {}})
84 +
85 def testGetConfigProfileEnv(self):
86 # Test the mode which is used to parse /etc/env.d and /etc/profile.env.
87
88
89 diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
90 index 24553da..614b2b3 100644
91 --- a/pym/portage/util/__init__.py
92 +++ b/pym/portage/util/__init__.py
93 @@ -1,4 +1,4 @@
94 -# Copyright 2004-2013 Gentoo Foundation
95 +# Copyright 2004-2014 Gentoo Foundation
96 # Distributed under the terms of the GNU General Public License v2
97
98 from __future__ import unicode_literals
99 @@ -593,8 +593,13 @@ class _getconfig_shlex(shlex.shlex):
100 shlex.shlex.__init__(self, **kwargs)
101 self.__portage_tolerant = portage_tolerant
102
103 + def allow_sourcing(self, var_expand_map):
104 + self.source = portage._native_string("source")
105 + self.var_expand_map = var_expand_map
106 +
107 def sourcehook(self, newfile):
108 try:
109 + newfile = varexpand(newfile, self.var_expand_map)
110 return shlex.shlex.sourcehook(self, newfile)
111 except EnvironmentError as e:
112 if e.errno == PermissionDenied.errno:
113 @@ -694,7 +699,7 @@ def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True,
114 string.ascii_letters + "~!@#$%*_\:;?,./-+{}")
115 lex.quotes = portage._native_string("\"'")
116 if allow_sourcing:
117 - lex.source = portage._native_string("source")
118 + lex.allow_sourcing(expand_map)
119
120 while True:
121 key = _unicode_decode(lex.get_token())