From: "Jesus Rivero" <neurogeek@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/tests/util/, pym/portage/util/
Date: Wed, 22 Jan 2014 04:49:15 +0000 (UTC) [thread overview]
Message-ID: <1390350571.dece844592b73a84330024bcf81fdcebcb6ff1c3.neurogeek@gentoo> (raw)
commit: dece844592b73a84330024bcf81fdcebcb6ff1c3
Author: Jesus Rivero <neurogeek <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 22 00:29:31 2014 +0000
Commit: Jesus Rivero <neurogeek <AT> gentoo <DOT> org>
CommitDate: Wed Jan 22 00:29:31 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=dece8445
Added support for variable expansion in source command argument in make.conf
---
.../tests/util/make.conf.example.source_test | 6 ++++++
.../tests/util/make.conf.example.source_test_after | 7 +++++++
pym/portage/tests/util/test_getconfig.py | 22 +++++++++++++++++++++-
pym/portage/util/__init__.py | 9 +++++++--
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/pym/portage/tests/util/make.conf.example.source_test b/pym/portage/tests/util/make.conf.example.source_test
new file mode 100644
index 0000000..c0b1c16
--- /dev/null
+++ b/pym/portage/tests/util/make.conf.example.source_test
@@ -0,0 +1,6 @@
+# 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/pym/portage/tests/util/make.conf.example.source_test_after b/pym/portage/tests/util/make.conf.example.source_test_after
new file mode 100644
index 0000000..e41913e
--- /dev/null
+++ b/pym/portage/tests/util/make.conf.example.source_test_after
@@ -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.
+# 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..e7b638f 100644
--- a/pym/portage/tests/util/test_getconfig.py
+++ b/pym/portage/tests/util/test_getconfig.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import tempfile
@@ -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,25 @@ class GetConfigTestCase(TestCase):
for k, v in self._cases.items():
self.assertEqual(d[k], v)
+ def testGetConfigSourceLex(self):
+
+ base = os.path.dirname(__file__)
+ 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.assertIsNotNone(d)
+ 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' : {}})
+
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..614b2b3 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2013 Gentoo Foundation
+# Copyright 2004-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import unicode_literals
@@ -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())
next reply other threads:[~2014-01-22 4:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-22 4:49 Jesus Rivero [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-06-27 3:32 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/util/, pym/portage/util/ Zac Medico
2017-04-20 19:39 Zac Medico
2012-05-12 22:17 Zac Medico
2011-07-01 8:47 Zac Medico
2011-06-28 9:09 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1390350571.dece844592b73a84330024bcf81fdcebcb6ff1c3.neurogeek@gentoo \
--to=neurogeek@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox