From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 408F8138247 for ; Tue, 14 Jan 2014 04:29:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 52134E0B90; Tue, 14 Jan 2014 04:29:49 +0000 (UTC) Received: from mail-qc0-f176.google.com (mail-qc0-f176.google.com [209.85.216.176]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C9A89E0B8D for ; Tue, 14 Jan 2014 04:29:48 +0000 (UTC) Received: by mail-qc0-f176.google.com with SMTP id e16so4938949qcx.21 for ; Mon, 13 Jan 2014 20:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=UXPCMMJQ0/oPJhSUhrEZqSkDZi7ZnPW3sU9eO0TmN5E=; b=mGAZJU/VDKUlRi7QlhiDQh0JTWDMyDGvIJ3g2D7id3p2zGb+2tgvSR4HJuUoNloCtK tqyFVGV3hGA/W9h1JUs0E/5kQ9O4LTF+s2ZpYwnxHwBPidgvss7sDGTApOyPOxJ20tUF ioxkJBYgY8aLR2EmA2G/d18ofRkndDywZ0hEakCGkfiP1G35jLneu7cQyFnQrZeFFe6o kB7BsRaTVmxKFxLFRYByr3DelYSGG5i+VfyPJekepLlP/anfsPYXd4RtfsQCkM6AnlLb PO/86UV7rIrOlDnIPhq25oG0F9NaR5za0JJwaUFyDEDGRpU17ZHSh0KCdEgUJxf7z5WQ eg4A== X-Received: by 10.49.131.69 with SMTP id ok5mr46335709qeb.77.1389673787978; Mon, 13 Jan 2014 20:29:47 -0800 (PST) Received: from localhost.localdomain (pool-71-172-34-99.nwrknj.fios.verizon.net. [71.172.34.99]) by mx.google.com with ESMTPSA id t10sm18428253qef.23.2014.01.13.20.29.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Jan 2014 20:29:47 -0800 (PST) Sender: Neurogeek From: Jesus Rivero To: gentoo-portage-dev@lists.gentoo.org Cc: Jesus Rivero Subject: [gentoo-portage-dev] [PATCH v3] Added support for variable expansion in source command argument in make.conf Date: Mon, 13 Jan 2014 19:10:22 -0500 Message-Id: <1389658222-28921-1-git-send-email-neurogeek@gentoo.org> X-Mailer: git-send-email 1.7.2.2 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 3efd8f43-6ab1-49fe-ade3-eb177aae2215 X-Archives-Hash: c8d6abe1e8d26f0dd15b2bec4c3003af Signed-off-by: Jesus Rivero --- pym/portage/tests/util/make.conf.example.source_test | 6 ++++++ .../tests/util/make.conf.example.source_test_after | 7 +++++++ pym/portage/tests/util/test_getconfig.py | 20 ++++++++++++++++++++ pym/portage/util/__init__.py | 7 ++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 pym/portage/tests/util/make.conf.example.source_test create mode 100644 pym/portage/tests/util/make.conf.example.source_test_after 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..bffbc4f 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,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..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