1 |
commit: e8ea1bcb31db5929e19dac0392922994a9577bdd |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Dec 22 00:29:30 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Dec 22 00:29:30 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e8ea1bcb |
7 |
|
8 |
vardbapi._aux_get: search environment in one pass |
9 |
|
10 |
--- |
11 |
pym/portage/dbapi/vartree.py | 96 +++++++++++++++++++++++------------------- |
12 |
1 files changed, 53 insertions(+), 43 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py |
15 |
index 7184550..c2e90d8 100644 |
16 |
--- a/pym/portage/dbapi/vartree.py |
17 |
+++ b/pym/portage/dbapi/vartree.py |
18 |
@@ -625,7 +625,8 @@ class vardbapi(dbapi): |
19 |
cache_these_wants.add(x) |
20 |
|
21 |
if not cache_these_wants: |
22 |
- return self._aux_get(mycpv, wants) |
23 |
+ mydata = self._aux_get(mycpv, wants) |
24 |
+ return [mydata[x] for x in wants] |
25 |
|
26 |
cache_these = set(self._aux_cache_keys) |
27 |
cache_these.update(cache_these_wants) |
28 |
@@ -670,9 +671,7 @@ class vardbapi(dbapi): |
29 |
if pull_me: |
30 |
# pull any needed data and cache it |
31 |
aux_keys = list(pull_me) |
32 |
- for k, v in zip(aux_keys, |
33 |
- self._aux_get(mycpv, aux_keys, st=mydir_stat)): |
34 |
- mydata[k] = v |
35 |
+ mydata.update(self._aux_get(mycpv, aux_keys, st=mydir_stat)) |
36 |
if not cache_valid or cache_these.difference(metadata): |
37 |
cache_data = {} |
38 |
if cache_valid and metadata: |
39 |
@@ -703,10 +702,11 @@ class vardbapi(dbapi): |
40 |
raise |
41 |
if not stat.S_ISDIR(st.st_mode): |
42 |
raise KeyError(mycpv) |
43 |
- results = [] |
44 |
+ results = {} |
45 |
+ env_keys = [] |
46 |
for x in wants: |
47 |
if x == "_mtime_": |
48 |
- results.append(st[stat.ST_MTIME]) |
49 |
+ results[x] = st[stat.ST_MTIME] |
50 |
continue |
51 |
try: |
52 |
myf = io.open( |
53 |
@@ -719,35 +719,46 @@ class vardbapi(dbapi): |
54 |
finally: |
55 |
myf.close() |
56 |
except IOError: |
57 |
- myd = None |
58 |
if x not in self._aux_cache_keys and \ |
59 |
self._aux_cache_keys_re.match(x) is None: |
60 |
- myd = self._aux_env_search(mycpv, x) |
61 |
- if myd is None: |
62 |
- myd = _unicode_decode('') |
63 |
+ env_keys.append(x) |
64 |
+ continue |
65 |
+ myd = _unicode_decode('') |
66 |
|
67 |
# Preserve \n for metadata that is known to |
68 |
# contain multiple lines. |
69 |
if self._aux_multi_line_re.match(x) is None: |
70 |
myd = " ".join(myd.split()) |
71 |
|
72 |
- if x == "EAPI" and not myd: |
73 |
- results.append(_unicode_decode('0')) |
74 |
- else: |
75 |
- results.append(myd) |
76 |
+ results[x] = myd |
77 |
+ |
78 |
+ if env_keys: |
79 |
+ env_results = self._aux_env_search(mycpv, env_keys) |
80 |
+ for k in env_keys: |
81 |
+ v = env_results.get(k) |
82 |
+ if v is None: |
83 |
+ v = _unicode_decode('') |
84 |
+ if self._aux_multi_line_re.match(k) is None: |
85 |
+ v = " ".join(v.split()) |
86 |
+ results[k] = v |
87 |
+ |
88 |
+ if results.get("EAPI") == "": |
89 |
+ results["EAPI"] = _unicode_decode('0') |
90 |
+ |
91 |
return results |
92 |
|
93 |
- def _aux_env_search(self, cpv, variable): |
94 |
+ def _aux_env_search(self, cpv, variables): |
95 |
""" |
96 |
- Search environment.bz2 of the specified variable. Returns |
97 |
- the value if found, otherwise None. This is useful for |
98 |
- querying variables like ${SRC_URI} and ${A}, which are not |
99 |
- saved in separate files but are available in environment.bz2 |
100 |
- (see bug #395463). |
101 |
+ Search environment.bz2 for the specified variables. Returns |
102 |
+ a dict mapping variables to values, and any variables not |
103 |
+ found in the environment will not be included in the dict. |
104 |
+ This is useful for querying variables like ${SRC_URI} and |
105 |
+ ${A}, which are not saved in separate files but are available |
106 |
+ in environment.bz2 (see bug #395463). |
107 |
""" |
108 |
env_file = self.getpath(cpv, filename="environment.bz2") |
109 |
if not os.path.isfile(env_file): |
110 |
- return None |
111 |
+ return {} |
112 |
bunzip2_cmd = portage.util.shlex_split( |
113 |
self.settings.get("PORTAGE_BUNZIP2_COMMAND", "")) |
114 |
if not bunzip2_cmd: |
115 |
@@ -771,38 +782,37 @@ class vardbapi(dbapi): |
116 |
return close_quote_match is not None and \ |
117 |
close_quote_match.group(1) == quote |
118 |
|
119 |
- value = None |
120 |
+ variables = frozenset(variables) |
121 |
+ results = {} |
122 |
for line in proc.stdout: |
123 |
line = _unicode_decode(line, |
124 |
encoding=_encodings['content'], errors='replace') |
125 |
var_assign_match = var_assign_re.match(line) |
126 |
if var_assign_match is not None: |
127 |
- if var_assign_match.group(2) == variable: |
128 |
- quote = var_assign_match.group(3) |
129 |
- if quote is not None: |
130 |
- if have_end_quote(quote, |
131 |
- line[var_assign_match.end(2)+2:]): |
132 |
- value = var_assign_match.group(4) |
133 |
- else: |
134 |
- value = [var_assign_match.group(4)] |
135 |
- for line in proc.stdout: |
136 |
- value.append(line) |
137 |
- if have_end_quote(quote, line): |
138 |
- break |
139 |
- value = ''.join(value) |
140 |
- # remove trailing quote and whitespace |
141 |
- value = value.rstrip()[:-1] |
142 |
+ key = var_assign_match.group(2) |
143 |
+ quote = var_assign_match.group(3) |
144 |
+ if quote is not None: |
145 |
+ if have_end_quote(quote, |
146 |
+ line[var_assign_match.end(2)+2:]): |
147 |
+ value = var_assign_match.group(4) |
148 |
else: |
149 |
- value = var_assign_match.group(4).rstrip() |
150 |
+ value = [var_assign_match.group(4)] |
151 |
+ for line in proc.stdout: |
152 |
+ value.append(line) |
153 |
+ if have_end_quote(quote, line): |
154 |
+ break |
155 |
+ value = ''.join(value) |
156 |
+ # remove trailing quote and whitespace |
157 |
+ value = value.rstrip()[:-1] |
158 |
+ else: |
159 |
+ value = var_assign_match.group(4).rstrip() |
160 |
|
161 |
- # ignore remainder of file |
162 |
- for line in proc.stdout: |
163 |
- pass |
164 |
- break |
165 |
+ if key in variables: |
166 |
+ results[key] = value |
167 |
|
168 |
proc.wait() |
169 |
proc.stdout.close() |
170 |
- return value |
171 |
+ return results |
172 |
|
173 |
def aux_update(self, cpv, values): |
174 |
mylink = self._dblink(cpv) |