* [gentoo-portage-dev] [PATCH] Added support for variable expansion in source command. wrt bug #490896
@ 2014-01-12 23:21 99% Jesus Rivero (Neurogeek)
0 siblings, 0 replies; 1+ results
From: Jesus Rivero (Neurogeek) @ 2014-01-12 23:21 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1.1: Type: text/plain, Size: 573 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
Attached is a patch to allow variables in the argument for the source
command in make.conf
The implementation refactors what happens when allow_sourcing is True in
the portage.util.getconfig
function. Instead of just setting lex.source, now we also pass the
expand_map dict.
This patch fixes bug #490896
Jesus Rivero
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
iEYEARECAAYFAlLS5XgACgkQdIssYB9vBoOUoQCdFA2JfPHvjLDVp0mqDTo01Z9E
wMoAmgJLflNFTb9JoSnOJzZga6oJckYI
=3Atz
-----END PGP SIGNATURE-----
[-- Attachment #1.2: Type: text/html, Size: 819 bytes --]
[-- Attachment #2: 0001-Added-support-for-variable-expansion-in-source-command.patch --]
[-- Type: application/octet-stream, Size: 4097 bytes --]
From 6745a84475363772dca1464f7e39191ef7d0e240 Mon Sep 17 00:00:00 2001
From: Jesus Rivero <neurogeek@gentoo.org>
Date: Sun, 12 Jan 2014 18:33:16 +0000
Subject: [CHANGE] Added support for variable expansion in source command
argument in make.conf
---
cnf/make.conf.example.source_test | 7 +++++++
cnf/make.conf.example.source_test_after | 8 ++++++++
pym/portage/tests/util/test_getconfig.py | 18 ++++++++++++++++++
pym/portage/util/__init__.py | 7 ++++++-
4 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 cnf/make.conf.example.source_test
create mode 100644 cnf/make.conf.example.source_test_after
diff --git a/cnf/make.conf.example.source_test b/cnf/make.conf.example.source_test
new file mode 100644
index 0000000..abacd35
--- /dev/null
+++ b/cnf/make.conf.example.source_test
@@ -0,0 +1,7 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# Contains local system settings for Portage system
+
+# Test make.conf for variable expansion in
+# source tokens.
+source "$PORTAGE_BASE_PATH/make.conf.example.source_test_after"
diff --git a/cnf/make.conf.example.source_test_after b/cnf/make.conf.example.source_test_after
new file mode 100644
index 0000000..bc45ef3
--- /dev/null
+++ b/cnf/make.conf.example.source_test_after
@@ -0,0 +1,8 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# Contains local system settings for Portage system
+
+# Test make.conf for variable expansion in
+# source tokens.
+# We should see this variable in getconfig result
+PASSES_SOURCING_TEST="True"
diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py
index c7ab360..ad56f3f 100644
--- a/pym/portage/tests/util/test_getconfig.py
+++ b/pym/portage/tests/util/test_getconfig.py
@@ -8,6 +8,7 @@ from portage import _unicode_encode
from portage.const import PORTAGE_BASE_PATH
from portage.tests import TestCase
from portage.util import getconfig
+from portage.exception import ParseError
class GetConfigTestCase(TestCase):
"""
@@ -31,6 +32,23 @@ class GetConfigTestCase(TestCase):
for k, v in self._cases.items():
self.assertEqual(d[k], v)
+ def testGetConfigSourceLex(self):
+ base = os.path.join(PORTAGE_BASE_PATH, "cnf")
+ make_conf_file = os.path.join(base,
+ 'make.conf.example.source_test')
+
+ d = getconfig(make_conf_file,
+ allow_sourcing=True, expand={"PORTAGE_BASE_PATH" : base} )
+
+ # PASSES_SOURCING_TEST should exist in getconfig result
+ self.assertEqual("True", d['PASSES_SOURCING_TEST'])
+
+ # With allow_sourcing : True and empty expand map, this should
+ # Throw a FileNotFound exception
+ self.assertRaisesMsg("An empty expand map should throw an exception",
+ ParseError, getconfig, *(make_conf_file,),
+ **{'allow_sourcing' : True, 'expand' : {"PORTAGE_BASE_PATH" : base}})
+
def testGetConfigProfileEnv(self):
# Test the mode which is used to parse /etc/env.d and /etc/profile.env.
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 24553da..0799487 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -593,8 +593,13 @@ class _getconfig_shlex(shlex.shlex):
shlex.shlex.__init__(self, **kwargs)
self.__portage_tolerant = portage_tolerant
+ def allow_sourcing(self, var_expand_map):
+ self.source = portage._native_string("source")
+ self.var_expand_map = var_expand_map
+
def sourcehook(self, newfile):
try:
+ newfile = varexpand(newfile, self.var_expand_map)
return shlex.shlex.sourcehook(self, newfile)
except EnvironmentError as e:
if e.errno == PermissionDenied.errno:
@@ -694,7 +699,7 @@ def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True,
string.ascii_letters + "~!@#$%*_\:;?,./-+{}")
lex.quotes = portage._native_string("\"'")
if allow_sourcing:
- lex.source = portage._native_string("source")
+ lex.allow_sourcing(expand_map)
while True:
key = _unicode_decode(lex.get_token())
--
1.8.3.2
^ permalink raw reply related [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2014-01-12 23:21 99% [gentoo-portage-dev] [PATCH] Added support for variable expansion in source command. wrt bug #490896 Jesus Rivero (Neurogeek)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox