summaryrefslogtreecommitdiffstats
path: root/pym/portage_util.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-03-01 00:10:37 +0000
committerZac Medico <zmedico@gentoo.org>2008-03-01 00:10:37 +0000
commitedf4aa7cf938f71ba9d8faaefd7870cb66deb24c (patch)
tree27cce4d02ba3158c1dba7c5d900393939b6bc8d6 /pym/portage_util.py
parent21596c1e3202ed9b9ccd59a5a2d6b0d83f94d74d (diff)
downloadportage-edf4aa7cf938f71ba9d8faaefd7870cb66deb24c.tar.gz
portage-edf4aa7cf938f71ba9d8faaefd7870cb66deb24c.tar.bz2
portage-edf4aa7cf938f71ba9d8faaefd7870cb66deb24c.zip
Make 'import portage' statements more tolerant to broken source statements
in make.conf since exceptions thrown during 'import portage' statements can practically render the api unusable for api consumers. Thanks to lxnay for the suggestion. (trunk r9400) svn path=/main/branches/2.1.2/; revision=9401
Diffstat (limited to 'pym/portage_util.py')
-rw-r--r--pym/portage_util.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 486376bfc..902ed091f 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -16,6 +16,11 @@ except ImportError:
if not hasattr(__builtins__, "set"):
from sets import Set as set
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
noiselimit = 0
def writemsg(mystr,noiselevel=0,fd=None):
@@ -291,6 +296,15 @@ def writedict(mydict,myfilename,writekey=True):
return 0
return 1
+class _tolerant_shlex(shlex.shlex):
+ def sourcehook(self, newfile):
+ try:
+ return shlex.shlex.sourcehook(self, newfile)
+ except EnvironmentError, e:
+ writemsg("!!! Parse error in '%s': source command failed: %s\n" % \
+ (self.infile, str(e)), noiselevel=-1)
+ return (newfile, StringIO.StringIO())
+
def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
mykeys={}
try:
@@ -302,10 +316,14 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
raise
return None
try:
+ if tolerant:
+ shlex_class = _tolerant_shlex
+ else:
+ shlex_class = shlex.shlex
# The default shlex.sourcehook() implementation
# only joins relative paths when the infile
# attribute is properly set.
- lex = shlex.shlex(f, infile=mycfg, posix=True)
+ lex = shlex_class(f, infile=mycfg, posix=True)
lex.wordchars=string.digits+string.letters+"~!@#$%*_\:;?,./-+{}"
lex.quotes="\"'"
if allow_sourcing: