1 |
Author: grobian |
2 |
Date: 2009-08-24 09:20:57 +0000 (Mon, 24 Aug 2009) |
3 |
New Revision: 14136 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/_emerge/PackageUninstall.py |
7 |
main/branches/prefix/pym/portage/__init__.py |
8 |
main/branches/prefix/pym/portage/dbapi/vartree.py |
9 |
main/branches/prefix/pym/portage/elog/__init__.py |
10 |
main/branches/prefix/pym/portage/elog/messages.py |
11 |
main/branches/prefix/pym/portage/elog/mod_mail_summary.py |
12 |
main/branches/prefix/pym/portage/elog/mod_save.py |
13 |
main/branches/prefix/pym/portage/elog/mod_save_summary.py |
14 |
main/branches/prefix/pym/portage/manifest.py |
15 |
main/branches/prefix/pym/portage/sets/__init__.py |
16 |
main/branches/prefix/pym/portage/sets/dbapi.py |
17 |
main/branches/prefix/pym/portage/sets/files.py |
18 |
main/branches/prefix/pym/portage/sets/profiles.py |
19 |
main/branches/prefix/pym/portage/sets/security.py |
20 |
main/branches/prefix/pym/portage/sets/shell.py |
21 |
Log: |
22 |
Merged from trunk -r14047:14057 |
23 |
|
24 |
| 14048 | Revert r14042 since we're not going to use it. | |
25 |
| zmedico | | |
26 |
|
27 |
| 14049 | In dblink._unmerge_pkgfiles(), if the package appears to | |
28 |
| zmedico | have been merged with a different value of | |
29 |
| | sys.getfilesystemencoding(), fall back to utf_8 if | |
30 |
| | appropriate. | |
31 |
|
32 |
| 14050 | Inside dblink.treewalk(), handle filenames with incorrect | |
33 |
| zmedico | encoding like we do after src_install. The check needs to be | |
34 |
| | repeated here for binary packages (it's inexpensive since we | |
35 |
| | call os.walk() here anyway). | |
36 |
|
37 |
| 14051 | Update imports to import portage.os (with unicode wrappers). | |
38 |
| zmedico | | |
39 |
|
40 |
| 14052 | Update imports to import portage.os (with unicode wrappers), | |
41 |
| zmedico | and use _unicode_encode() and _unicode_decode() where | |
42 |
| | appropriate. | |
43 |
|
44 |
| 14053 | Use portage._fs_encoding where applicable. | |
45 |
| zmedico | | |
46 |
|
47 |
| 14054 | Handle UnicodeDecodeError for os.walk() inside | |
48 |
| zmedico | digestcheck(). | |
49 |
|
50 |
| 14055 | Use portage._fs_encoding where appropriage, and use strict | |
51 |
| zmedico | handling for errors. | |
52 |
|
53 |
| 14056 | Add a portage._content_encoding constant, set to utf_8. | |
54 |
| zmedico | | |
55 |
|
56 |
| 14057 | Fix broken _selinux_merge definition. | |
57 |
| zmedico | | |
58 |
|
59 |
|
60 |
Modified: main/branches/prefix/pym/_emerge/PackageUninstall.py |
61 |
=================================================================== |
62 |
--- main/branches/prefix/pym/_emerge/PackageUninstall.py 2009-08-24 06:25:30 UTC (rev 14135) |
63 |
+++ main/branches/prefix/pym/_emerge/PackageUninstall.py 2009-08-24 09:20:57 UTC (rev 14136) |
64 |
@@ -12,14 +12,12 @@ |
65 |
|
66 |
class PackageUninstall(AsynchronousTask): |
67 |
|
68 |
- __slots__ = ("clean_world", "ldpath_mtimes", "opts", |
69 |
- "pkg", "scheduler", "settings") |
70 |
+ __slots__ = ("ldpath_mtimes", "opts", "pkg", "scheduler", "settings") |
71 |
|
72 |
def _start(self): |
73 |
try: |
74 |
unmerge(self.pkg.root_config, self.opts, "unmerge", |
75 |
- [self.pkg.cpv], self.ldpath_mtimes, |
76 |
- clean_world=self.clean_world, |
77 |
+ [self.pkg.cpv], self.ldpath_mtimes, clean_world=0, |
78 |
clean_delay=0, raise_on_error=1, scheduler=self.scheduler, |
79 |
writemsg_level=self._writemsg_level) |
80 |
except UninstallFailure, e: |
81 |
|
82 |
Modified: main/branches/prefix/pym/portage/__init__.py |
83 |
=================================================================== |
84 |
--- main/branches/prefix/pym/portage/__init__.py 2009-08-24 06:25:30 UTC (rev 14135) |
85 |
+++ main/branches/prefix/pym/portage/__init__.py 2009-08-24 09:20:57 UTC (rev 14136) |
86 |
@@ -73,6 +73,7 @@ |
87 |
'portage.getbinpkg', |
88 |
'portage.locks', |
89 |
'portage.locks:lockdir,lockfile,unlockdir,unlockfile', |
90 |
+ 'portage.mail', |
91 |
'portage.output', |
92 |
'portage.output:bold,colorize', |
93 |
'portage.process', |
94 |
@@ -118,12 +119,20 @@ |
95 |
sys.stderr.write(" "+str(e)+"\n\n") |
96 |
raise |
97 |
|
98 |
-def _unicode_encode(s, encoding='utf_8', errors='replace'): |
99 |
+# Assume utf_8 encoding for content of all files. |
100 |
+_content_encoding = 'utf_8' |
101 |
+ |
102 |
+# Assume utf_8 fs encoding everywhere except in merge code. |
103 |
+_fs_encoding = 'utf_8' |
104 |
+ |
105 |
+_merge_encoding = sys.getfilesystemencoding() |
106 |
+ |
107 |
+def _unicode_encode(s, encoding=_content_encoding, errors='replace'): |
108 |
if isinstance(s, unicode): |
109 |
s = s.encode(encoding, errors) |
110 |
return s |
111 |
|
112 |
-def _unicode_decode(s, encoding='utf_8', errors='replace'): |
113 |
+def _unicode_decode(s, encoding=_content_encoding, errors='replace'): |
114 |
if not isinstance(s, unicode): |
115 |
if sys.hexversion < 0x3000000: |
116 |
if isinstance(s, basestring): |
117 |
@@ -197,8 +206,6 @@ |
118 |
result = _unicode_func_wrapper(result, encoding=encoding) |
119 |
return result |
120 |
|
121 |
-_merge_encoding = sys.getfilesystemencoding() |
122 |
- |
123 |
import os as _os |
124 |
_os_overrides = { |
125 |
id(_os.fdopen) : _os.fdopen, |
126 |
@@ -206,20 +213,22 @@ |
127 |
id(_os.system) : _os.system, |
128 |
} |
129 |
|
130 |
-os = _unicode_module_wrapper(_os, overrides=_os_overrides) |
131 |
+os = _unicode_module_wrapper(_os, overrides=_os_overrides, |
132 |
+ encoding=_fs_encoding) |
133 |
_os_merge = _unicode_module_wrapper(_os, |
134 |
encoding=_merge_encoding, overrides=_os_overrides) |
135 |
|
136 |
import shutil as _shutil |
137 |
-shutil = _unicode_module_wrapper(_shutil) |
138 |
+shutil = _unicode_module_wrapper(_shutil, encoding=_fs_encoding) |
139 |
|
140 |
# Imports below this point rely on the above unicode wrapper definitions. |
141 |
_selinux = None |
142 |
selinux = None |
143 |
-_selinux_merge = _unicode_module_wrapper(_selinux, encoding=_merge_encoding) |
144 |
+_selinux_merge = None |
145 |
try: |
146 |
import portage._selinux |
147 |
- selinux = _unicode_module_wrapper(_selinux) |
148 |
+ selinux = _unicode_module_wrapper(_selinux, encoding=_fs_encoding) |
149 |
+ _selinux_merge = _unicode_module_wrapper(_selinux, encoding=_merge_encoding) |
150 |
except OSError, e: |
151 |
sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e)) |
152 |
del e |
153 |
@@ -5310,12 +5319,37 @@ |
154 |
filesdir = os.path.join(pkgdir, "files") |
155 |
|
156 |
for parent, dirs, files in os.walk(filesdir): |
157 |
- parent = _unicode_decode(parent) |
158 |
+ try: |
159 |
+ parent = _unicode_decode(parent, |
160 |
+ encoding=_fs_encoding, errors='strict') |
161 |
+ except UnicodeDecodeError: |
162 |
+ parent = _unicode_decode(parent, |
163 |
+ encoding=_fs_encoding, errors='replace') |
164 |
+ writemsg("!!! Path contains invalid " + \ |
165 |
+ "character(s) for encoding '%s': '%s'" \ |
166 |
+ % (_fs_encoding, parent), noiselevel=-1) |
167 |
+ if strict: |
168 |
+ return 0 |
169 |
+ continue |
170 |
for d in dirs: |
171 |
if d.startswith(".") or d == "CVS": |
172 |
dirs.remove(d) |
173 |
for f in files: |
174 |
- f = _unicode_decode(f) |
175 |
+ try: |
176 |
+ f = _unicode_decode(f, |
177 |
+ encoding=_fs_encoding, errors='strict') |
178 |
+ except UnicodeDecodeError: |
179 |
+ f = _unicode_decode(f, |
180 |
+ encoding=_fs_encoding, errors='replace') |
181 |
+ if f.startswith("."): |
182 |
+ continue |
183 |
+ f = os.path.join(parent, f)[len(filesdir) + 1:] |
184 |
+ writemsg("!!! File name contains invalid " + \ |
185 |
+ "character(s) for encoding '%s': '%s'" \ |
186 |
+ % (_fs_encoding, f), noiselevel=-1) |
187 |
+ if strict: |
188 |
+ return 0 |
189 |
+ continue |
190 |
if f.startswith("."): |
191 |
continue |
192 |
f = os.path.join(parent, f)[len(filesdir) + 1:] |
193 |
@@ -5645,34 +5679,10 @@ |
194 |
break |
195 |
|
196 |
if unicode_errors: |
197 |
- from textwrap import wrap |
198 |
from portage.elog.messages import eerror |
199 |
- def _eerror(l): |
200 |
+ for l in _merge_unicode_error(unicode_errors): |
201 |
eerror(l, phase='install', key=mysettings.mycpv, out=out) |
202 |
|
203 |
- msg = "This package installs one or more file names containing " + \ |
204 |
- "characters that do not match your current locale " + \ |
205 |
- "settings. The current setting for filesystem encoding is '%s'." \ |
206 |
- % _merge_encoding |
207 |
- for l in wrap(msg, 72): |
208 |
- _eerror(l) |
209 |
- |
210 |
- _eerror("") |
211 |
- for x in unicode_errors: |
212 |
- _eerror("\t" + x) |
213 |
- _eerror("") |
214 |
- |
215 |
- if _merge_encoding.lower().replace('_', '').replace('-', '') != 'utf8': |
216 |
- msg = "For best results, UTF-8 encoding is recommended. See " + \ |
217 |
- "the Gentoo Linux Localization Guide for instructions " + \ |
218 |
- "about how to configure your locale for UTF-8 encoding:" |
219 |
- for l in wrap(msg, 72): |
220 |
- _eerror(l) |
221 |
- _eerror("") |
222 |
- _eerror("\t" + \ |
223 |
- "http://www.gentoo.org/doc/en/guide-localization.xml") |
224 |
- _eerror("") |
225 |
- |
226 |
open(_unicode_encode(os.path.join(mysettings['PORTAGE_BUILDDIR'], |
227 |
'build-info', 'SIZE')), 'w').write(str(size) + '\n') |
228 |
|
229 |
@@ -5682,6 +5692,33 @@ |
230 |
(_shell_quote(mysettings["D"]), |
231 |
_shell_quote(os.path.join(mysettings["T"], "bsdflags.mtree")))) |
232 |
|
233 |
+def _merge_unicode_error(errors): |
234 |
+ from textwrap import wrap |
235 |
+ lines = [] |
236 |
+ |
237 |
+ msg = "This package installs one or more file names containing " + \ |
238 |
+ "characters that do not match your current locale " + \ |
239 |
+ "settings. The current setting for filesystem encoding is '%s'." \ |
240 |
+ % _merge_encoding |
241 |
+ lines.extend(wrap(msg, 72)) |
242 |
+ |
243 |
+ lines.append("") |
244 |
+ errors.sort() |
245 |
+ lines.extend("\t" + x for x in errors) |
246 |
+ lines.append("") |
247 |
+ |
248 |
+ if _merge_encoding.lower().replace('_', '').replace('-', '') != 'utf8': |
249 |
+ msg = "For best results, UTF-8 encoding is recommended. See " + \ |
250 |
+ "the Gentoo Linux Localization Guide for instructions " + \ |
251 |
+ "about how to configure your locale for UTF-8 encoding:" |
252 |
+ lines.extend(wrap(msg, 72)) |
253 |
+ lines.append("") |
254 |
+ lines.append("\t" + \ |
255 |
+ "http://www.gentoo.org/doc/en/guide-localization.xml") |
256 |
+ lines.append("") |
257 |
+ |
258 |
+ return lines |
259 |
+ |
260 |
def _post_pkg_preinst_cmd(mysettings): |
261 |
""" |
262 |
Post phase logic and tasks that have been factored out of |
263 |
@@ -7129,7 +7166,7 @@ |
264 |
"mv '%s' '%s'" % (src, dest)) |
265 |
|
266 |
def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
267 |
- hardlink_candidates=None, encoding='utf_8'): |
268 |
+ hardlink_candidates=None, encoding=_fs_encoding): |
269 |
"""moves a file from src to dest, preserving all permissions and attributes; mtime will |
270 |
be preserved even when moving across filesystems. Returns true on success and false on |
271 |
failure. Move is atomic.""" |
272 |
|
273 |
Modified: main/branches/prefix/pym/portage/dbapi/vartree.py |
274 |
=================================================================== |
275 |
--- main/branches/prefix/pym/portage/dbapi/vartree.py 2009-08-24 06:25:30 UTC (rev 14135) |
276 |
+++ main/branches/prefix/pym/portage/dbapi/vartree.py 2009-08-24 09:20:57 UTC (rev 14136) |
277 |
@@ -38,9 +38,11 @@ |
278 |
|
279 |
# This is a special version of the os module, wrapped for unicode support. |
280 |
from portage import os |
281 |
+from portage import _fs_encoding |
282 |
from portage import _merge_encoding |
283 |
from portage import _os_merge |
284 |
from portage import _selinux_merge |
285 |
+from portage import _unicode_decode |
286 |
from portage import _unicode_encode |
287 |
|
288 |
from portage.cache.mappings import slot_dict_class |
289 |
@@ -3074,6 +3076,20 @@ |
290 |
scheduler.scheduleYield() |
291 |
|
292 |
obj = normalize_path(objkey) |
293 |
+ if os is _os_merge: |
294 |
+ try: |
295 |
+ _unicode_encode(obj, encoding=_merge_encoding, errors='strict') |
296 |
+ except UnicodeEncodeError: |
297 |
+ # The package appears to have been merged with a |
298 |
+ # different value of sys.getfilesystemencoding(), |
299 |
+ # so fall back to utf_8 if appropriate. |
300 |
+ try: |
301 |
+ _unicode_encode(obj, encoding=_fs_encoding, errors='strict') |
302 |
+ except UnicodeEncodeError: |
303 |
+ pass |
304 |
+ else: |
305 |
+ os = portage.os |
306 |
+ |
307 |
file_data = pkgfiles[objkey] |
308 |
file_type = file_data[0] |
309 |
statobj = None |
310 |
@@ -3991,31 +4007,82 @@ |
311 |
max_dblnk = dblnk |
312 |
self._installed_instance = max_dblnk |
313 |
|
314 |
- myfilelist = [] |
315 |
- mylinklist = [] |
316 |
- paths_with_newlines = [] |
317 |
- srcroot_len = len(srcroot) |
318 |
- def onerror(e): |
319 |
- raise |
320 |
- for parent, dirs, files in os.walk(srcroot, onerror=onerror): |
321 |
- parent = portage._unicode_decode(parent, encoding=_merge_encoding) |
322 |
- for f in files: |
323 |
- f = portage._unicode_decode(f, encoding=_merge_encoding) |
324 |
- file_path = os.path.join(parent, f) |
325 |
- relative_path = file_path[srcroot_len:] |
326 |
+ # We check for unicode encoding issues after src_install. However, |
327 |
+ # the check must be repeated here for binary packages (it's |
328 |
+ # inexpensive since we call os.walk() here anyway). |
329 |
+ unicode_errors = [] |
330 |
|
331 |
- if "\n" in relative_path: |
332 |
- paths_with_newlines.append(relative_path) |
333 |
+ while True: |
334 |
|
335 |
- file_mode = os.lstat(file_path).st_mode |
336 |
- if stat.S_ISREG(file_mode): |
337 |
- myfilelist.append(relative_path) |
338 |
- elif stat.S_ISLNK(file_mode): |
339 |
- # Note: os.walk puts symlinks to directories in the "dirs" |
340 |
- # list and it does not traverse them since that could lead |
341 |
- # to an infinite recursion loop. |
342 |
- mylinklist.append(relative_path) |
343 |
+ unicode_error = False |
344 |
|
345 |
+ myfilelist = [] |
346 |
+ mylinklist = [] |
347 |
+ paths_with_newlines = [] |
348 |
+ srcroot_len = len(srcroot) |
349 |
+ def onerror(e): |
350 |
+ raise |
351 |
+ for parent, dirs, files in os.walk(srcroot, onerror=onerror): |
352 |
+ try: |
353 |
+ parent = _unicode_decode(parent, |
354 |
+ encoding=_merge_encoding, errors='strict') |
355 |
+ except UnicodeDecodeError: |
356 |
+ new_parent = _unicode_decode(parent, |
357 |
+ encoding=_merge_encoding, errors='replace') |
358 |
+ new_parent = _unicode_encode(new_parent, |
359 |
+ encoding=_merge_encoding, errors='backslashreplace') |
360 |
+ new_parent = _unicode_decode(new_parent, |
361 |
+ encoding=_merge_encoding, errors='replace') |
362 |
+ os.rename(parent, new_parent) |
363 |
+ unicode_error = True |
364 |
+ unicode_errors.append(new_parent[srcroot_len:]) |
365 |
+ break |
366 |
+ |
367 |
+ for fname in files: |
368 |
+ try: |
369 |
+ fname = _unicode_decode(fname, |
370 |
+ encoding=_merge_encoding, errors='strict') |
371 |
+ except UnicodeDecodeError: |
372 |
+ fpath = portage._os.path.join( |
373 |
+ parent.encode(_merge_encoding), fname) |
374 |
+ new_fname = _unicode_decode(fname, |
375 |
+ encoding=_merge_encoding, errors='replace') |
376 |
+ new_fname = _unicode_encode(new_fname, |
377 |
+ encoding=_merge_encoding, errors='backslashreplace') |
378 |
+ new_fname = _unicode_decode(new_fname, |
379 |
+ encoding=_merge_encoding, errors='replace') |
380 |
+ new_fpath = os.path.join(parent, new_fname) |
381 |
+ os.rename(fpath, new_fpath) |
382 |
+ unicode_error = True |
383 |
+ unicode_errors.append(new_fpath[srcroot_len:]) |
384 |
+ fname = new_fname |
385 |
+ fpath = new_fpath |
386 |
+ else: |
387 |
+ fpath = os.path.join(parent, fname) |
388 |
+ |
389 |
+ relative_path = fpath[srcroot_len:] |
390 |
+ |
391 |
+ if "\n" in relative_path: |
392 |
+ paths_with_newlines.append(relative_path) |
393 |
+ |
394 |
+ file_mode = os.lstat(fpath).st_mode |
395 |
+ if stat.S_ISREG(file_mode): |
396 |
+ myfilelist.append(relative_path) |
397 |
+ elif stat.S_ISLNK(file_mode): |
398 |
+ # Note: os.walk puts symlinks to directories in the "dirs" |
399 |
+ # list and it does not traverse them since that could lead |
400 |
+ # to an infinite recursion loop. |
401 |
+ mylinklist.append(relative_path) |
402 |
+ |
403 |
+ if unicode_error: |
404 |
+ break |
405 |
+ |
406 |
+ if not unicode_error: |
407 |
+ break |
408 |
+ |
409 |
+ if unicode_errors: |
410 |
+ eerror(portage._merge_unicode_error(unicode_errors)) |
411 |
+ |
412 |
if paths_with_newlines: |
413 |
msg = [] |
414 |
msg.append(_("This package installs one or more files containing a newline (\\n) character:")) |
415 |
|
416 |
Modified: main/branches/prefix/pym/portage/elog/__init__.py |
417 |
=================================================================== |
418 |
--- main/branches/prefix/pym/portage/elog/__init__.py 2009-08-24 06:25:30 UTC (rev 14135) |
419 |
+++ main/branches/prefix/pym/portage/elog/__init__.py 2009-08-24 09:20:57 UTC (rev 14136) |
420 |
@@ -14,9 +14,8 @@ |
421 |
from portage.elog.messages import collect_ebuild_messages, collect_messages |
422 |
from portage.elog.filtering import filter_loglevels |
423 |
from portage.localization import _ |
424 |
+from portage import os |
425 |
|
426 |
-import os |
427 |
- |
428 |
def _merge_logentries(a, b): |
429 |
rValue = {} |
430 |
phases = set(a) |
431 |
|
432 |
Modified: main/branches/prefix/pym/portage/elog/messages.py |
433 |
=================================================================== |
434 |
--- main/branches/prefix/pym/portage/elog/messages.py 2009-08-24 06:25:30 UTC (rev 14135) |
435 |
+++ main/branches/prefix/pym/portage/elog/messages.py 2009-08-24 09:20:57 UTC (rev 14136) |
436 |
@@ -11,9 +11,9 @@ |
437 |
|
438 |
from portage.const import EBUILD_PHASES |
439 |
from portage.localization import _ |
440 |
+from portage import os |
441 |
|
442 |
import codecs |
443 |
-import os |
444 |
import sys |
445 |
|
446 |
def collect_ebuild_messages(path): |
447 |
|
448 |
Modified: main/branches/prefix/pym/portage/elog/mod_mail_summary.py |
449 |
=================================================================== |
450 |
--- main/branches/prefix/pym/portage/elog/mod_mail_summary.py 2009-08-24 06:25:30 UTC (rev 14135) |
451 |
+++ main/branches/prefix/pym/portage/elog/mod_mail_summary.py 2009-08-24 09:20:57 UTC (rev 14136) |
452 |
@@ -3,11 +3,15 @@ |
453 |
# Distributed under the terms of the GNU General Public License v2 |
454 |
# $Id$ |
455 |
|
456 |
-import portage.mail, socket, os, time |
457 |
+import portage |
458 |
from portage.exception import PortageException |
459 |
from portage.localization import _ |
460 |
from portage.util import writemsg |
461 |
+from portage import os |
462 |
|
463 |
+import socket |
464 |
+import time |
465 |
+ |
466 |
_items = {} |
467 |
def process(mysettings, key, logentries, fulltext): |
468 |
global _items |
469 |
|
470 |
Modified: main/branches/prefix/pym/portage/elog/mod_save.py |
471 |
=================================================================== |
472 |
--- main/branches/prefix/pym/portage/elog/mod_save.py 2009-08-24 06:25:30 UTC (rev 14135) |
473 |
+++ main/branches/prefix/pym/portage/elog/mod_save.py 2009-08-24 09:20:57 UTC (rev 14136) |
474 |
@@ -4,7 +4,8 @@ |
475 |
# $Id$ |
476 |
|
477 |
import codecs |
478 |
-import os, time |
479 |
+import time |
480 |
+from portage import os |
481 |
from portage.data import portage_uid, portage_gid |
482 |
from portage.util import ensure_dirs |
483 |
from portage.const import EPREFIX |
484 |
|
485 |
Modified: main/branches/prefix/pym/portage/elog/mod_save_summary.py |
486 |
=================================================================== |
487 |
--- main/branches/prefix/pym/portage/elog/mod_save_summary.py 2009-08-24 06:25:30 UTC (rev 14135) |
488 |
+++ main/branches/prefix/pym/portage/elog/mod_save_summary.py 2009-08-24 09:20:57 UTC (rev 14136) |
489 |
@@ -4,7 +4,8 @@ |
490 |
# $Id$ |
491 |
|
492 |
import codecs |
493 |
-import os, time |
494 |
+import time |
495 |
+from portage import os |
496 |
from portage.data import portage_uid, portage_gid |
497 |
from portage.localization import _ |
498 |
from portage.util import ensure_dirs, apply_permissions |
499 |
|
500 |
Modified: main/branches/prefix/pym/portage/manifest.py |
501 |
=================================================================== |
502 |
--- main/branches/prefix/pym/portage/manifest.py 2009-08-24 06:25:30 UTC (rev 14135) |
503 |
+++ main/branches/prefix/pym/portage/manifest.py 2009-08-24 09:20:57 UTC (rev 14136) |
504 |
@@ -12,6 +12,8 @@ |
505 |
) |
506 |
|
507 |
from portage import os |
508 |
+from portage import _content_encoding |
509 |
+from portage import _fs_encoding |
510 |
from portage import _unicode_decode |
511 |
from portage import _unicode_encode |
512 |
from portage.exception import DigestException, FileNotFound, \ |
513 |
@@ -141,8 +143,9 @@ |
514 |
"""Parse a manifest. If myhashdict is given then data will be added too it. |
515 |
Otherwise, a new dict will be created and returned.""" |
516 |
try: |
517 |
- fd = codecs.open(_unicode_encode(file_path), mode='r', |
518 |
- encoding='utf_8', errors='replace') |
519 |
+ fd = codecs.open(_unicode_encode(file_path, |
520 |
+ encoding=_fs_encoding, errors='strict'), mode='r', |
521 |
+ encoding=_content_encoding, errors='replace') |
522 |
if myhashdict is None: |
523 |
myhashdict = {} |
524 |
self._parseDigests(fd, myhashdict=myhashdict, **kwargs) |
525 |
@@ -228,8 +231,9 @@ |
526 |
update_manifest = True |
527 |
if not force: |
528 |
try: |
529 |
- f = codecs.open(_unicode_encode(self.getFullname()), |
530 |
- mode='r', encoding='utf_8', errors='replace') |
531 |
+ f = codecs.open(_unicode_encode(self.getFullname(), |
532 |
+ encoding=_fs_encoding, errors='strict'), |
533 |
+ mode='r', encoding=_content_encoding, errors='replace') |
534 |
oldentries = list(self._parseManifestLines(f)) |
535 |
f.close() |
536 |
if len(oldentries) == len(myentries): |
537 |
@@ -320,7 +324,11 @@ |
538 |
for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir): |
539 |
break |
540 |
for f in pkgdir_files: |
541 |
- f = _unicode_decode(f) |
542 |
+ try: |
543 |
+ f = _unicode_decode(f, |
544 |
+ encoding=_fs_encoding, errors='strict') |
545 |
+ except UnicodeDecodeError: |
546 |
+ continue |
547 |
if f[:1] == ".": |
548 |
continue |
549 |
pf = None |
550 |
@@ -351,6 +359,11 @@ |
551 |
cut_len = len(os.path.join(pkgdir, "files") + os.sep) |
552 |
for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")): |
553 |
for f in files: |
554 |
+ try: |
555 |
+ f = _unicode_decode(f, |
556 |
+ encoding=_fs_encoding, errors='strict') |
557 |
+ except UnicodeDecodeError: |
558 |
+ continue |
559 |
full_path = os.path.join(parentdir, f) |
560 |
recursive_files.append(full_path[cut_len:]) |
561 |
for f in recursive_files: |
562 |
@@ -508,8 +521,9 @@ |
563 |
mfname = self.getFullname() |
564 |
if not os.path.exists(mfname): |
565 |
return rVal |
566 |
- myfile = codecs.open(_unicode_encode(mfname), |
567 |
- mode='r', encoding='utf_8', errors='replace') |
568 |
+ myfile = codecs.open(_unicode_encode(mfname, |
569 |
+ encoding=_fs_encoding, errors='strict'), |
570 |
+ mode='r', encoding=_content_encoding, errors='replace') |
571 |
lines = myfile.readlines() |
572 |
myfile.close() |
573 |
for l in lines: |
574 |
|
575 |
Modified: main/branches/prefix/pym/portage/sets/__init__.py |
576 |
=================================================================== |
577 |
--- main/branches/prefix/pym/portage/sets/__init__.py 2009-08-24 06:25:30 UTC (rev 14135) |
578 |
+++ main/branches/prefix/pym/portage/sets/__init__.py 2009-08-24 09:20:57 UTC (rev 14136) |
579 |
@@ -5,7 +5,7 @@ |
580 |
__all__ = ["SETPREFIX", "get_boolean", "SetConfigError", |
581 |
"SetConfig", "load_default_config"] |
582 |
|
583 |
-import os |
584 |
+from portage import os |
585 |
from ConfigParser import SafeConfigParser, NoOptionError |
586 |
from portage import load_mod |
587 |
from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH |
588 |
|
589 |
Modified: main/branches/prefix/pym/portage/sets/dbapi.py |
590 |
=================================================================== |
591 |
--- main/branches/prefix/pym/portage/sets/dbapi.py 2009-08-24 06:25:30 UTC (rev 14135) |
592 |
+++ main/branches/prefix/pym/portage/sets/dbapi.py 2009-08-24 09:20:57 UTC (rev 14136) |
593 |
@@ -2,6 +2,9 @@ |
594 |
# Distributed under the terms of the GNU General Public License v2 |
595 |
# $Id$ |
596 |
|
597 |
+import time |
598 |
+ |
599 |
+from portage import os |
600 |
from portage.versions import catpkgsplit, catsplit, pkgcmp, best |
601 |
from portage.dep import Atom |
602 |
from portage.localization import _ |
603 |
@@ -280,7 +283,6 @@ |
604 |
self._age = age |
605 |
|
606 |
def _filter(self, atom): |
607 |
- import time, os |
608 |
|
609 |
cpv = self._db.match(atom)[0] |
610 |
path = self._db.getpath(cpv, filename="COUNTER") |
611 |
|
612 |
Modified: main/branches/prefix/pym/portage/sets/files.py |
613 |
=================================================================== |
614 |
--- main/branches/prefix/pym/portage/sets/files.py 2009-08-24 06:25:30 UTC (rev 14135) |
615 |
+++ main/branches/prefix/pym/portage/sets/files.py 2009-08-24 09:20:57 UTC (rev 14136) |
616 |
@@ -2,10 +2,13 @@ |
617 |
# Distributed under the terms of the GNU General Public License v2 |
618 |
# $Id$ |
619 |
|
620 |
-import os |
621 |
import re |
622 |
from itertools import chain |
623 |
|
624 |
+from portage import os |
625 |
+from portage import _fs_encoding |
626 |
+from portage import _unicode_decode |
627 |
+from portage import _unicode_encode |
628 |
from portage.util import grabfile, write_atomic, ensure_dirs, normalize_path |
629 |
from portage.const import PRIVATE_PATH, USER_CONFIG_PATH, EPREFIX_LSTRIP |
630 |
from portage.localization import _ |
631 |
@@ -125,35 +128,43 @@ |
632 |
except KeyError: |
633 |
raise SetConfigError(_("Could not find repository '%s'") % match.groupdict()["reponame"]) |
634 |
|
635 |
+ try: |
636 |
+ directory = _unicode_decode(directory, |
637 |
+ encoding=_fs_encoding, errors='strict') |
638 |
+ # Now verify that we can also encode it. |
639 |
+ _unicode_encode(directory, |
640 |
+ encoding=_fs_encoding, errors='strict') |
641 |
+ except UnicodeError: |
642 |
+ directory = _unicode_decode(directory, |
643 |
+ encoding=_fs_encoding, errors='replace') |
644 |
+ raise SetConfigError( |
645 |
+ _("Directory path contains invalid character(s) for encoding '%s': '%s'") \ |
646 |
+ % (_fs_encoding, directory)) |
647 |
+ |
648 |
if os.path.isdir(directory): |
649 |
directory = normalize_path(directory) |
650 |
|
651 |
- if isinstance(directory, unicode): |
652 |
- # Avoid UnicodeDecodeError raised from |
653 |
- # os.path.join when called by os.walk. |
654 |
- directory_unicode = directory |
655 |
- directory = directory.encode('utf_8', 'replace') |
656 |
- else: |
657 |
- directory_unicode = unicode(directory, |
658 |
- encoding='utf_8', errors='replace') |
659 |
- |
660 |
for parent, dirs, files in os.walk(directory): |
661 |
- if not isinstance(parent, unicode): |
662 |
- parent = unicode(parent, |
663 |
- encoding='utf_8', errors='replace') |
664 |
+ try: |
665 |
+ parent = _unicode_decode(parent, |
666 |
+ encoding=_fs_encoding, errors='strict') |
667 |
+ except UnicodeDecodeError: |
668 |
+ continue |
669 |
for d in dirs[:]: |
670 |
if d[:1] == '.': |
671 |
dirs.remove(d) |
672 |
for filename in files: |
673 |
- if not isinstance(filename, unicode): |
674 |
- filename = unicode(filename, |
675 |
- encoding='utf_8', errors='replace') |
676 |
+ try: |
677 |
+ filename = _unicode_decode(filename, |
678 |
+ encoding=_fs_encoding, errors='strict') |
679 |
+ except UnicodeDecodeError: |
680 |
+ continue |
681 |
if filename[:1] == '.': |
682 |
continue |
683 |
if filename.endswith(".metadata"): |
684 |
continue |
685 |
filename = os.path.join(parent, |
686 |
- filename)[1 + len(directory_unicode):] |
687 |
+ filename)[1 + len(directory):] |
688 |
myname = name_pattern.replace("$name", filename) |
689 |
myname = myname.replace("${name}", filename) |
690 |
rValue[myname] = StaticFileSet( |
691 |
|
692 |
Modified: main/branches/prefix/pym/portage/sets/profiles.py |
693 |
=================================================================== |
694 |
--- main/branches/prefix/pym/portage/sets/profiles.py 2009-08-24 06:25:30 UTC (rev 14135) |
695 |
+++ main/branches/prefix/pym/portage/sets/profiles.py 2009-08-24 09:20:57 UTC (rev 14136) |
696 |
@@ -3,7 +3,8 @@ |
697 |
# $Id$ |
698 |
|
699 |
import logging |
700 |
-import os |
701 |
+ |
702 |
+from portage import os |
703 |
from portage.util import grabfile_package, stack_lists |
704 |
from portage.sets.base import PackageSet |
705 |
from portage.sets import get_boolean |
706 |
|
707 |
Modified: main/branches/prefix/pym/portage/sets/security.py |
708 |
=================================================================== |
709 |
--- main/branches/prefix/pym/portage/sets/security.py 2009-08-24 06:25:30 UTC (rev 14135) |
710 |
+++ main/branches/prefix/pym/portage/sets/security.py 2009-08-24 09:20:57 UTC (rev 14136) |
711 |
@@ -2,9 +2,7 @@ |
712 |
# Distributed under the terms of the GNU General Public License v2 |
713 |
# $Id$ |
714 |
|
715 |
-import os |
716 |
import portage.glsa as glsa |
717 |
-from portage.util import grabfile, write_atomic |
718 |
from portage.sets.base import PackageSet |
719 |
from portage.versions import catpkgsplit, pkgcmp |
720 |
from portage.sets import get_boolean |
721 |
|
722 |
Modified: main/branches/prefix/pym/portage/sets/shell.py |
723 |
=================================================================== |
724 |
--- main/branches/prefix/pym/portage/sets/shell.py 2009-08-24 06:25:30 UTC (rev 14135) |
725 |
+++ main/branches/prefix/pym/portage/sets/shell.py 2009-08-24 09:20:57 UTC (rev 14136) |
726 |
@@ -3,8 +3,9 @@ |
727 |
# $Id$ |
728 |
|
729 |
import subprocess |
730 |
-import os |
731 |
|
732 |
+from portage import os |
733 |
+from portage import _unicode_decode |
734 |
from portage.sets.base import PackageSet |
735 |
from portage.sets import SetConfigError |
736 |
|
737 |
@@ -35,8 +36,7 @@ |
738 |
pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True) |
739 |
stdout, stderr = pipe.communicate() |
740 |
if pipe.wait() == os.EX_OK: |
741 |
- self._setAtoms(unicode(stdout, |
742 |
- encoding='utf_8', errors='replace').splitlines()) |
743 |
+ self._setAtoms(_unicode_decode(stdout).splitlines()) |
744 |
|
745 |
def singleBuilder(self, options, settings, trees): |
746 |
if not "command" in options: |