@type local_config: Boolean
"""
- debug = os.environ.get("PORTAGE_DEBUG") == "1"
+ # When initializing the global portage.settings instance, avoid
+ # raising exceptions whenever possible since exceptions thrown
+ # from 'import portage' or 'import portage.exceptions' statements
+ # can practically render the api unusable for api consumers.
+ tolerant = "_initializing_globals" in globals()
self.already_in_regenerate = 0
self.mygcfg = getconfig(
os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)),
- allow_sourcing=True)
+ tolerant=tolerant, allow_sourcing=True)
if self.mygcfg is None:
self.mygcfg = {}
for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")):
kwargs[k] = os.environ.get(envvar, "/")
+ global _initializing_globals
+ _initializing_globals = True
db = create_trees(**kwargs)
+ del _initializing_globals
settings = db["/"]["vartree"].settings
portdb = db["/"]["porttree"].dbapi
except ImportError:
import pickle as cPickle
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
noiselimit = 0
def initialize_logger(level=logging.WARN):
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:
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: