Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r13923 - in main/branches/prefix/pym: _emerge portage portage/dbapi
Date: Wed, 05 Aug 2009 18:11:47
Message-Id: E1MYkxl-0002YQ-3T@stork.gentoo.org
1 Author: grobian
2 Date: 2009-08-05 18:11:44 +0000 (Wed, 05 Aug 2009)
3 New Revision: 13923
4
5 Modified:
6 main/branches/prefix/pym/_emerge/Binpkg.py
7 main/branches/prefix/pym/_emerge/BinpkgVerifier.py
8 main/branches/prefix/pym/_emerge/EbuildBuild.py
9 main/branches/prefix/pym/_emerge/EbuildFetcher.py
10 main/branches/prefix/pym/_emerge/EbuildPhase.py
11 main/branches/prefix/pym/_emerge/PackageUninstall.py
12 main/branches/prefix/pym/_emerge/changelog.py
13 main/branches/prefix/pym/_emerge/depgraph.py
14 main/branches/prefix/pym/_emerge/emergelog.py
15 main/branches/prefix/pym/_emerge/main.py
16 main/branches/prefix/pym/portage/__init__.py
17 main/branches/prefix/pym/portage/dbapi/bintree.py
18 main/branches/prefix/pym/portage/xpak.py
19 Log:
20 Merged from trunk -r13909:13919
21
22 | 13910 | Avoid UnicodeEncodeError with unicode package.mask comments. |
23 | zmedico | Thanks to Thanks to Scott Moreau (soreau) for reporting. |
24
25 | 13911 | Fix bindbapi.aux_get and aux_update to work with |
26 | zmedico | py3k/unicode. |
27
28 | 13912 | Open all files in binary mode for py3k compatibility. |
29 | zmedico | |
30
31 | 13913 | Open file in text mode (unicode) where appropriate. |
32 | zmedico | |
33
34 | 13914 | In _check_build_log(), open the log in text mode (unicode). |
35 | zmedico | |
36
37 | 13915 | Open ld.so.conf as text (unicode). |
38 | zmedico | |
39
40 | 13916 | Fix the FEATURES=parse-eapi-ebuild-head regex to handle |
41 | zmedico | comments on the same line, like this: EAPI=2 #foo Thanks to |
42 | | Markus Meier <maekke@g.o> for reporting. |
43
44 | 13917 | s/utf8/utf_8/ for consistency |
45 | zmedico | |
46
47 | 13919 | Fix insert_optional_args() to properly handle thinks like |
48 | zmedico | -Dk which require multiple substitutions of default |
49 | | arguments. |
50
51
52 Modified: main/branches/prefix/pym/_emerge/Binpkg.py
53 ===================================================================
54 --- main/branches/prefix/pym/_emerge/Binpkg.py 2009-08-05 18:10:06 UTC (rev 13922)
55 +++ main/branches/prefix/pym/_emerge/Binpkg.py 2009-08-05 18:11:44 UTC (rev 13923)
56 @@ -11,6 +11,7 @@
57 from _emerge.EbuildBuildDir import EbuildBuildDir
58 from portage.util import writemsg
59 # for an explanation on this logic, see pym/_emerge/__init__.py
60 +import codecs
61 import os
62 import sys
63 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
64 @@ -36,7 +37,8 @@
65
66 log_path = self.settings.get("PORTAGE_LOG_FILE")
67 if log_path is not None:
68 - f = open(log_path, 'a')
69 + f = codecs.open(log_path, mode='a',
70 + encoding='utf_8', errors='replace')
71 try:
72 f.write(msg)
73 finally:
74 @@ -229,7 +231,8 @@
75 else:
76 continue
77
78 - f = open(os.path.join(infloc, k), 'wb')
79 + f = codecs.open(os.path.join(infloc, k), mode='w',
80 + encoding='utf_8', errors='replace')
81 try:
82 f.write(v + "\n")
83 finally:
84
85 Modified: main/branches/prefix/pym/_emerge/BinpkgVerifier.py
86 ===================================================================
87 --- main/branches/prefix/pym/_emerge/BinpkgVerifier.py 2009-08-05 18:10:06 UTC (rev 13922)
88 +++ main/branches/prefix/pym/_emerge/BinpkgVerifier.py 2009-08-05 18:11:44 UTC (rev 13923)
89 @@ -6,6 +6,7 @@
90 from portage.util import writemsg
91 import sys
92 # for an explanation on this logic, see pym/_emerge/__init__.py
93 +import codecs
94 import os
95 import sys
96 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
97 @@ -31,7 +32,8 @@
98 stderr_orig = sys.stderr
99 log_file = None
100 if self.background and self.logfile is not None:
101 - log_file = open(self.logfile, 'a')
102 + log_file = codecs.open(self.logfile, mode='a',
103 + encoding='utf_8', errors='replace')
104 try:
105 if log_file is not None:
106 sys.stdout = log_file
107
108 Modified: main/branches/prefix/pym/_emerge/EbuildBuild.py
109 ===================================================================
110 --- main/branches/prefix/pym/_emerge/EbuildBuild.py 2009-08-05 18:10:06 UTC (rev 13922)
111 +++ main/branches/prefix/pym/_emerge/EbuildBuild.py 2009-08-05 18:11:44 UTC (rev 13923)
112 @@ -12,6 +12,7 @@
113 from _emerge.EbuildBuildDir import EbuildBuildDir
114 from portage.util import writemsg
115 # for an explanation on this logic, see pym/_emerge/__init__.py
116 +import codecs
117 import os
118 import sys
119 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
120 @@ -188,7 +189,8 @@
121
122 log_path = self.settings.get("PORTAGE_LOG_FILE")
123 if log_path is not None:
124 - log_file = open(log_path, 'a')
125 + log_file = codecs.open(log_path, mode='a',
126 + encoding='utf_8', errors='replace')
127 try:
128 log_file.write(msg)
129 finally:
130
131 Modified: main/branches/prefix/pym/_emerge/EbuildFetcher.py
132 ===================================================================
133 --- main/branches/prefix/pym/_emerge/EbuildFetcher.py 2009-08-05 18:10:06 UTC (rev 13922)
134 +++ main/branches/prefix/pym/_emerge/EbuildFetcher.py 2009-08-05 18:11:44 UTC (rev 13923)
135 @@ -12,6 +12,7 @@
136 else:
137 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "pym"))
138 import portage
139 +import codecs
140 import os
141 from portage.elog.messages import eerror
142 class EbuildFetcher(SpawnProcess):
143 @@ -92,7 +93,8 @@
144 elog_out = None
145 if self.logfile is not None:
146 if self.background:
147 - elog_out = open(self.logfile, 'a')
148 + elog_out = codecs.open(self.logfile, mode='a',
149 + encoding='utf_8', errors='replace')
150 msg = "Fetch failed for '%s'" % (self.pkg.cpv,)
151 if self.logfile is not None:
152 msg += ", Log file:"
153
154 Modified: main/branches/prefix/pym/_emerge/EbuildPhase.py
155 ===================================================================
156 --- main/branches/prefix/pym/_emerge/EbuildPhase.py 2009-08-05 18:10:06 UTC (rev 13922)
157 +++ main/branches/prefix/pym/_emerge/EbuildPhase.py 2009-08-05 18:11:44 UTC (rev 13923)
158 @@ -7,6 +7,7 @@
159 from _emerge.CompositeTask import CompositeTask
160 from portage.util import writemsg
161 # for an explanation on this logic, see pym/_emerge/__init__.py
162 +import codecs
163 import os
164 import sys
165 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
166 @@ -36,7 +37,8 @@
167 log_path = self.settings.get("PORTAGE_LOG_FILE")
168 log_file = None
169 if self.background and log_path is not None:
170 - log_file = open(log_path, 'a')
171 + log_file = codecs.open(log_path, mode='a',
172 + encoding='utf_8', errors='replace')
173 out = log_file
174 try:
175 portage._check_build_log(self.settings, out=out)
176
177 Modified: main/branches/prefix/pym/_emerge/PackageUninstall.py
178 ===================================================================
179 --- main/branches/prefix/pym/_emerge/PackageUninstall.py 2009-08-05 18:10:06 UTC (rev 13922)
180 +++ main/branches/prefix/pym/_emerge/PackageUninstall.py 2009-08-05 18:11:44 UTC (rev 13923)
181 @@ -2,6 +2,7 @@
182 # Distributed under the terms of the GNU General Public License v2
183 # $Id$
184
185 +import codecs
186 import logging
187 # for an explanation on this logic, see pym/_emerge/__init__.py
188 import os
189 @@ -46,7 +47,8 @@
190 portage.util.writemsg_level(msg,
191 level=level, noiselevel=noiselevel)
192
193 - f = open(log_path, 'a')
194 + f = codecs.open(log_path, mode='a',
195 + encoding='utf_8', errors='replace')
196 try:
197 f.write(msg)
198 finally:
199
200 Modified: main/branches/prefix/pym/_emerge/changelog.py
201 ===================================================================
202 --- main/branches/prefix/pym/_emerge/changelog.py 2009-08-05 18:10:06 UTC (rev 13922)
203 +++ main/branches/prefix/pym/_emerge/changelog.py 2009-08-05 18:11:44 UTC (rev 13923)
204 @@ -2,6 +2,7 @@
205 # Distributed under the terms of the GNU General Public License v2
206 # $Id$
207
208 +import codecs
209 import os
210 import re
211
212 @@ -25,7 +26,8 @@
213 next = next[:-3]
214 changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
215 try:
216 - changelog = open(changelogpath).read()
217 + changelog = codecs.open(changelogpath, mode='r',
218 + encoding='utf_8', errors='replace').read()
219 except SystemExit, e:
220 raise # Needed else can't exit
221 except:
222
223 Modified: main/branches/prefix/pym/_emerge/depgraph.py
224 ===================================================================
225 --- main/branches/prefix/pym/_emerge/depgraph.py 2009-08-05 18:10:06 UTC (rev 13922)
226 +++ main/branches/prefix/pym/_emerge/depgraph.py 2009-08-05 18:11:44 UTC (rev 13923)
227 @@ -4356,6 +4356,14 @@
228 if "--changelog" in self._frozen_config.myopts:
229 print
230 for revision,text in changelogs:
231 +
232 + if sys.hexversion < 0x3000000:
233 + # avoid potential UnicodeEncodeError
234 + if isinstance(revision, unicode):
235 + revision = revision.encode('utf_8', 'replace')
236 + if isinstance(text, unicode):
237 + text = text.encode('utf_8', 'replace')
238 +
239 print bold('*'+revision)
240 sys.stdout.write(text)
241
242 @@ -5113,6 +5121,11 @@
243 pass
244
245 print "- "+cpv+" (masked by: "+", ".join(mreasons)+")"
246 +
247 + if sys.hexversion < 0x3000000 and isinstance(comment, unicode):
248 + # avoid potential UnicodeEncodeError
249 + comment = comment.encode('utf_8', 'replace')
250 +
251 if comment and comment not in shown_comments:
252 print filename+":"
253 print comment
254
255 Modified: main/branches/prefix/pym/_emerge/emergelog.py
256 ===================================================================
257 --- main/branches/prefix/pym/_emerge/emergelog.py 2009-08-05 18:10:06 UTC (rev 13922)
258 +++ main/branches/prefix/pym/_emerge/emergelog.py 2009-08-05 18:11:44 UTC (rev 13923)
259 @@ -2,6 +2,7 @@
260 # Distributed under the terms of the GNU General Public License v2
261 # $Id$
262
263 +import codecs
264 import os
265 import sys
266 import time
267 @@ -27,7 +28,8 @@
268 xtermTitle(short_msg)
269 try:
270 file_path = os.path.join(_emerge_log_dir, 'emerge.log')
271 - mylogfile = open(file_path, "a")
272 + mylogfile = codecs.open(file_path, mode='a',
273 + encoding='utf_8', errors='replace')
274 portage.util.apply_secpass_permissions(file_path,
275 uid=portage.portage_uid, gid=portage.portage_gid,
276 mode=0660)
277
278 Modified: main/branches/prefix/pym/_emerge/main.py
279 ===================================================================
280 --- main/branches/prefix/pym/_emerge/main.py 2009-08-05 18:10:06 UTC (rev 13922)
281 +++ main/branches/prefix/pym/_emerge/main.py 2009-08-05 18:11:44 UTC (rev 13923)
282 @@ -487,7 +487,9 @@
283 new_args.append(opt_arg)
284
285 if saved_opts is not None:
286 - new_args.append("-" + saved_opts)
287 + # Recycle these on arg_stack since they
288 + # might contain another match.
289 + arg_stack.append("-" + saved_opts)
290
291 return new_args
292
293
294 Modified: main/branches/prefix/pym/portage/__init__.py
295 ===================================================================
296 --- main/branches/prefix/pym/portage/__init__.py 2009-08-05 18:10:06 UTC (rev 13922)
297 +++ main/branches/prefix/pym/portage/__init__.py 2009-08-05 18:11:44 UTC (rev 13923)
298 @@ -727,7 +727,8 @@
299
300 ldsoconf_path = os.path.join(target_root, EPREFIX_LSTRIP, "etc", "ld.so.conf")
301 try:
302 - myld = open(ldsoconf_path)
303 + myld = codecs.open(ldsoconf_path, mode='r',
304 + encoding='utf_8', errors='replace')
305 myldlines=myld.readlines()
306 myld.close()
307 oldld=[]
308 @@ -5034,7 +5035,8 @@
309 if logfile is None:
310 return
311 try:
312 - f = open(logfile)
313 + f = codecs.open(logfile, mode='r',
314 + encoding='utf_8', errors='replace')
315 except EnvironmentError:
316 return
317
318 @@ -5295,7 +5297,7 @@
319 # the ebuild.
320 _validate_cache_for_unsupported_eapis = True
321
322 -_parse_eapi_ebuild_head_re = re.compile(r'^EAPI=[\'"]?([^\'"]*)')
323 +_parse_eapi_ebuild_head_re = re.compile(r'^EAPI=[\'"]?([^\'"#]*)')
324 _parse_eapi_ebuild_head_max_lines = 30
325
326 def _parse_eapi_ebuild_head(f):
327
328 Modified: main/branches/prefix/pym/portage/dbapi/bintree.py
329 ===================================================================
330 --- main/branches/prefix/pym/portage/dbapi/bintree.py 2009-08-05 18:10:06 UTC (rev 13922)
331 +++ main/branches/prefix/pym/portage/dbapi/bintree.py 2009-08-05 18:11:44 UTC (rev 13923)
332 @@ -25,6 +25,7 @@
333 import codecs
334 import os, errno, stat
335 import re
336 +import sys
337 from itertools import chain, izip
338
339 class bindbapi(fakedbapi):
340 @@ -68,7 +69,12 @@
341 tbz2_path = self.bintree.getname(mycpv)
342 if not os.path.exists(tbz2_path):
343 raise KeyError(mycpv)
344 - getitem = portage.xpak.tbz2(tbz2_path).getfile
345 + tbz2 = portage.xpak.tbz2(tbz2_path)
346 + def getitem(k):
347 + v = tbz2.getfile(k)
348 + if v is not None and not isinstance(v, unicode):
349 + v = unicode(v, encoding='utf_8', errors='replace')
350 + return v
351 else:
352 getitem = self.bintree._remotepkgs[mycpv].get
353 mydata = {}
354 @@ -81,15 +87,16 @@
355 # or the tbz2 is corrupt.
356 if myval:
357 mydata[x] = " ".join(myval.split())
358 - if "EAPI" in mykeys:
359 - if not mydata.setdefault("EAPI", "0"):
360 - mydata["EAPI"] = "0"
361 +
362 + if not mydata.setdefault('EAPI', u'0'):
363 + mydata['EAPI'] = u'0'
364 +
365 if cache_me:
366 aux_cache = self._aux_cache_slot_dict()
367 for x in self._aux_cache_keys:
368 - aux_cache[x] = mydata.get(x, "")
369 + aux_cache[x] = mydata.get(x, u'')
370 self._aux_cache[mycpv] = aux_cache
371 - return [mydata.get(x, "") for x in wants]
372 + return [mydata.get(x, u'') for x in wants]
373
374 def aux_update(self, cpv, values):
375 if not self.bintree.populated:
376 @@ -99,7 +106,23 @@
377 raise KeyError(cpv)
378 mytbz2 = portage.xpak.tbz2(tbz2path)
379 mydata = mytbz2.get_data()
380 - mydata.update(values)
381 +
382 + if sys.hexversion < 0x3000000:
383 + for k, v in values.iteritems():
384 + if isinstance(k, unicode):
385 + k = k.encode('utf_8', 'replace')
386 + if isinstance(v, unicode):
387 + v = v.encode('utf_8', 'replace')
388 + mydata[k] = v
389 +
390 + else:
391 + for k, v in values.iteritems():
392 + if isinstance(k, str):
393 + k = k.encode('utf_8', 'replace')
394 + if isinstance(v, str):
395 + v = v.encode('utf_8', 'replace')
396 + mydata[k] = v
397 +
398 for k, v in mydata.items():
399 if not v:
400 del mydata[k]
401 @@ -1083,7 +1106,7 @@
402 pkgindex = self._new_pkgindex()
403 try:
404 f = codecs.open(self._pkgindex_file,
405 - encoding='utf8', errors='replace')
406 + encoding='utf_8', errors='replace')
407 except EnvironmentError:
408 pass
409 else:
410
411 Modified: main/branches/prefix/pym/portage/xpak.py
412 ===================================================================
413 --- main/branches/prefix/pym/portage/xpak.py 2009-08-05 18:10:06 UTC (rev 13922)
414 +++ main/branches/prefix/pym/portage/xpak.py 2009-08-05 18:11:44 UTC (rev 13923)
415 @@ -68,14 +68,14 @@
416 mylist.sort()
417 mydata = {}
418 for x in mylist:
419 - a = open(x, "r")
420 + a = open(x, 'rb')
421 mydata[x] = a.read()
422 a.close()
423 os.chdir(origdir)
424
425 xpak_segment = xpak_mem(mydata)
426 if outfile:
427 - outf = open(outfile, "w")
428 + outf = open(outfile, 'wb')
429 outf.write(xpak_segment)
430 outf.close()
431 else:
432 @@ -104,7 +104,7 @@
433 """(infile) -- Splits the infile into two files.
434 'infile.index' contains the index segment.
435 'infile.dat' contails the data segment."""
436 - myfile=open(infile,"r")
437 + myfile = open(infile, 'rb')
438 mydat=myfile.read()
439 myfile.close()
440
441 @@ -112,10 +112,10 @@
442 if not splits:
443 return False
444
445 - myfile=open(infile+".index","w")
446 + myfile = open(infile + '.index', 'wb')
447 myfile.write(splits[0])
448 myfile.close()
449 - myfile=open(infile+".dat","w")
450 + myfile = open(infile + '.dat', 'wb')
451 myfile.write(splits[1])
452 myfile.close()
453 return True
454 @@ -130,7 +130,7 @@
455
456 def getindex(infile):
457 """(infile) -- grabs the index segment from the infile and returns it."""
458 - myfile=open(infile,"r")
459 + myfile = open(infile, 'rb')
460 myheader=myfile.read(16)
461 if myheader[0:8]!="XPAKPACK":
462 myfile.close()
463 @@ -143,7 +143,7 @@
464 def getboth(infile):
465 """(infile) -- grabs the index and data segments from the infile.
466 Returns an array [indexSegment,dataSegment]"""
467 - myfile=open(infile,"r")
468 + myfile = open(infile, 'rb')
469 myheader=myfile.read(16)
470 if myheader[0:8]!="XPAKPACK":
471 myfile.close()
472 @@ -217,7 +217,7 @@
473 if dirname:
474 if not os.path.exists(dirname):
475 os.makedirs(dirname)
476 - mydat=open(myname,"w")
477 + mydat = open(myname, 'wb')
478 mydat.write(mydata[datapos:datapos+datalen])
479 mydat.close()
480 startpos=startpos+namelen+12
481 @@ -262,7 +262,7 @@
482
483 def recompose_mem(self, xpdata):
484 self.scan() # Don't care about condition... We'll rewrite the data anyway.
485 - myfile=open(self.file,"a+")
486 + myfile = open(self.file, 'ab+')
487 if not myfile:
488 raise IOError
489 myfile.seek(-self.xpaksize,2) # 0,2 or -0,2 just mean EOF.
490 @@ -298,7 +298,7 @@
491 if not changed:
492 return 1
493 self.filestat=mystat
494 - a=open(self.file,"r")
495 + a = open(self.file, 'rb')
496 a.seek(-16,2)
497 trailer=a.read()
498 self.infosize=0
499 @@ -341,7 +341,7 @@
500 myresult=searchindex(self.index,myfile)
501 if not myresult:
502 return mydefault
503 - a=open(self.file,"r")
504 + a = open(self.file, 'rb')
505 a.seek(self.datapos+myresult[0],0)
506 myreturn=a.read(myresult[1])
507 a.close()
508 @@ -365,7 +365,7 @@
509 except:
510 os.chdir("/")
511 origdir="/"
512 - a=open(self.file,"r")
513 + a = open(self.file, 'rb')
514 if not os.path.exists(mydest):
515 os.makedirs(mydest)
516 os.chdir(mydest)
517 @@ -379,7 +379,7 @@
518 if dirname:
519 if not os.path.exists(dirname):
520 os.makedirs(dirname)
521 - mydat=open(myname,"w")
522 + mydat = open(myname, 'wb')
523 a.seek(self.datapos+datapos)
524 mydat.write(a.read(datalen))
525 mydat.close()
526 @@ -392,7 +392,7 @@
527 """Returns all the files from the dataSegment as a map object."""
528 if not self.scan():
529 return 0
530 - a = open(self.file, "r")
531 + a = open(self.file, 'rb')
532 mydata = {}
533 startpos=0
534 while ((startpos+8)<self.indexsize):
535 @@ -411,7 +411,7 @@
536 if not self.scan():
537 return None
538
539 - a = open(self.file,"r")
540 + a = open(self.file, 'rb')
541 a.seek(self.datapos)
542 mydata =a.read(self.datasize)
543 a.close()