1 |
Author: grobian |
2 |
Date: 2009-08-24 09:31:55 +0000 (Mon, 24 Aug 2009) |
3 |
New Revision: 14139 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/portage/__init__.py |
7 |
main/branches/prefix/pym/portage/_selinux.py |
8 |
main/branches/prefix/pym/portage/dispatch_conf.py |
9 |
main/branches/prefix/pym/portage/locks.py |
10 |
main/branches/prefix/pym/portage/news.py |
11 |
main/branches/prefix/pym/portage/output.py |
12 |
main/branches/prefix/pym/portage/tests/bin/setup_env.py |
13 |
main/branches/prefix/pym/portage/tests/ebuild/test_spawn.py |
14 |
main/branches/prefix/pym/portage/tests/env/config/test_PackageKeywordsFile.py |
15 |
main/branches/prefix/pym/portage/tests/env/config/test_PackageMaskFile.py |
16 |
main/branches/prefix/pym/portage/tests/env/config/test_PackageUseFile.py |
17 |
main/branches/prefix/pym/portage/tests/env/config/test_PortageModulesFile.py |
18 |
main/branches/prefix/pym/portage/tests/news/test_NewsItem.py |
19 |
main/branches/prefix/pym/portage/tests/process/test_poll.py |
20 |
main/branches/prefix/pym/portage/tests/sets/files/testConfigFileSet.py |
21 |
main/branches/prefix/pym/portage/tests/sets/files/testStaticFileSet.py |
22 |
main/branches/prefix/pym/portage/tests/util/test_uniqueArray.py |
23 |
Log: |
24 |
Merged from trunk -r14077:14087 |
25 |
|
26 |
| 14078 | Use portage.os, _content_encoding, and _fs_encoding where | |
27 |
| zmedico | appropriate. | |
28 |
|
29 |
| 14079 | Enable error='strict' when encoding arguments inside | |
30 |
| zmedico | _unicode_func_wrapper(), and document behavior. | |
31 |
|
32 |
| 14080 | Use portage.os, _content_encoding, and _fs_encoding where | |
33 |
| zmedico | appropriate. | |
34 |
|
35 |
| 14081 | Bug #277619 - Fix news item relevance logic. Thanks to Alec | |
36 |
| zmedico | Warner <antarus@g.o> for this patch. | |
37 |
|
38 |
| 14082 | Use st_* attributes instead of the stat module. | |
39 |
| zmedico | | |
40 |
|
41 |
| 14083 | Implement lazy loading of color.map when either the codes or | |
42 |
| zmedico | _styles attribute is accessed. This provides and | |
43 |
| | _init(config_root='/') function that the prefix branch can | |
44 |
| | use to substitute an appropriate config_root value at | |
45 |
| | runtime. | |
46 |
|
47 |
| 14084 | Use _content_encoding and _fs_encoding where appropriate. | |
48 |
| zmedico | | |
49 |
|
50 |
| 14085 | Use _content_encoding and _fs_encoding where appropriate. | |
51 |
| zmedico | Also, enable strict exceptions for unicode encoding | |
52 |
| | failures. | |
53 |
|
54 |
| 14086 | Bug #270866 - Validate News-Item-Format headers. | |
55 |
| zmedico | | |
56 |
|
57 |
| 14087 | Don't wrap os.popen(). | |
58 |
| zmedico | | |
59 |
|
60 |
|
61 |
Modified: main/branches/prefix/pym/portage/__init__.py |
62 |
=================================================================== |
63 |
--- main/branches/prefix/pym/portage/__init__.py 2009-08-24 09:28:51 UTC (rev 14138) |
64 |
+++ main/branches/prefix/pym/portage/__init__.py 2009-08-24 09:31:55 UTC (rev 14139) |
65 |
@@ -145,7 +145,13 @@ |
66 |
class _unicode_func_wrapper(object): |
67 |
""" |
68 |
Wraps a function, converts arguments from unicode to bytes, |
69 |
- and return values to unicode from bytes. |
70 |
+ and return values to unicode from bytes. Function calls |
71 |
+ will raise UnicodeEncodeError if an argument fails to be |
72 |
+ encoded with the required encoding. Return values that |
73 |
+ are single strings are decoded with errors='replace'. Return |
74 |
+ values that are lists of strings are decoded with errors='strict' |
75 |
+ and elements that fail to be decoded are omitted from the returned |
76 |
+ list. |
77 |
""" |
78 |
__slots__ = ('_func', '_encoding') |
79 |
|
80 |
@@ -156,10 +162,12 @@ |
81 |
def __call__(self, *args, **kwargs): |
82 |
|
83 |
encoding = self._encoding |
84 |
- wrapped_args = [_unicode_encode(x) for x in args] |
85 |
+ wrapped_args = [_unicode_encode(x, encoding=encoding, errors='strict') |
86 |
+ for x in args] |
87 |
if kwargs: |
88 |
- wrapped_kwargs = dict((_unicode_encode(k, encoding=encoding), |
89 |
- _unicode_encode(v, encoding=encoding)) \ |
90 |
+ wrapped_kwargs = dict( |
91 |
+ (_unicode_encode(k, encoding=encoding, errors='strict'), |
92 |
+ _unicode_encode(v, encoding=encoding, errors='strict')) |
93 |
for k, v in kwargs.iteritems()) |
94 |
else: |
95 |
wrapped_kwargs = {} |
96 |
@@ -168,7 +176,8 @@ |
97 |
|
98 |
if isinstance(rval, (basestring, list, tuple)): |
99 |
if isinstance(rval, basestring): |
100 |
- rval = _unicode_decode(rval, encoding=encoding) |
101 |
+ rval = _unicode_decode(rval, |
102 |
+ encoding=encoding, errors='replace') |
103 |
else: |
104 |
decoded_rval = [] |
105 |
for x in rval: |
106 |
@@ -218,6 +227,7 @@ |
107 |
import os as _os |
108 |
_os_overrides = { |
109 |
id(_os.fdopen) : _os.fdopen, |
110 |
+ id(_os.popen) : _os.popen, |
111 |
id(_os.read) : _os.read, |
112 |
id(_os.system) : _os.system, |
113 |
} |
114 |
|
115 |
Modified: main/branches/prefix/pym/portage/_selinux.py |
116 |
=================================================================== |
117 |
--- main/branches/prefix/pym/portage/_selinux.py 2009-08-24 09:28:51 UTC (rev 14138) |
118 |
+++ main/branches/prefix/pym/portage/_selinux.py 2009-08-24 09:31:55 UTC (rev 14139) |
119 |
@@ -7,15 +7,17 @@ |
120 |
import os |
121 |
import shutil |
122 |
|
123 |
-import portage |
124 |
+from portage import _content_encoding |
125 |
+from portage import _fs_encoding |
126 |
+from portage import _unicode_encode |
127 |
from portage.localization import _ |
128 |
|
129 |
import selinux |
130 |
-from selinux import is_selinux_enabled, getfilecon, lgetfilecon |
131 |
+from selinux import is_selinux_enabled |
132 |
|
133 |
def copyfile(src, dest): |
134 |
- src = portage._unicode_encode(src) |
135 |
- dest = portage._unicode_encode(dest) |
136 |
+ src = _unicode_encode(src, encoding=_fs_encoding, errors='strict') |
137 |
+ dest = _unicode_encode(dest, encoding=_fs_encoding, errors='strict') |
138 |
(rc, ctx) = selinux.lgetfilecon(src) |
139 |
if rc < 0: |
140 |
raise OSError(_("copyfile: Failed getting context of \"%s\".") % src) |
141 |
@@ -34,23 +36,23 @@ |
142 |
return ctx |
143 |
|
144 |
def mkdir(target, refdir): |
145 |
- target = portage._unicode_encode(target) |
146 |
- refdir = portage._unicode_encode(refdir) |
147 |
+ target = _unicode_encode(target, encoding=_fs_encoding, errors='strict') |
148 |
+ refdir = _unicode_encode(refdir, encoding=_fs_encoding, errors='strict') |
149 |
(rc, ctx) = selinux.getfilecon(refdir) |
150 |
if rc < 0: |
151 |
raise OSError( |
152 |
_("mkdir: Failed getting context of reference directory \"%s\".") \ |
153 |
% refdir) |
154 |
|
155 |
- setfscreatecon(ctx) |
156 |
+ selinux.setfscreatecon(ctx) |
157 |
try: |
158 |
os.mkdir(target) |
159 |
finally: |
160 |
- setfscreatecon() |
161 |
+ selinux.setfscreatecon() |
162 |
|
163 |
def rename(src, dest): |
164 |
- src = portage._unicode_encode(src) |
165 |
- dest = portage._unicode_encode(dest) |
166 |
+ src = _unicode_encode(src, encoding=_fs_encoding, errors='strict') |
167 |
+ dest = _unicode_encode(dest, encoding=_fs_encoding, errors='strict') |
168 |
(rc, ctx) = selinux.lgetfilecon(src) |
169 |
if rc < 0: |
170 |
raise OSError(_("rename: Failed getting context of \"%s\".") % src) |
171 |
@@ -67,21 +69,23 @@ |
172 |
return ":".join(ret) |
173 |
|
174 |
def setexec(ctx="\n"): |
175 |
- if isinstance(ctx, unicode): |
176 |
- ctx = ctx.encode('utf_8', 'replace') |
177 |
+ ctx = _unicode_encode(ctx, encoding=_content_encoding, errors='strict') |
178 |
if selinux.setexeccon(ctx) < 0: |
179 |
raise OSError(_("setexec: Failed setting exec() context \"%s\".") % ctx) |
180 |
|
181 |
def setfscreate(ctx="\n"): |
182 |
- ctx = portage._unicode_encode(ctx) |
183 |
+ ctx = _unicode_encode(ctx, |
184 |
+ encoding=_content_encoding, errors='strict') |
185 |
if selinux.setfscreatecon(ctx) < 0: |
186 |
raise OSError( |
187 |
_("setfscreate: Failed setting fs create context \"%s\".") % ctx) |
188 |
|
189 |
def spawn_wrapper(spawn_func, selinux_type): |
190 |
|
191 |
+ selinux_type = _unicode_encode(selinux_type, |
192 |
+ encoding=_content_encoding, errors='strict') |
193 |
+ |
194 |
def wrapper_func(*args, **kwargs): |
195 |
- selinux_type = portage._unicode_encode(selinux_type) |
196 |
con = settype(selinux_type) |
197 |
setexec(con) |
198 |
try: |
199 |
@@ -92,9 +96,9 @@ |
200 |
return wrapper_func |
201 |
|
202 |
def symlink(target, link, reflnk): |
203 |
- target = portage._unicode_encode(target) |
204 |
- link = portage._unicode_encode(link) |
205 |
- reflnk = portage._unicode_encode(reflnk) |
206 |
+ target = _unicode_encode(target, encoding=_fs_encoding, errors='strict') |
207 |
+ link = _unicode_encode(link, encoding=_fs_encoding, errors='strict') |
208 |
+ reflnk = _unicode_encode(reflnk, encoding=_fs_encoding, errors='strict') |
209 |
(rc, ctx) = selinux.lgetfilecon(reflnk) |
210 |
if rc < 0: |
211 |
raise OSError( |
212 |
|
213 |
Modified: main/branches/prefix/pym/portage/dispatch_conf.py |
214 |
=================================================================== |
215 |
--- main/branches/prefix/pym/portage/dispatch_conf.py 2009-08-24 09:28:51 UTC (rev 14138) |
216 |
+++ main/branches/prefix/pym/portage/dispatch_conf.py 2009-08-24 09:31:55 UTC (rev 14139) |
217 |
@@ -7,7 +7,6 @@ |
218 |
# Library by Wayne Davison <gentoo@×××××.net>, derived from code |
219 |
# written by Jeremy Wohl (http://igmus.org) |
220 |
|
221 |
-from stat import * |
222 |
import os, sys, commands, shutil |
223 |
|
224 |
import portage, portage.const |
225 |
@@ -86,8 +85,8 @@ |
226 |
# This puts the results of the merge into mrgconf. |
227 |
ret = os.system(RCS_MERGE % (archive, mrgconf)) |
228 |
mystat = os.lstat(newconf) |
229 |
- os.chmod(mrgconf, mystat[ST_MODE]) |
230 |
- os.chown(mrgconf, mystat[ST_UID], mystat[ST_GID]) |
231 |
+ os.chmod(mrgconf, mystat.st_mode) |
232 |
+ os.chown(mrgconf, mystat.st_uid, mystat.st_gid) |
233 |
os.rename(archive, archive + '.dist.new') |
234 |
return ret |
235 |
|
236 |
@@ -137,8 +136,8 @@ |
237 |
# This puts the results of the merge into mrgconf. |
238 |
ret = os.system(DIFF3_MERGE % (curconf, archive + '.dist', newconf, mrgconf)) |
239 |
mystat = os.lstat(newconf) |
240 |
- os.chmod(mrgconf, mystat[ST_MODE]) |
241 |
- os.chown(mrgconf, mystat[ST_UID], mystat[ST_GID]) |
242 |
+ os.chmod(mrgconf, mystat.st_mode) |
243 |
+ os.chown(mrgconf, mystat.st_uid, mystat.st_gid) |
244 |
|
245 |
return ret |
246 |
|
247 |
|
248 |
Modified: main/branches/prefix/pym/portage/locks.py |
249 |
=================================================================== |
250 |
--- main/branches/prefix/pym/portage/locks.py 2009-08-24 09:28:51 UTC (rev 14138) |
251 |
+++ main/branches/prefix/pym/portage/locks.py 2009-08-24 09:31:55 UTC (rev 14139) |
252 |
@@ -7,7 +7,10 @@ |
253 |
"hardlock_name", "hardlink_is_mine", "hardlink_lockfile", \ |
254 |
"unhardlink_lockfile", "hardlock_cleanup"] |
255 |
|
256 |
-import errno, os, stat, time |
257 |
+import errno |
258 |
+import stat |
259 |
+import time |
260 |
+from portage import os |
261 |
from portage.exception import DirectoryNotFound, FileNotFound, \ |
262 |
InvalidData, TryAgain, OperationNotPermitted, PermissionDenied |
263 |
from portage.data import portage_gid |
264 |
|
265 |
Modified: main/branches/prefix/pym/portage/news.py |
266 |
=================================================================== |
267 |
--- main/branches/prefix/pym/portage/news.py 2009-08-24 09:28:51 UTC (rev 14138) |
268 |
+++ main/branches/prefix/pym/portage/news.py 2009-08-24 09:31:55 UTC (rev 14139) |
269 |
@@ -9,8 +9,13 @@ |
270 |
|
271 |
import codecs |
272 |
import logging |
273 |
-import os |
274 |
+import os as _os |
275 |
import re |
276 |
+from portage import os |
277 |
+from portage import _content_encoding |
278 |
+from portage import _fs_encoding |
279 |
+from portage import _unicode_decode |
280 |
+from portage import _unicode_encode |
281 |
from portage.util import apply_secpass_permissions, ensure_dirs, \ |
282 |
grabfile, normalize_path, write_atomic, writemsg_level |
283 |
from portage.data import portage_gid |
284 |
@@ -94,7 +99,8 @@ |
285 |
|
286 |
news_dir = self._news_dir(repoid) |
287 |
try: |
288 |
- news = os.listdir(news_dir) |
289 |
+ news = _os.listdir(_unicode_encode(news_dir, |
290 |
+ encoding=_fs_encoding, errors='strict')) |
291 |
except OSError: |
292 |
return |
293 |
|
294 |
@@ -112,14 +118,23 @@ |
295 |
|
296 |
updates = [] |
297 |
for itemid in news: |
298 |
+ try: |
299 |
+ itemid = _unicode_decode(itemid, |
300 |
+ encoding=_fs_encoding, errors='strict') |
301 |
+ except UnicodeDecodeError: |
302 |
+ itemid = _unicode_decode(itemid, |
303 |
+ encoding=_fs_encoding, errors='replace') |
304 |
+ writemsg_level( |
305 |
+ "!!! Invalid encoding in news item name: '%s'\n" % \ |
306 |
+ itemid, level=logging.ERROR, noiselevel=-1) |
307 |
+ continue |
308 |
+ |
309 |
if itemid in skip: |
310 |
continue |
311 |
filename = os.path.join(news_dir, itemid, |
312 |
itemid + "." + self.language_id + ".txt") |
313 |
if not os.path.isfile(filename): |
314 |
continue |
315 |
- if not isinstance(itemid, unicode): |
316 |
- itemid = unicode(itemid, encoding='utf_8', errors='replace') |
317 |
item = NewsItem(filename, itemid) |
318 |
if not item.isValid(): |
319 |
continue |
320 |
@@ -171,6 +186,7 @@ |
321 |
if unread_lock: |
322 |
unlockfile(unread_lock) |
323 |
|
324 |
+_formatRE = re.compile("News-Item-Format:\s*([^\s]*)\s*$") |
325 |
_installedRE = re.compile("Display-If-Installed:(.*)\n") |
326 |
_profileRE = re.compile("Display-If-Profile:(.*)\n") |
327 |
_keywordRE = re.compile("Display-If-Keyword:(.*)\n") |
328 |
@@ -184,7 +200,6 @@ |
329 |
"display if arch: x86" and so forth. |
330 |
|
331 |
Creation of a news item involves passing in the path to the particular news item. |
332 |
- |
333 |
""" |
334 |
|
335 |
def __init__(self, path, name): |
336 |
@@ -203,24 +218,33 @@ |
337 |
and a vardb so we can look at installed packages). |
338 |
Each restriction will pluck out the items that are required for it to match |
339 |
or raise a ValueError exception if the required object is not present. |
340 |
+ |
341 |
+ Restrictions of the form Display-X are OR'd with like-restrictions; |
342 |
+ otherwise restrictions are AND'd. any_match is the ORing and |
343 |
+ all_match is the ANDing. |
344 |
""" |
345 |
|
346 |
if not self._parsed: |
347 |
self.parse() |
348 |
|
349 |
if not len(self.restrictions): |
350 |
- return True # no restrictions to match means everyone should see it |
351 |
+ return True |
352 |
|
353 |
kwargs = \ |
354 |
{ 'vardb' : vardb, |
355 |
'config' : config, |
356 |
'profile' : profile } |
357 |
|
358 |
- for restriction in self.restrictions: |
359 |
- if restriction.checkRestriction(**kwargs): |
360 |
- return True |
361 |
+ all_match = True |
362 |
+ for values in self.restrictions.itervalues(): |
363 |
+ any_match = False |
364 |
+ for restriction in values: |
365 |
+ if restriction.checkRestriction(**kwargs): |
366 |
+ any_match = True |
367 |
+ if not any_match: |
368 |
+ all_match = False |
369 |
|
370 |
- return False # No restrictions were met; thus we aren't relevant :( |
371 |
+ return all_match |
372 |
|
373 |
def isValid(self): |
374 |
if not self._parsed: |
375 |
@@ -228,13 +252,18 @@ |
376 |
return self._valid |
377 |
|
378 |
def parse(self): |
379 |
- lines = codecs.open(self.path, mode='r', |
380 |
- encoding='utf_8', errors='replace').readlines() |
381 |
- self.restrictions = [] |
382 |
+ lines = codecs.open(_unicode_encode(self.path, |
383 |
+ encoding=_fs_encoding, errors='strict'), |
384 |
+ mode='r', encoding=_content_encoding, errors='replace').readlines() |
385 |
+ self.restrictions = {} |
386 |
invalids = [] |
387 |
for i, line in enumerate(lines): |
388 |
- #Optimization to ignore regex matchines on lines that |
389 |
- #will never match |
390 |
+ # Optimization to ignore regex matchines on lines that |
391 |
+ # will never match |
392 |
+ format_match = _formatRE.match(line) |
393 |
+ if format_match is not None and format_match.group(1) != '1.0': |
394 |
+ invalids.append((i + 1, line.rstrip('\n'))) |
395 |
+ break |
396 |
if not line.startswith('D'): |
397 |
continue |
398 |
restricts = { _installedRE : DisplayInstalledRestriction, |
399 |
@@ -243,9 +272,12 @@ |
400 |
for regex, restriction in restricts.iteritems(): |
401 |
match = regex.match(line) |
402 |
if match: |
403 |
- self.restrictions.append(restriction(match.groups()[0].strip())) |
404 |
- if not self.restrictions[-1].isValid(): |
405 |
+ restrict = restriction(match.groups()[0].strip()) |
406 |
+ if not restrict.isValid(): |
407 |
invalids.append((i + 1, line.rstrip("\n"))) |
408 |
+ else: |
409 |
+ self.restrictions.setdefault( |
410 |
+ id(restriction), []).append(restrict) |
411 |
continue |
412 |
if invalids: |
413 |
self._valid = False |
414 |
|
415 |
Modified: main/branches/prefix/pym/portage/output.py |
416 |
=================================================================== |
417 |
--- main/branches/prefix/pym/portage/output.py 2009-08-24 09:28:51 UTC (rev 14138) |
418 |
+++ main/branches/prefix/pym/portage/output.py 2009-08-24 09:31:55 UTC (rev 14139) |
419 |
@@ -8,9 +8,7 @@ |
420 |
import commands |
421 |
import errno |
422 |
import formatter |
423 |
-import os |
424 |
import re |
425 |
-import shlex |
426 |
import sys |
427 |
|
428 |
import portage |
429 |
@@ -18,6 +16,10 @@ |
430 |
'portage.util:writemsg', |
431 |
) |
432 |
|
433 |
+from portage import os |
434 |
+from portage import _content_encoding |
435 |
+from portage import _fs_encoding |
436 |
+from portage import _unicode_encode |
437 |
from portage.const import COLOR_MAP_FILE, EPREFIX |
438 |
from portage.exception import CommandNotFound, FileNotFound, \ |
439 |
ParseError, PermissionDenied, PortageException |
440 |
@@ -141,7 +143,7 @@ |
441 |
_styles["PROMPT_CHOICE_DEFAULT"] = ( "green", ) |
442 |
_styles["PROMPT_CHOICE_OTHER"] = ( "red", ) |
443 |
|
444 |
-def _parse_color_map(onerror=None): |
445 |
+def _parse_color_map(config_root='/', onerror=None): |
446 |
""" |
447 |
Parse /etc/portage/color.map and return a dict of error codes. |
448 |
|
449 |
@@ -157,7 +159,7 @@ |
450 |
# that can be called in order adjust the location that color.map |
451 |
# is read from. |
452 |
global codes, _styles |
453 |
- myfile = os.path.join(EPREFIX, COLOR_MAP_FILE) |
454 |
+ myfile = os.path.join(config_root, COLOR_MAP_FILE) |
455 |
ansi_code_pattern = re.compile("^[0-9;]*m$") |
456 |
quotes = '\'"' |
457 |
def strip_quotes(token): |
458 |
@@ -166,8 +168,9 @@ |
459 |
return token |
460 |
try: |
461 |
lineno=0 |
462 |
- for line in codecs.open( myfile, mode='r', |
463 |
- encoding='utf_8', errors='replace' ): |
464 |
+ for line in codecs.open(_unicode_encode(myfile, |
465 |
+ encoding=_fs_encoding, errors='strict'), |
466 |
+ mode='r', encoding=_content_encoding, errors='replace'): |
467 |
lineno += 1 |
468 |
|
469 |
commenter_pos = line.find("#") |
470 |
@@ -467,7 +470,7 @@ |
471 |
def _write(self, f, s): |
472 |
if sys.hexversion < 0x3000000 and isinstance(s, unicode): |
473 |
# avoid potential UnicodeEncodeError |
474 |
- s = s.encode('utf_8', 'replace') |
475 |
+ s = s.encode(_content_encoding, 'replace') |
476 |
f.write(s) |
477 |
f.flush() |
478 |
|
479 |
@@ -723,13 +726,46 @@ |
480 |
">" + ((max_bar_width - bar_width) * " ") + "]" |
481 |
return image |
482 |
|
483 |
-try: |
484 |
- _parse_color_map(onerror=lambda e: writemsg("%s\n" % str(e), noiselevel=-1)) |
485 |
-except FileNotFound: |
486 |
- pass |
487 |
-except PermissionDenied, e: |
488 |
- writemsg(_("Permission denied: '%s'\n") % str(e), noiselevel=-1) |
489 |
- del e |
490 |
-except PortageException, e: |
491 |
- writemsg("%s\n" % str(e), noiselevel=-1) |
492 |
- del e |
493 |
+_color_map_loaded = False |
494 |
+ |
495 |
+def _init(config_root='/'): |
496 |
+ """ |
497 |
+ Load color.map from the given config_root. This is called automatically |
498 |
+ on first access of the codes or _styles attributes (unless it has already |
499 |
+ been called for some other reason). |
500 |
+ """ |
501 |
+ |
502 |
+ global _color_map_loaded, codes, _styles |
503 |
+ if _color_map_loaded: |
504 |
+ return |
505 |
+ |
506 |
+ _color_map_loaded = True |
507 |
+ codes = object.__getattribute__(codes, '_attr') |
508 |
+ _styles = object.__getattribute__(_styles, '_attr') |
509 |
+ |
510 |
+ try: |
511 |
+ _parse_color_map(config_root=config_root, |
512 |
+ onerror=lambda e: writemsg("%s\n" % str(e), noiselevel=-1)) |
513 |
+ except FileNotFound: |
514 |
+ pass |
515 |
+ except PermissionDenied, e: |
516 |
+ writemsg(_("Permission denied: '%s'\n") % str(e), noiselevel=-1) |
517 |
+ del e |
518 |
+ except PortageException, e: |
519 |
+ writemsg("%s\n" % str(e), noiselevel=-1) |
520 |
+ del e |
521 |
+ |
522 |
+class _LazyInitColorMap(portage.proxy.objectproxy.ObjectProxy): |
523 |
+ |
524 |
+ __slots__ = ('_attr',) |
525 |
+ |
526 |
+ def __init__(self, attr): |
527 |
+ portage.proxy.objectproxy.ObjectProxy.__init__(self) |
528 |
+ object.__setattr__(self, '_attr', attr) |
529 |
+ |
530 |
+ def _get_target(self): |
531 |
+ _init() |
532 |
+ return object.__getattribute__(self, '_attr') |
533 |
+ |
534 |
+codes = _LazyInitColorMap(codes) |
535 |
+_styles = _LazyInitColorMap(_styles) |
536 |
|
537 |
Modified: main/branches/prefix/pym/portage/tests/bin/setup_env.py |
538 |
=================================================================== |
539 |
--- main/branches/prefix/pym/portage/tests/bin/setup_env.py 2009-08-24 09:28:51 UTC (rev 14138) |
540 |
+++ main/branches/prefix/pym/portage/tests/bin/setup_env.py 2009-08-24 09:31:55 UTC (rev 14139) |
541 |
@@ -3,15 +3,17 @@ |
542 |
# Distributed under the terms of the GNU General Public License v2 |
543 |
# $Id$ |
544 |
|
545 |
-import os, shutil, sys |
546 |
-from os.path import dirname, abspath, join |
547 |
+from portage import os |
548 |
+from portage import shutil |
549 |
from portage.tests import TestCase |
550 |
from portage.process import spawn |
551 |
from portage.const import PORTAGE_BIN_PATH |
552 |
|
553 |
-bindir = join(dirname(dirname(abspath(__file__))), |
554 |
+bindir = os.path.join(os.path.dirname(os.path.dirname( |
555 |
+ os.path.abspath(__file__))), |
556 |
"..", "..", "..", "bin", "ebuild-helpers") |
557 |
-basedir = join(dirname(dirname(abspath(__file__))), "bin", "root") |
558 |
+basedir = os.path.join(os.path.dirname(os.path.dirname( |
559 |
+ os.path.abspath(__file__))), "bin", "root") |
560 |
os.environ["D"] = os.path.join(basedir, "image") |
561 |
os.environ["T"] = os.path.join(basedir, "temp") |
562 |
os.environ["S"] = os.path.join(basedir, "workdir") |
563 |
@@ -52,7 +54,7 @@ |
564 |
def portage_func(func, args, exit_status=0): |
565 |
# we don't care about the output of the programs, |
566 |
# just their exit value and the state of $D |
567 |
- f = open('/dev/null', 'w') |
568 |
+ f = open('/dev/null', 'wb') |
569 |
fd_pipes = {0:0,1:f.fileno(),2:f.fileno()} |
570 |
spawn(func+" "+args, env=os.environ, fd_pipes=fd_pipes) |
571 |
f.close() |
572 |
|
573 |
Modified: main/branches/prefix/pym/portage/tests/ebuild/test_spawn.py |
574 |
=================================================================== |
575 |
--- main/branches/prefix/pym/portage/tests/ebuild/test_spawn.py 2009-08-24 09:28:51 UTC (rev 14138) |
576 |
+++ main/branches/prefix/pym/portage/tests/ebuild/test_spawn.py 2009-08-24 09:31:55 UTC (rev 14139) |
577 |
@@ -2,7 +2,13 @@ |
578 |
# Distributed under the terms of the GNU General Public License v2 |
579 |
# $Id$ |
580 |
|
581 |
-import errno, os, sys |
582 |
+import codecs |
583 |
+import errno |
584 |
+import sys |
585 |
+from portage import os |
586 |
+from portage import _content_encoding |
587 |
+from portage import _fs_encoding |
588 |
+from portage import _unicode_encode |
589 |
from portage.tests import TestCase |
590 |
|
591 |
class SpawnTestCase(TestCase): |
592 |
@@ -27,7 +33,9 @@ |
593 |
spawn("echo -n '%s'" % test_string, settings, logfile=logfile, |
594 |
free=1, fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd}) |
595 |
os.close(null_fd) |
596 |
- f = open(logfile, 'r') |
597 |
+ f = codecs.open(_unicode_encode(logfile, |
598 |
+ encoding=_fs_encoding, errors='strict'), |
599 |
+ mode='r', encoding=_content_encoding, errors='strict') |
600 |
log_content = f.read() |
601 |
f.close() |
602 |
# When logging passes through a pty, this comparison will fail |
603 |
|
604 |
Modified: main/branches/prefix/pym/portage/tests/env/config/test_PackageKeywordsFile.py |
605 |
=================================================================== |
606 |
--- main/branches/prefix/pym/portage/tests/env/config/test_PackageKeywordsFile.py 2009-08-24 09:28:51 UTC (rev 14138) |
607 |
+++ main/branches/prefix/pym/portage/tests/env/config/test_PackageKeywordsFile.py 2009-08-24 09:31:55 UTC (rev 14139) |
608 |
@@ -3,10 +3,10 @@ |
609 |
# Distributed under the terms of the GNU General Public License v2 |
610 |
# $Id$ |
611 |
|
612 |
+from portage import os |
613 |
from portage.tests import TestCase |
614 |
from portage.env.config import PackageKeywordsFile |
615 |
from tempfile import mkstemp |
616 |
-import os |
617 |
|
618 |
class PackageKeywordsFileTestCase(TestCase): |
619 |
|
620 |
@@ -38,5 +38,4 @@ |
621 |
f.close() |
622 |
|
623 |
def NukeFile(self): |
624 |
- import os |
625 |
os.unlink(self.fname) |
626 |
|
627 |
Modified: main/branches/prefix/pym/portage/tests/env/config/test_PackageMaskFile.py |
628 |
=================================================================== |
629 |
--- main/branches/prefix/pym/portage/tests/env/config/test_PackageMaskFile.py 2009-08-24 09:28:51 UTC (rev 14138) |
630 |
+++ main/branches/prefix/pym/portage/tests/env/config/test_PackageMaskFile.py 2009-08-24 09:31:55 UTC (rev 14139) |
631 |
@@ -3,8 +3,7 @@ |
632 |
# Distributed under the terms of the GNU General Public License v2 |
633 |
# $Id$ |
634 |
|
635 |
-import os |
636 |
- |
637 |
+from portage import os |
638 |
from portage.env.config import PackageMaskFile |
639 |
from portage.tests import TestCase, test_cps |
640 |
from tempfile import mkstemp |
641 |
|
642 |
Modified: main/branches/prefix/pym/portage/tests/env/config/test_PackageUseFile.py |
643 |
=================================================================== |
644 |
--- main/branches/prefix/pym/portage/tests/env/config/test_PackageUseFile.py 2009-08-24 09:28:51 UTC (rev 14138) |
645 |
+++ main/branches/prefix/pym/portage/tests/env/config/test_PackageUseFile.py 2009-08-24 09:31:55 UTC (rev 14139) |
646 |
@@ -3,7 +3,7 @@ |
647 |
# Distributed under the terms of the GNU General Public License v2 |
648 |
# $Id$ |
649 |
|
650 |
-import os |
651 |
+from portage import os |
652 |
from portage.tests import TestCase |
653 |
from portage.env.config import PackageUseFile |
654 |
from tempfile import mkstemp |
655 |
|
656 |
Modified: main/branches/prefix/pym/portage/tests/env/config/test_PortageModulesFile.py |
657 |
=================================================================== |
658 |
--- main/branches/prefix/pym/portage/tests/env/config/test_PortageModulesFile.py 2009-08-24 09:28:51 UTC (rev 14138) |
659 |
+++ main/branches/prefix/pym/portage/tests/env/config/test_PortageModulesFile.py 2009-08-24 09:31:55 UTC (rev 14139) |
660 |
@@ -1,9 +1,12 @@ |
661 |
+# Copyright 2006-2009 Gentoo Foundation |
662 |
+# Distributed under the terms of the GNU General Public License v2 |
663 |
+# $Id$ |
664 |
|
665 |
+from portage import os |
666 |
from portage.tests import TestCase |
667 |
from portage.env.config import PortageModulesFile |
668 |
from tempfile import mkstemp |
669 |
from itertools import izip |
670 |
-import os |
671 |
|
672 |
class PortageModulesFileTestCase(TestCase): |
673 |
|
674 |
|
675 |
Modified: main/branches/prefix/pym/portage/tests/news/test_NewsItem.py |
676 |
=================================================================== |
677 |
--- main/branches/prefix/pym/portage/tests/news/test_NewsItem.py 2009-08-24 09:28:51 UTC (rev 14138) |
678 |
+++ main/branches/prefix/pym/portage/tests/news/test_NewsItem.py 2009-08-24 09:31:55 UTC (rev 14139) |
679 |
@@ -3,10 +3,9 @@ |
680 |
# Distributed under the terms of the GNU General Public License v2 |
681 |
# $Id$ |
682 |
|
683 |
-import os |
684 |
+from portage import os |
685 |
from portage.tests import TestCase |
686 |
from portage.news import NewsItem |
687 |
-from portage.const import PROFILE_PATH |
688 |
from portage.dbapi.virtual import testdbapi |
689 |
from tempfile import mkstemp |
690 |
# TODO(antarus) Make newsitem use a loader so we can load using a string instead of a tempfile |
691 |
|
692 |
Modified: main/branches/prefix/pym/portage/tests/process/test_poll.py |
693 |
=================================================================== |
694 |
--- main/branches/prefix/pym/portage/tests/process/test_poll.py 2009-08-24 09:28:51 UTC (rev 14138) |
695 |
+++ main/branches/prefix/pym/portage/tests/process/test_poll.py 2009-08-24 09:31:55 UTC (rev 14139) |
696 |
@@ -2,11 +2,8 @@ |
697 |
# Distributed under the terms of the GNU General Public License v2 |
698 |
# $Id$ |
699 |
|
700 |
-import errno, os, sys |
701 |
-import fcntl |
702 |
-import termios |
703 |
-import portage |
704 |
-from portage.output import get_term_size, set_term_size |
705 |
+import sys |
706 |
+from portage import os |
707 |
from portage.tests import TestCase |
708 |
from _emerge.TaskScheduler import TaskScheduler |
709 |
from _emerge.PipeReader import PipeReader |
710 |
|
711 |
Modified: main/branches/prefix/pym/portage/tests/sets/files/testConfigFileSet.py |
712 |
=================================================================== |
713 |
--- main/branches/prefix/pym/portage/tests/sets/files/testConfigFileSet.py 2009-08-24 09:28:51 UTC (rev 14138) |
714 |
+++ main/branches/prefix/pym/portage/tests/sets/files/testConfigFileSet.py 2009-08-24 09:31:55 UTC (rev 14139) |
715 |
@@ -3,8 +3,9 @@ |
716 |
# Distributed under the terms of the GNU General Public License v2 |
717 |
# $Id$ |
718 |
|
719 |
-import tempfile, os |
720 |
+import tempfile |
721 |
|
722 |
+from portage import os |
723 |
from portage.tests import TestCase, test_cps |
724 |
from portage.sets.files import ConfigFileSet |
725 |
|
726 |
|
727 |
Modified: main/branches/prefix/pym/portage/tests/sets/files/testStaticFileSet.py |
728 |
=================================================================== |
729 |
--- main/branches/prefix/pym/portage/tests/sets/files/testStaticFileSet.py 2009-08-24 09:28:51 UTC (rev 14138) |
730 |
+++ main/branches/prefix/pym/portage/tests/sets/files/testStaticFileSet.py 2009-08-24 09:31:55 UTC (rev 14139) |
731 |
@@ -3,12 +3,11 @@ |
732 |
# Distributed under the terms of the GNU General Public License v2 |
733 |
# $Id$ |
734 |
|
735 |
-import tempfile, os |
736 |
+import tempfile |
737 |
|
738 |
+from portage import os |
739 |
from portage.tests import TestCase, test_cps |
740 |
from portage.sets.files import StaticFileSet |
741 |
-from portage.env.loaders import TestTextLoader |
742 |
-from portage.env.config import ConfigLoaderKlass |
743 |
|
744 |
class StaticFileSetTestCase(TestCase): |
745 |
"""Simple Test Case for StaticFileSet""" |
746 |
|
747 |
Modified: main/branches/prefix/pym/portage/tests/util/test_uniqueArray.py |
748 |
=================================================================== |
749 |
--- main/branches/prefix/pym/portage/tests/util/test_uniqueArray.py 2009-08-24 09:28:51 UTC (rev 14138) |
750 |
+++ main/branches/prefix/pym/portage/tests/util/test_uniqueArray.py 2009-08-24 09:31:55 UTC (rev 14139) |
751 |
@@ -3,6 +3,7 @@ |
752 |
# Distributed under the terms of the GNU General Public License v2 |
753 |
# $Id$ |
754 |
|
755 |
+from portage import os |
756 |
from portage.tests import TestCase |
757 |
from portage.util import unique_array |
758 |
|
759 |
@@ -13,8 +14,6 @@ |
760 |
test portage.util.uniqueArray() |
761 |
""" |
762 |
|
763 |
- import os |
764 |
- |
765 |
tests = [ ( ["a","a","a",os,os,[],[],[]], ['a',os,[]] ), |
766 |
( [1,1,1,2,3,4,4] , [1,2,3,4]) ] |