1 |
Author: grobian |
2 |
Date: 2009-09-26 18:44:55 +0000 (Sat, 26 Sep 2009) |
3 |
New Revision: 14437 |
4 |
|
5 |
Added: |
6 |
main/branches/prefix/pym/portage/tests/ebuild/test_pty_eof.py |
7 |
Modified: |
8 |
main/branches/prefix/bin/dispatch-conf |
9 |
main/branches/prefix/bin/emaint |
10 |
main/branches/prefix/bin/regenworld |
11 |
main/branches/prefix/pym/portage/__init__.py |
12 |
main/branches/prefix/pym/portage/cache/flat_hash.py |
13 |
main/branches/prefix/pym/portage/dbapi/porttree.py |
14 |
main/branches/prefix/pym/portage/dbapi/vartree.py |
15 |
main/branches/prefix/pym/portage/glsa.py |
16 |
main/branches/prefix/pym/portage/tests/__init__.py |
17 |
main/branches/prefix/pym/portage/update.py |
18 |
main/branches/prefix/pym/portage/util.py |
19 |
main/branches/prefix/pym/repoman/utilities.py |
20 |
Log: |
21 |
Merged from trunk -r14412:14422 |
22 |
|
23 |
| 14413 | Use a runtime check to see if | |
24 |
| zmedico | http://bugs.python.org/issue5380 is fixed. | |
25 |
|
26 |
| 14414 | Make _test_pty_eof() return None if openpty() fails. | |
27 |
| zmedico | | |
28 |
|
29 |
| 14415 | Add a test case for http://bugs.python.org/issue5380 and | |
30 |
| zmedico | mark it as 'todo' since it fails with current versions of | |
31 |
| | python 3. | |
32 |
|
33 |
| 14416 | Fix regression in _getitem() from r14398, since | |
34 |
| zmedico | myf.read().split("\n") yields an empty string at the end | |
35 |
| | which is causes _parse_data() to catch a ValueError and | |
36 |
| | raise CacheCorruption. | |
37 |
|
38 |
| 14417 | Show an appropriate error message in _create_pty_or_pipe() | |
39 |
| zmedico | if openpty() fails inside _test_pty_eof(). | |
40 |
|
41 |
| 14418 | Remove unnecessary dict.has_key() call (fix for python 3). | |
42 |
| zmedico | | |
43 |
|
44 |
| 14419 | Fix ValueError in digestcheck(), reported by Arfrever. | |
45 |
| zmedico | | |
46 |
|
47 |
| 14420 | Fix more. | |
48 |
| zmedico | | |
49 |
|
50 |
| 14421 | Use list comprehensions instead of filter() or map() in | |
51 |
| arfrever | some places for compatibility with Python 3. | |
52 |
|
53 |
| 14422 | Use 'in' instead of has_key() in portage.glsa.Glsa.parse() | |
54 |
| arfrever | when Python 3 is used. | |
55 |
|
56 |
|
57 |
Modified: main/branches/prefix/bin/dispatch-conf |
58 |
=================================================================== |
59 |
--- main/branches/prefix/bin/dispatch-conf 2009-09-26 18:43:40 UTC (rev 14436) |
60 |
+++ main/branches/prefix/bin/dispatch-conf 2009-09-26 18:44:55 UTC (rev 14437) |
61 |
@@ -207,7 +207,7 @@ |
62 |
else: |
63 |
return True |
64 |
|
65 |
- confs = filter (f, confs) |
66 |
+ confs = [x for x in confs if f(x)] |
67 |
|
68 |
# |
69 |
# Interactively process remaining |
70 |
|
71 |
Modified: main/branches/prefix/bin/emaint |
72 |
=================================================================== |
73 |
--- main/branches/prefix/bin/emaint 2009-09-26 18:43:40 UTC (rev 14436) |
74 |
+++ main/branches/prefix/bin/emaint 2009-09-26 18:44:55 UTC (rev 14437) |
75 |
@@ -82,9 +82,9 @@ |
76 |
self._check_world(onProgress) |
77 |
errors = [] |
78 |
if self.found: |
79 |
- errors += map(lambda x: "'%s' is not a valid atom" % x, self.invalid) |
80 |
- errors += map(lambda x: "'%s' is not installed" % x, self.not_installed) |
81 |
- errors += map(lambda x: "'%s' has a category that is not listed in /etc/portage/categories" % x, self.invalid_category) |
82 |
+ errors += ["'%s' is not a valid atom" % x for x in self.invalid] |
83 |
+ errors += ["'%s' is not installed" % x for x in self.not_installed] |
84 |
+ errors += ["'%s' has a category that is not listed in /etc/portage/categories" % x for x in self.invalid_category] |
85 |
else: |
86 |
errors.append(self.world_file + " could not be opened for reading") |
87 |
return errors |
88 |
|
89 |
Modified: main/branches/prefix/bin/regenworld |
90 |
=================================================================== |
91 |
--- main/branches/prefix/bin/regenworld 2009-09-26 18:43:40 UTC (rev 14436) |
92 |
+++ main/branches/prefix/bin/regenworld 2009-09-26 18:44:55 UTC (rev 14437) |
93 |
@@ -59,18 +59,16 @@ |
94 |
sys.exit(0) |
95 |
|
96 |
worldlist = portage.grabfile(os.path.join(portage.const.EPREFIX, portage.WORLD_FILE)) |
97 |
-syslist = portage.settings.packages |
98 |
-syslist = filter(issyspkg, syslist) |
99 |
+syslist = [x for x in portage.settings.packages if issyspkg(x)] |
100 |
|
101 |
logfile = portage.grabfile(portage.const.EPREFIX+"/var/log/emerge.log") |
102 |
-biglist = filter(iscandidate, logfile) |
103 |
-biglist = map(getpkginfo, biglist) |
104 |
+biglist = [getpkginfo(x) for x in logfile if iscandidate(x)] |
105 |
tmplist = [] |
106 |
for l in biglist: |
107 |
tmplist += l.split() |
108 |
-biglist = filter(isunwanted, tmplist) |
109 |
+biglist = [x for x in tmplist if isunwanted(x)] |
110 |
#for p in biglist: |
111 |
-# print p |
112 |
+# print(p) |
113 |
#sys.exit(0) |
114 |
|
115 |
# resolving virtuals |
116 |
@@ -78,7 +76,7 @@ |
117 |
for mykey in syslist: |
118 |
# drop the asterix |
119 |
mykey = mykey[1:] |
120 |
- #print "candidate:",mykey |
121 |
+ #print("candidate:",mykey) |
122 |
mylist=portage.db["/"]["vartree"].dbapi.match(mykey) |
123 |
if mylist: |
124 |
mykey=portage.cpv_getkey(mylist[0]) |
125 |
@@ -86,7 +84,7 @@ |
126 |
realsyslist.append(mykey) |
127 |
|
128 |
for mykey in biglist: |
129 |
- #print "checking:",mykey |
130 |
+ #print("checking:",mykey) |
131 |
try: |
132 |
mylist=portage.db["/"]["vartree"].dbapi.match(mykey) |
133 |
except (portage.exception.InvalidAtom, KeyError): |
134 |
|
135 |
Modified: main/branches/prefix/pym/portage/__init__.py |
136 |
=================================================================== |
137 |
--- main/branches/prefix/pym/portage/__init__.py 2009-09-26 18:43:40 UTC (rev 14436) |
138 |
+++ main/branches/prefix/pym/portage/__init__.py 2009-09-26 18:44:55 UTC (rev 14437) |
139 |
@@ -3755,6 +3755,60 @@ |
140 |
keys = __iter__ |
141 |
items = iteritems |
142 |
|
143 |
+def _test_pty_eof(): |
144 |
+ """ |
145 |
+ Returns True if this issues is fixed for the currently |
146 |
+ running version of python: http://bugs.python.org/issue5380 |
147 |
+ Raises an EnvironmentError from openpty() if it fails. |
148 |
+ """ |
149 |
+ |
150 |
+ import array, pty, termios |
151 |
+ test_string = 2 * "blah blah blah\n" |
152 |
+ test_string = _unicode_decode(test_string, |
153 |
+ encoding='utf_8', errors='strict') |
154 |
+ |
155 |
+ # may raise EnvironmentError |
156 |
+ master_fd, slave_fd = pty.openpty() |
157 |
+ |
158 |
+ master_file = os.fdopen(master_fd, 'rb') |
159 |
+ slave_file = os.fdopen(slave_fd, 'wb') |
160 |
+ |
161 |
+ # Disable post-processing of output since otherwise weird |
162 |
+ # things like \n -> \r\n transformations may occur. |
163 |
+ mode = termios.tcgetattr(slave_fd) |
164 |
+ mode[1] &= ~termios.OPOST |
165 |
+ termios.tcsetattr(slave_fd, termios.TCSANOW, mode) |
166 |
+ |
167 |
+ # Simulate a subprocess writing some data to the |
168 |
+ # slave end of the pipe, and then exiting. |
169 |
+ slave_file.write(_unicode_encode(test_string, |
170 |
+ encoding='utf_8', errors='strict')) |
171 |
+ slave_file.close() |
172 |
+ |
173 |
+ eof = False |
174 |
+ data = [] |
175 |
+ |
176 |
+ while not eof: |
177 |
+ |
178 |
+ buf = array.array('B') |
179 |
+ try: |
180 |
+ buf.fromfile(master_file, 1024) |
181 |
+ except EOFError: |
182 |
+ eof = True |
183 |
+ except IOError: |
184 |
+ # This is where data loss occurs. |
185 |
+ eof = True |
186 |
+ |
187 |
+ if not buf: |
188 |
+ eof = True |
189 |
+ else: |
190 |
+ data.append(_unicode_decode(buf.tostring(), |
191 |
+ encoding='utf_8', errors='strict')) |
192 |
+ |
193 |
+ master_file.close() |
194 |
+ |
195 |
+ return test_string == ''.join(data) |
196 |
+ |
197 |
# In some cases, openpty can be slow when it fails. Therefore, |
198 |
# stop trying to use it after the first failure. |
199 |
if platform.system() in ["SunOS"]: |
200 |
@@ -3764,11 +3818,8 @@ |
201 |
_disable_openpty = True |
202 |
else: |
203 |
_disable_openpty = False |
204 |
+_tested_pty = False |
205 |
|
206 |
-if sys.hexversion >= 0x3000000: |
207 |
- # This is a temporary workaround for http://bugs.python.org/issue5380. |
208 |
- _disable_openpty = True |
209 |
- |
210 |
def _create_pty_or_pipe(copy_term_size=None): |
211 |
""" |
212 |
Try to create a pty and if then fails then create a normal |
213 |
@@ -3785,7 +3836,18 @@ |
214 |
|
215 |
got_pty = False |
216 |
|
217 |
- global _disable_openpty |
218 |
+ global _disable_openpty, _tested_pty |
219 |
+ if not (_tested_pty or _disable_openpty): |
220 |
+ try: |
221 |
+ if not _test_pty_eof(): |
222 |
+ _disable_openpty = True |
223 |
+ except EnvironmentError as e: |
224 |
+ _disable_openpty = True |
225 |
+ writemsg("openpty failed: '%s'\n" % str(e), |
226 |
+ noiselevel=-1) |
227 |
+ del e |
228 |
+ _tested_pty = True |
229 |
+ |
230 |
if _disable_openpty: |
231 |
master_fd, slave_fd = os.pipe() |
232 |
else: |
233 |
@@ -5379,6 +5441,7 @@ |
234 |
return 0 |
235 |
continue |
236 |
for d in dirs: |
237 |
+ d_bytes = d |
238 |
try: |
239 |
d = _unicode_decode(d, |
240 |
encoding=_encodings['fs'], errors='strict') |
241 |
@@ -5391,10 +5454,10 @@ |
242 |
noiselevel=-1) |
243 |
if strict: |
244 |
return 0 |
245 |
- dirs.remove(d) |
246 |
+ dirs.remove(d_bytes) |
247 |
continue |
248 |
if d.startswith(".") or d == "CVS": |
249 |
- dirs.remove(d) |
250 |
+ dirs.remove(d_bytes) |
251 |
for f in files: |
252 |
try: |
253 |
f = _unicode_decode(f, |
254 |
|
255 |
Modified: main/branches/prefix/pym/portage/cache/flat_hash.py |
256 |
=================================================================== |
257 |
--- main/branches/prefix/pym/portage/cache/flat_hash.py 2009-09-26 18:43:40 UTC (rev 14436) |
258 |
+++ main/branches/prefix/pym/portage/cache/flat_hash.py 2009-09-26 18:44:55 UTC (rev 14437) |
259 |
@@ -41,7 +41,10 @@ |
260 |
mode='r', encoding=_encodings['repo.content'], |
261 |
errors='replace') |
262 |
try: |
263 |
- d = self._parse_data(myf.read().split("\n"), cpv) |
264 |
+ lines = myf.read().split("\n") |
265 |
+ if not lines[-1]: |
266 |
+ lines.pop() |
267 |
+ d = self._parse_data(lines, cpv) |
268 |
if '_mtime_' not in d: |
269 |
# Backward compatibility with old cache |
270 |
# that uses mtime mangling. |
271 |
|
272 |
Modified: main/branches/prefix/pym/portage/dbapi/porttree.py |
273 |
=================================================================== |
274 |
--- main/branches/prefix/pym/portage/dbapi/porttree.py 2009-09-26 18:43:40 UTC (rev 14436) |
275 |
+++ main/branches/prefix/pym/portage/dbapi/porttree.py 2009-09-26 18:44:55 UTC (rev 14437) |
276 |
@@ -342,7 +342,7 @@ |
277 |
|
278 |
# XXX: REMOVE THIS ONCE UNUSED_0 IS YANKED FROM auxdbkeys |
279 |
# ~harring |
280 |
- filtered_auxdbkeys = list(filter(lambda x: not x.startswith("UNUSED_0"), auxdbkeys)) |
281 |
+ filtered_auxdbkeys = [x for x in auxdbkeys if not x.startswith("UNUSED_0")] |
282 |
filtered_auxdbkeys.sort() |
283 |
from portage.cache import metadata_overlay, volatile |
284 |
if not depcachedir_w_ok: |
285 |
|
286 |
Modified: main/branches/prefix/pym/portage/dbapi/vartree.py |
287 |
=================================================================== |
288 |
--- main/branches/prefix/pym/portage/dbapi/vartree.py 2009-09-26 18:43:40 UTC (rev 14436) |
289 |
+++ main/branches/prefix/pym/portage/dbapi/vartree.py 2009-09-26 18:44:55 UTC (rev 14437) |
290 |
@@ -388,7 +388,7 @@ |
291 |
for x in filter(None, fields[3].replace( |
292 |
"${ORIGIN}", os.path.dirname(obj)).replace( |
293 |
"$ORIGIN", os.path.dirname(obj)).split(":"))]) |
294 |
- needed = filter(None, fields[4].split(",")) |
295 |
+ needed = [x for x in fields[4].split(",") if x] |
296 |
|
297 |
obj_key = self._obj_key(obj) |
298 |
indexed = True |
299 |
|
300 |
Modified: main/branches/prefix/pym/portage/glsa.py |
301 |
=================================================================== |
302 |
--- main/branches/prefix/pym/portage/glsa.py 2009-09-26 18:43:40 UTC (rev 14436) |
303 |
+++ main/branches/prefix/pym/portage/glsa.py 2009-09-26 18:44:55 UTC (rev 14437) |
304 |
@@ -511,7 +511,8 @@ |
305 |
# <revised count="2">2007-12-30</revised> |
306 |
revisedEl = myroot.getElementsByTagName("revised")[0] |
307 |
self.revised = getText(revisedEl, format="strip") |
308 |
- if (revisedEl.attributes.has_key("count")): |
309 |
+ if ((sys.hexversion >= 0x3000000 and "count" in revisedEl.attributes) or |
310 |
+ (sys.hexversion < 0x3000000 and revisedEl.attributes.has_key("count"))): |
311 |
count = revisedEl.getAttribute("count") |
312 |
elif (self.revised.find(":") >= 0): |
313 |
(self.revised, count) = self.revised.split(":") |
314 |
|
315 |
Modified: main/branches/prefix/pym/portage/tests/__init__.py |
316 |
=================================================================== |
317 |
--- main/branches/prefix/pym/portage/tests/__init__.py 2009-09-26 18:43:40 UTC (rev 14436) |
318 |
+++ main/branches/prefix/pym/portage/tests/__init__.py 2009-09-26 18:44:55 UTC (rev 14437) |
319 |
@@ -176,7 +176,8 @@ |
320 |
self.stream.writeln() |
321 |
if not result.wasSuccessful(): |
322 |
self.stream.write("FAILED (") |
323 |
- failed, errored = map(len, (result.failures, result.errors)) |
324 |
+ failed = len(result.failures) |
325 |
+ errored = len(result.errors) |
326 |
if failed: |
327 |
self.stream.write("failures=%d" % failed) |
328 |
if errored: |
329 |
|
330 |
Copied: main/branches/prefix/pym/portage/tests/ebuild/test_pty_eof.py (from rev 14422, main/trunk/pym/portage/tests/ebuild/test_pty_eof.py) |
331 |
=================================================================== |
332 |
--- main/branches/prefix/pym/portage/tests/ebuild/test_pty_eof.py (rev 0) |
333 |
+++ main/branches/prefix/pym/portage/tests/ebuild/test_pty_eof.py 2009-09-26 18:44:55 UTC (rev 14437) |
334 |
@@ -0,0 +1,22 @@ |
335 |
+# Copyright 1998-2007 Gentoo Foundation |
336 |
+# Distributed under the terms of the GNU General Public License v2 |
337 |
+# $Id$ |
338 |
+ |
339 |
+import pty |
340 |
+ |
341 |
+import portage |
342 |
+from portage import os |
343 |
+from portage.tests import TestCase |
344 |
+ |
345 |
+class PtyEofTestCase(TestCase): |
346 |
+ |
347 |
+ def testPtyEof(self): |
348 |
+ # This tests if the following python issue is fixed yet: |
349 |
+ # http://bugs.python.org/issue5380 |
350 |
+ # Since it might not be fixed, mark as todo. |
351 |
+ self.todo = True |
352 |
+ # The result is only valid if openpty does not raise EnvironmentError. |
353 |
+ try: |
354 |
+ self.assertEqual(portage._test_pty_eof(), True) |
355 |
+ except EnvironmentError: |
356 |
+ pass |
357 |
|
358 |
Modified: main/branches/prefix/pym/portage/update.py |
359 |
=================================================================== |
360 |
--- main/branches/prefix/pym/portage/update.py 2009-09-26 18:43:40 UTC (rev 14436) |
361 |
+++ main/branches/prefix/pym/portage/update.py 2009-09-26 18:44:55 UTC (rev 14437) |
362 |
@@ -227,8 +227,6 @@ |
363 |
mode='r', encoding=_encodings['content'], |
364 |
errors='replace').readlines() |
365 |
except IOError: |
366 |
- if file_contents.has_key(x): |
367 |
- del file_contents[x] |
368 |
continue |
369 |
|
370 |
# update /etc/portage/packages.* |
371 |
|
372 |
Modified: main/branches/prefix/pym/portage/util.py |
373 |
=================================================================== |
374 |
--- main/branches/prefix/pym/portage/util.py 2009-09-26 18:43:40 UTC (rev 14436) |
375 |
+++ main/branches/prefix/pym/portage/util.py 2009-09-26 18:44:55 UTC (rev 14437) |
376 |
@@ -151,7 +151,7 @@ |
377 |
new_dl = {} |
378 |
for key in myDict: |
379 |
new_dl[key] = [] |
380 |
- new_dl[key] = map(func,myDict[key]) |
381 |
+ new_dl[key] = [func(x) for x in myDict[key]] |
382 |
return new_dl |
383 |
|
384 |
def stack_dictlist(original_dicts, incremental=0, incrementals=[], ignore_none=0): |
385 |
|
386 |
Modified: main/branches/prefix/pym/repoman/utilities.py |
387 |
=================================================================== |
388 |
--- main/branches/prefix/pym/repoman/utilities.py 2009-09-26 18:43:40 UTC (rev 14436) |
389 |
+++ main/branches/prefix/pym/repoman/utilities.py 2009-09-26 18:44:55 UTC (rev 14437) |
390 |
@@ -346,7 +346,7 @@ |
391 |
Args: |
392 |
settings - portage.config instance, preferably repoman_settings |
393 |
Returns: |
394 |
- tuple(portdir, portdir_overlay, location) |
395 |
+ list(portdir, portdir_overlay, location) |
396 |
""" |
397 |
|
398 |
portdir = None |
399 |
@@ -430,4 +430,4 @@ |
400 |
if not portdir.endswith('/'): |
401 |
portdir += '/' |
402 |
|
403 |
- return map(normalize_path, (portdir, portdir_overlay, location)) |
404 |
+ return [normalize_path(x) for x in (portdir, portdir_overlay, location)] |