1 |
Author: zmedico |
2 |
Date: 2009-09-29 06:04:42 +0000 (Tue, 29 Sep 2009) |
3 |
New Revision: 14461 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/Binpkg.py |
7 |
main/trunk/pym/portage/__init__.py |
8 |
main/trunk/pym/portage/dbapi/bintree.py |
9 |
Log: |
10 |
Handle encoding/decoding of unicode when using the xpak api. |
11 |
Use tbz2.get_data() instead of tbz2.getfile() when reading multiple values, |
12 |
in order to avoid multiple tbz2.scan() and searchindex() calls. |
13 |
|
14 |
|
15 |
Modified: main/trunk/pym/_emerge/Binpkg.py |
16 |
=================================================================== |
17 |
--- main/trunk/pym/_emerge/Binpkg.py 2009-09-29 05:56:39 UTC (rev 14460) |
18 |
+++ main/trunk/pym/_emerge/Binpkg.py 2009-09-29 06:04:42 UTC (rev 14461) |
19 |
@@ -215,7 +215,8 @@ |
20 |
check_missing_metadata = ("CATEGORY", "PF") |
21 |
missing_metadata = set() |
22 |
for k in check_missing_metadata: |
23 |
- v = pkg_xpak.getfile(k) |
24 |
+ v = pkg_xpak.getfile(_unicode_encode(k, |
25 |
+ encoding=_encodings['repo.content'])) |
26 |
if not v: |
27 |
missing_metadata.add(k) |
28 |
|
29 |
|
30 |
Modified: main/trunk/pym/portage/__init__.py |
31 |
=================================================================== |
32 |
--- main/trunk/pym/portage/__init__.py 2009-09-29 05:56:39 UTC (rev 14460) |
33 |
+++ main/trunk/pym/portage/__init__.py 2009-09-29 06:04:42 UTC (rev 14461) |
34 |
@@ -8573,11 +8573,14 @@ |
35 |
|
36 |
mypkg = os.path.basename(mytbz2)[:-5] |
37 |
xptbz2 = portage.xpak.tbz2(mytbz2) |
38 |
- mycat = xptbz2.getfile("CATEGORY") |
39 |
+ mycat = xptbz2.getfile(_unicode_encode("CATEGORY", |
40 |
+ encoding=_encodings['repo.content'])) |
41 |
if not mycat: |
42 |
writemsg(_("!!! CATEGORY info missing from info chunk, aborting...\n"), |
43 |
noiselevel=-1) |
44 |
return 1 |
45 |
+ mycat = _unicode_decode(mycat, |
46 |
+ encoding=_encodings['repo.content'], errors='replace') |
47 |
mycat = mycat.strip() |
48 |
|
49 |
# These are the same directories that would be used at build time. |
50 |
|
51 |
Modified: main/trunk/pym/portage/dbapi/bintree.py |
52 |
=================================================================== |
53 |
--- main/trunk/pym/portage/dbapi/bintree.py 2009-09-29 05:56:39 UTC (rev 14460) |
54 |
+++ main/trunk/pym/portage/dbapi/bintree.py 2009-09-29 06:04:42 UTC (rev 14461) |
55 |
@@ -78,9 +78,11 @@ |
56 |
tbz2_path = self.bintree.getname(mycpv) |
57 |
if not os.path.exists(tbz2_path): |
58 |
raise KeyError(mycpv) |
59 |
- tbz2 = portage.xpak.tbz2(tbz2_path) |
60 |
+ metadata_bytes = portage.xpak.tbz2(tbz2_path).get_data() |
61 |
def getitem(k): |
62 |
- v = tbz2.getfile(k) |
63 |
+ v = metadata_bytes.get(_unicode_encode(k, |
64 |
+ encoding=_encodings['repo.content'], |
65 |
+ errors='backslashreplace')) |
66 |
if v is not None: |
67 |
v = _unicode_decode(v, |
68 |
encoding=_encodings['repo.content'], errors='replace') |
69 |
@@ -377,8 +379,12 @@ |
70 |
|
71 |
if st is not None: |
72 |
# For invalid packages, other_cat could be None. |
73 |
- other_cat = portage.xpak.tbz2(dest_path).getfile("CATEGORY") |
74 |
+ other_cat = portage.xpak.tbz2(dest_path).getfile( |
75 |
+ _unicode_encode("CATEGORY", |
76 |
+ encoding=_encodings['repo.content'])) |
77 |
if other_cat: |
78 |
+ other_cat = _unicode_decode(other_cat, |
79 |
+ encoding=_encodings['repo.content'], errors='replace') |
80 |
other_cat = other_cat.strip() |
81 |
other_cpv = other_cat + "/" + mypkg |
82 |
self._move_from_all(other_cpv) |
83 |
@@ -546,11 +552,19 @@ |
84 |
noiselevel=-1) |
85 |
self.invalids.append(myfile[:-5]) |
86 |
continue |
87 |
- mytbz2 = portage.xpak.tbz2(full_path) |
88 |
- # For invalid packages, mycat could be None. |
89 |
- mycat = mytbz2.getfile("CATEGORY") |
90 |
- mypf = mytbz2.getfile("PF") |
91 |
- slot = mytbz2.getfile("SLOT") |
92 |
+ metadata_bytes = portage.xpak.tbz2(full_path).get_data() |
93 |
+ mycat = _unicode_decode(metadata_bytes.get( |
94 |
+ _unicode_encode("CATEGORY", |
95 |
+ encoding=_encodings['repo.content']), ""), |
96 |
+ encoding=_encodings['repo.content'], errors='replace') |
97 |
+ mypf = _unicode_decode(metadata_bytes.get( |
98 |
+ _unicode_encode("PF", |
99 |
+ encoding=_encodings['repo.content']), ""), |
100 |
+ encoding=_encodings['repo.content'], errors='replace') |
101 |
+ slot = _unicode_decode(metadata_bytes.get( |
102 |
+ _unicode_encode("SLOT", |
103 |
+ encoding=_encodings['repo.content']), ""), |
104 |
+ encoding=_encodings['repo.content'], errors='replace') |
105 |
mypkg = myfile[:-5] |
106 |
if not mycat or not mypf or not slot: |
107 |
#old-style or corrupt package |