1 |
Author: grobian |
2 |
Date: 2009-09-29 20:29:30 +0000 (Tue, 29 Sep 2009) |
3 |
New Revision: 14464 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/_emerge/Binpkg.py |
7 |
main/branches/prefix/pym/_emerge/Package.py |
8 |
main/branches/prefix/pym/portage/__init__.py |
9 |
main/branches/prefix/pym/portage/dbapi/bintree.py |
10 |
main/branches/prefix/pym/portage/mail.py |
11 |
main/branches/prefix/pym/portage/xpak.py |
12 |
Log: |
13 |
Merged from trunk -r14455:14463 |
14 |
|
15 |
| 14458 | Bug #286780 - Fix email.MIME* imports to use email.mime.* | |
16 |
| zmedico | (works with python 2.6 and python 3). Thanks to Hanno | |
17 |
| | Meyer-Thurow <h.mth@×××.de> for this patch. | |
18 |
|
19 |
| 14459 | Don't call self.scan() in tbz2.__init__ since all methods | |
20 |
| zmedico | call it anyway. | |
21 |
|
22 |
| 14460 | Make tbz2.get_data() return an empty dict on failure. | |
23 |
| zmedico | | |
24 |
|
25 |
| 14461 | Handle encoding/decoding of unicode when using the xpak api. | |
26 |
| zmedico | Use tbz2.get_data() instead of tbz2.getfile() when reading | |
27 |
| | multiple values, in order to avoid multiple tbz2.scan() and | |
28 |
| | searchindex() calls. | |
29 |
|
30 |
| 14462 | Add back _PackageMetadataWrapper__setitem__, removed in | |
31 |
| zmedico | r14280, since removing it seems to cause problems. Thanks to | |
32 |
| | Jeremy Olexa <darkside@g.o> for reporting, and Marat | |
33 |
| | Radchenko <marat@××××××××××××.org> for bisecting to find the | |
34 |
| | revision. | |
35 |
|
36 |
| 14463 | Revert the rest of r14280 since it seems that dict bypasses | |
37 |
| zmedico | __getitem__ and/or __setitem__ too often. | |
38 |
|
39 |
|
40 |
Modified: main/branches/prefix/pym/_emerge/Binpkg.py |
41 |
=================================================================== |
42 |
--- main/branches/prefix/pym/_emerge/Binpkg.py 2009-09-29 20:00:57 UTC (rev 14463) |
43 |
+++ main/branches/prefix/pym/_emerge/Binpkg.py 2009-09-29 20:29:30 UTC (rev 14464) |
44 |
@@ -222,7 +222,8 @@ |
45 |
check_missing_metadata = ("CATEGORY", "PF") |
46 |
missing_metadata = set() |
47 |
for k in check_missing_metadata: |
48 |
- v = pkg_xpak.getfile(k) |
49 |
+ v = pkg_xpak.getfile(_unicode_encode(k, |
50 |
+ encoding=_encodings['repo.content'])) |
51 |
if not v: |
52 |
missing_metadata.add(k) |
53 |
|
54 |
|
55 |
Modified: main/branches/prefix/pym/_emerge/Package.py |
56 |
=================================================================== |
57 |
--- main/branches/prefix/pym/_emerge/Package.py 2009-09-29 20:00:57 UTC (rev 14463) |
58 |
+++ main/branches/prefix/pym/_emerge/Package.py 2009-09-29 20:29:30 UTC (rev 14464) |
59 |
@@ -6,6 +6,7 @@ |
60 |
import sys |
61 |
from itertools import chain |
62 |
import portage |
63 |
+from portage.cache.mappings import slot_dict_class |
64 |
from portage.dep import paren_reduce, use_reduce, \ |
65 |
paren_normalize, paren_enclose |
66 |
from _emerge.Task import Task |
67 |
@@ -157,54 +158,30 @@ |
68 |
_all_metadata_keys.update(Package.metadata_keys) |
69 |
_all_metadata_keys = frozenset(_all_metadata_keys) |
70 |
|
71 |
-class _PackageMetadataWrapper(dict): |
72 |
+_PackageMetadataWrapperBase = slot_dict_class(_all_metadata_keys) |
73 |
+ |
74 |
+class _PackageMetadataWrapper(_PackageMetadataWrapperBase): |
75 |
""" |
76 |
Detect metadata updates and synchronize Package attributes. |
77 |
""" |
78 |
|
79 |
__slots__ = ("_pkg",) |
80 |
+ _wrapped_keys = frozenset( |
81 |
+ ["COUNTER", "INHERITED", "IUSE", "SLOT", "_mtime_"]) |
82 |
_use_conditional_keys = frozenset( |
83 |
['LICENSE', 'PROPERTIES', 'PROVIDE', 'RESTRICT',]) |
84 |
|
85 |
def __init__(self, pkg, metadata): |
86 |
+ _PackageMetadataWrapperBase.__init__(self) |
87 |
self._pkg = pkg |
88 |
if not pkg.built: |
89 |
# USE is lazy, but we want it to show up in self.keys(). |
90 |
self['USE'] = '' |
91 |
+ |
92 |
self.update(metadata) |
93 |
- for k, v in self.items(): |
94 |
- if k == 'INHERITED': |
95 |
- if isinstance(v, basestring): |
96 |
- v = frozenset(v.split()) |
97 |
- self._pkg.inherited = v |
98 |
- elif k == 'SLOT': |
99 |
- self._pkg.slot = v |
100 |
- elif k == 'IUSE': |
101 |
- self._pkg.iuse = self._pkg._iuse( |
102 |
- v.split(), self._pkg.root_config.iuse_implicit) |
103 |
- elif k == 'COUNTER': |
104 |
- if isinstance(v, basestring): |
105 |
- try: |
106 |
- v = long(v.strip()) |
107 |
- except ValueError: |
108 |
- v = 0 |
109 |
- self['COUNTER'] = str(v) |
110 |
- self._pkg.counter = v |
111 |
- elif k == '_mtime_': |
112 |
- if isinstance(v, basestring): |
113 |
- try: |
114 |
- v = long(v.strip()) |
115 |
- except ValueError: |
116 |
- v = 0 |
117 |
- self._pkg.mtime = v |
118 |
- elif k in self._use_conditional_keys: |
119 |
- try: |
120 |
- use_reduce(paren_reduce(v), matchall=1) |
121 |
- except portage.exception.InvalidDependString as e: |
122 |
- self._pkg._invalid_metadata(k + ".syntax", "%s: %s" % (k, e)) |
123 |
|
124 |
def __getitem__(self, k): |
125 |
- v = dict.__getitem__(self, k) |
126 |
+ v = _PackageMetadataWrapperBase.__getitem__(self, k) |
127 |
if k in self._use_conditional_keys: |
128 |
if self._pkg.root_config.settings.local_config and '?' in v: |
129 |
try: |
130 |
@@ -228,6 +205,44 @@ |
131 |
|
132 |
return v |
133 |
|
134 |
+ def __setitem__(self, k, v): |
135 |
+ _PackageMetadataWrapperBase.__setitem__(self, k, v) |
136 |
+ if k in self._wrapped_keys: |
137 |
+ getattr(self, "_set_" + k.lower())(k, v) |
138 |
+ elif k in self._use_conditional_keys: |
139 |
+ try: |
140 |
+ use_reduce(paren_reduce(v), matchall=1) |
141 |
+ except portage.exception.InvalidDependString, e: |
142 |
+ self._pkg._invalid_metadata(k + ".syntax", "%s: %s" % (k, e)) |
143 |
+ |
144 |
+ def _set_inherited(self, k, v): |
145 |
+ if isinstance(v, basestring): |
146 |
+ v = frozenset(v.split()) |
147 |
+ self._pkg.inherited = v |
148 |
+ |
149 |
+ def _set_iuse(self, k, v): |
150 |
+ self._pkg.iuse = self._pkg._iuse( |
151 |
+ v.split(), self._pkg.root_config.iuse_implicit) |
152 |
+ |
153 |
+ def _set_slot(self, k, v): |
154 |
+ self._pkg.slot = v |
155 |
+ |
156 |
+ def _set_counter(self, k, v): |
157 |
+ if isinstance(v, basestring): |
158 |
+ try: |
159 |
+ v = long(v.strip()) |
160 |
+ except ValueError: |
161 |
+ v = 0 |
162 |
+ self._pkg.counter = v |
163 |
+ |
164 |
+ def _set__mtime_(self, k, v): |
165 |
+ if isinstance(v, basestring): |
166 |
+ try: |
167 |
+ v = long(v.strip()) |
168 |
+ except ValueError: |
169 |
+ v = 0 |
170 |
+ self._pkg.mtime = v |
171 |
+ |
172 |
@property |
173 |
def properties(self): |
174 |
return self['PROPERTIES'].split() |
175 |
|
176 |
Modified: main/branches/prefix/pym/portage/__init__.py |
177 |
=================================================================== |
178 |
--- main/branches/prefix/pym/portage/__init__.py 2009-09-29 20:00:57 UTC (rev 14463) |
179 |
+++ main/branches/prefix/pym/portage/__init__.py 2009-09-29 20:29:30 UTC (rev 14464) |
180 |
@@ -8602,11 +8602,14 @@ |
181 |
|
182 |
mypkg = os.path.basename(mytbz2)[:-5] |
183 |
xptbz2 = portage.xpak.tbz2(mytbz2) |
184 |
- mycat = xptbz2.getfile("CATEGORY") |
185 |
+ mycat = xptbz2.getfile(_unicode_encode("CATEGORY", |
186 |
+ encoding=_encodings['repo.content'])) |
187 |
if not mycat: |
188 |
writemsg(_("!!! CATEGORY info missing from info chunk, aborting...\n"), |
189 |
noiselevel=-1) |
190 |
return 1 |
191 |
+ mycat = _unicode_decode(mycat, |
192 |
+ encoding=_encodings['repo.content'], errors='replace') |
193 |
mycat = mycat.strip() |
194 |
|
195 |
buildprefix = xptbz2.getfile("EPREFIX") |
196 |
|
197 |
Modified: main/branches/prefix/pym/portage/dbapi/bintree.py |
198 |
=================================================================== |
199 |
--- main/branches/prefix/pym/portage/dbapi/bintree.py 2009-09-29 20:00:57 UTC (rev 14463) |
200 |
+++ main/branches/prefix/pym/portage/dbapi/bintree.py 2009-09-29 20:29:30 UTC (rev 14464) |
201 |
@@ -80,9 +80,11 @@ |
202 |
tbz2_path = self.bintree.getname(mycpv) |
203 |
if not os.path.exists(tbz2_path): |
204 |
raise KeyError(mycpv) |
205 |
- tbz2 = portage.xpak.tbz2(tbz2_path) |
206 |
+ metadata_bytes = portage.xpak.tbz2(tbz2_path).get_data() |
207 |
def getitem(k): |
208 |
- v = tbz2.getfile(k) |
209 |
+ v = metadata_bytes.get(_unicode_encode(k, |
210 |
+ encoding=_encodings['repo.content'], |
211 |
+ errors='backslashreplace')) |
212 |
if v is not None: |
213 |
v = _unicode_decode(v, |
214 |
encoding=_encodings['repo.content'], errors='replace') |
215 |
@@ -380,8 +382,12 @@ |
216 |
|
217 |
if st is not None: |
218 |
# For invalid packages, other_cat could be None. |
219 |
- other_cat = portage.xpak.tbz2(dest_path).getfile("CATEGORY") |
220 |
+ other_cat = portage.xpak.tbz2(dest_path).getfile( |
221 |
+ _unicode_encode("CATEGORY", |
222 |
+ encoding=_encodings['repo.content'])) |
223 |
if other_cat: |
224 |
+ other_cat = _unicode_decode(other_cat, |
225 |
+ encoding=_encodings['repo.content'], errors='replace') |
226 |
other_cat = other_cat.strip() |
227 |
other_cpv = other_cat + "/" + mypkg |
228 |
self._move_from_all(other_cpv) |
229 |
@@ -549,11 +555,19 @@ |
230 |
noiselevel=-1) |
231 |
self.invalids.append(myfile[:-5]) |
232 |
continue |
233 |
- mytbz2 = portage.xpak.tbz2(full_path) |
234 |
- # For invalid packages, mycat could be None. |
235 |
- mycat = mytbz2.getfile("CATEGORY") |
236 |
- mypf = mytbz2.getfile("PF") |
237 |
- slot = mytbz2.getfile("SLOT") |
238 |
+ metadata_bytes = portage.xpak.tbz2(full_path).get_data() |
239 |
+ mycat = _unicode_decode(metadata_bytes.get( |
240 |
+ _unicode_encode("CATEGORY", |
241 |
+ encoding=_encodings['repo.content']), ""), |
242 |
+ encoding=_encodings['repo.content'], errors='replace') |
243 |
+ mypf = _unicode_decode(metadata_bytes.get( |
244 |
+ _unicode_encode("PF", |
245 |
+ encoding=_encodings['repo.content']), ""), |
246 |
+ encoding=_encodings['repo.content'], errors='replace') |
247 |
+ slot = _unicode_decode(metadata_bytes.get( |
248 |
+ _unicode_encode("SLOT", |
249 |
+ encoding=_encodings['repo.content']), ""), |
250 |
+ encoding=_encodings['repo.content'], errors='replace') |
251 |
mypkg = myfile[:-5] |
252 |
if not mycat or not mypf or not slot: |
253 |
#old-style or corrupt package |
254 |
|
255 |
Modified: main/branches/prefix/pym/portage/mail.py |
256 |
=================================================================== |
257 |
--- main/branches/prefix/pym/portage/mail.py 2009-09-29 20:00:57 UTC (rev 14463) |
258 |
+++ main/branches/prefix/pym/portage/mail.py 2009-09-29 20:29:30 UTC (rev 14464) |
259 |
@@ -3,9 +3,9 @@ |
260 |
# Distributed under the terms of the GNU General Public License v2 |
261 |
# $Id$ |
262 |
|
263 |
-from email.MIMEText import MIMEText as TextMessage |
264 |
-from email.MIMEMultipart import MIMEMultipart as MultipartMessage |
265 |
-from email.MIMEBase import MIMEBase as BaseMessage |
266 |
+from email.mime.text import MIMEText as TextMessage |
267 |
+from email.mime.multipart import MIMEMultipart as MultipartMessage |
268 |
+from email.mime.base import MIMEBase as BaseMessage |
269 |
from email.header import Header |
270 |
import smtplib |
271 |
import socket |
272 |
|
273 |
Modified: main/branches/prefix/pym/portage/xpak.py |
274 |
=================================================================== |
275 |
--- main/branches/prefix/pym/portage/xpak.py 2009-09-29 20:00:57 UTC (rev 14463) |
276 |
+++ main/branches/prefix/pym/portage/xpak.py 2009-09-29 20:29:30 UTC (rev 14464) |
277 |
@@ -272,7 +272,6 @@ |
278 |
self.datasize=None |
279 |
self.indexpos=None |
280 |
self.datapos=None |
281 |
- self.scan() |
282 |
|
283 |
def decompose(self,datadir,cleanup=1): |
284 |
"""Alias for unpackinfo() --- Complement to recompose() but optionally |
285 |
@@ -437,7 +436,7 @@ |
286 |
def get_data(self): |
287 |
"""Returns all the files from the dataSegment as a map object.""" |
288 |
if not self.scan(): |
289 |
- return 0 |
290 |
+ return {} |
291 |
a = open(_unicode_encode(self.file, |
292 |
encoding=_encodings['fs'], errors='strict'), 'rb') |
293 |
mydata = {} |