Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r9400 - main/trunk/pym/portage
Date: Sat, 01 Mar 2008 00:04:14
Message-Id: E1JVFD0-0003lE-MY@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-03-01 00:04:09 +0000 (Sat, 01 Mar 2008)
3 New Revision: 9400
4
5 Modified:
6 main/trunk/pym/portage/__init__.py
7 main/trunk/pym/portage/util.py
8 Log:
9 Make 'import portage' statements more tolerant to broken source statements
10 in make.conf since exceptions thrown during 'import portage' statements
11 can practically render the api unusable for api consumers. Thanks to lxnay
12 for the suggestion.
13
14
15 Modified: main/trunk/pym/portage/__init__.py
16 ===================================================================
17 --- main/trunk/pym/portage/__init__.py 2008-02-29 22:58:15 UTC (rev 9399)
18 +++ main/trunk/pym/portage/__init__.py 2008-03-01 00:04:09 UTC (rev 9400)
19 @@ -969,7 +969,11 @@
20 @type local_config: Boolean
21 """
22
23 - debug = os.environ.get("PORTAGE_DEBUG") == "1"
24 + # When initializing the global portage.settings instance, avoid
25 + # raising exceptions whenever possible since exceptions thrown
26 + # from 'import portage' or 'import portage.exceptions' statements
27 + # can practically render the api unusable for api consumers.
28 + tolerant = "_initializing_globals" in globals()
29
30 self.already_in_regenerate = 0
31
32 @@ -1244,7 +1248,7 @@
33
34 self.mygcfg = getconfig(
35 os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)),
36 - allow_sourcing=True)
37 + tolerant=tolerant, allow_sourcing=True)
38 if self.mygcfg is None:
39 self.mygcfg = {}
40
41 @@ -6284,7 +6288,10 @@
42 for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")):
43 kwargs[k] = os.environ.get(envvar, "/")
44
45 + global _initializing_globals
46 + _initializing_globals = True
47 db = create_trees(**kwargs)
48 + del _initializing_globals
49
50 settings = db["/"]["vartree"].settings
51 portdb = db["/"]["porttree"].dbapi
52
53 Modified: main/trunk/pym/portage/util.py
54 ===================================================================
55 --- main/trunk/pym/portage/util.py 2008-02-29 22:58:15 UTC (rev 9399)
56 +++ main/trunk/pym/portage/util.py 2008-03-01 00:04:09 UTC (rev 9400)
57 @@ -21,6 +21,11 @@
58 except ImportError:
59 import pickle as cPickle
60
61 +try:
62 + import cStringIO as StringIO
63 +except ImportError:
64 + import StringIO
65 +
66 noiselimit = 0
67
68 def initialize_logger(level=logging.WARN):
69 @@ -305,6 +310,15 @@
70 return 0
71 return 1
72
73 +class _tolerant_shlex(shlex.shlex):
74 + def sourcehook(self, newfile):
75 + try:
76 + return shlex.shlex.sourcehook(self, newfile)
77 + except EnvironmentError, e:
78 + writemsg("!!! Parse error in '%s': source command failed: %s\n" % \
79 + (self.infile, str(e)), noiselevel=-1)
80 + return (newfile, StringIO.StringIO())
81 +
82 def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
83 mykeys={}
84 try:
85 @@ -316,10 +330,14 @@
86 raise
87 return None
88 try:
89 + if tolerant:
90 + shlex_class = _tolerant_shlex
91 + else:
92 + shlex_class = shlex.shlex
93 # The default shlex.sourcehook() implementation
94 # only joins relative paths when the infile
95 # attribute is properly set.
96 - lex = shlex.shlex(f, infile=mycfg, posix=True)
97 + lex = shlex_class(f, infile=mycfg, posix=True)
98 lex.wordchars=string.digits+string.letters+"~!@#$%*_\:;?,./-+{}"
99 lex.quotes="\"'"
100 if allow_sourcing:
101
102 --
103 gentoo-commits@l.g.o mailing list