Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r15485 - in main/branches/prefix: bin pym/_emerge pym/portage
Date: Sat, 27 Feb 2010 20:12:00
Message-Id: E1NlT12-0003RZ-N0@stork.gentoo.org
1 Author: grobian
2 Date: 2010-02-27 20:11:56 +0000 (Sat, 27 Feb 2010)
3 New Revision: 15485
4
5 Added:
6 main/branches/prefix/pym/portage/_ensure_encodings.py
7 main/branches/prefix/pym/portage/_global_updates.py
8 Modified:
9 main/branches/prefix/bin/fixpackages
10 main/branches/prefix/bin/repoman
11 main/branches/prefix/pym/_emerge/actions.py
12 main/branches/prefix/pym/_emerge/clear_caches.py
13 main/branches/prefix/pym/_emerge/main.py
14 main/branches/prefix/pym/portage/__init__.py
15 Log:
16 Merged from trunk -r15470:15477
17
18 | 15471 | Bug #307021 - Show "Please fix" message in red instead of |
19 | zmedico | turquoise when repoman fails. |
20
21 | 15472 | Another turquoise -> red. |
22 | zmedico | |
23
24 | 15473 | Move missing encodings module workarounds (<python-2.6.4 + |
25 | zmedico | USE=build) to a _ensure_encodings module that's only |
26 | | imported on demand. |
27
28 | 15474 | Remove unused 'dircache' variable that's moved to |
29 | zmedico | portage.util.listdir. |
30
31 | 15475 | Move portage._global_updates to a submodule. |
32 | zmedico | |
33
34 | 15476 | Remove deprecated flushmtimedb function. |
35 | zmedico | |
36
37 | 15477 | Fix reference to portage.util.listdir.dircache. |
38 | zmedico | |
39
40
41 Modified: main/branches/prefix/bin/fixpackages
42 ===================================================================
43 --- main/branches/prefix/bin/fixpackages 2010-02-27 20:02:45 UTC (rev 15484)
44 +++ main/branches/prefix/bin/fixpackages 2010-02-27 20:11:56 UTC (rev 15485)
45 @@ -9,6 +9,7 @@
46 os.environ["PORTAGE_CALLER"]="fixpackages"
47
48 from portage import os
49 +from portage._global_updates import _global_updates
50 mysettings = portage.settings
51 mytrees = portage.db
52 mtimedb = portage.mtimedb
53 @@ -21,7 +22,7 @@
54 portage.writemsg("!!! %s\n" % str(e))
55 del e
56
57 -portage._global_updates(mytrees, mtimedb["updates"])
58 +_global_updates(mytrees, mtimedb["updates"])
59
60 print()
61 print("Done.")
62
63 Modified: main/branches/prefix/bin/repoman
64 ===================================================================
65 --- main/branches/prefix/bin/repoman 2010-02-27 20:02:45 UTC (rev 15484)
66 +++ main/branches/prefix/bin/repoman 2010-02-27 20:11:56 UTC (rev 15485)
67 @@ -1956,7 +1956,7 @@
68 elif not dofail:
69 print(green("RepoMan sez:"),"\"If everyone were like you, I'd be out of business!\"")
70 elif dofail:
71 - print(turquoise("Please fix these important QA issues first."))
72 + print(bad("Please fix these important QA issues first."))
73 print(green("RepoMan sez:"),"\"Make your QA payment on time and you'll never see the likes of me.\"\n")
74 sys.exit(1)
75 else:
76 @@ -1967,7 +1967,7 @@
77 elif dofail:
78 if options.force and not can_force:
79 print(bad("The --force option has been disabled due to extraordinary issues."))
80 - print(turquoise("Please fix these important QA issues first."))
81 + print(bad("Please fix these important QA issues first."))
82 print(green("RepoMan sez:"),"\"Make your QA payment on time and you'll never see the likes of me.\"\n")
83 sys.exit(1)
84
85
86 Modified: main/branches/prefix/pym/_emerge/actions.py
87 ===================================================================
88 --- main/branches/prefix/pym/_emerge/actions.py 2010-02-27 20:02:45 UTC (rev 15484)
89 +++ main/branches/prefix/pym/_emerge/actions.py 2010-02-27 20:11:56 UTC (rev 15485)
90 @@ -35,6 +35,7 @@
91 from portage.sets import load_default_config, SETPREFIX
92 from portage.sets.base import InternalPackageSet
93 from portage.util import cmp_sort_key, writemsg, writemsg_level
94 +from portage._global_updates import _global_updates
95
96 from _emerge.clear_caches import clear_caches
97 from _emerge.countdown import countdown
98 @@ -2207,7 +2208,7 @@
99 # the only one that's been synced here.
100 action_metadata(settings, portdb, myopts, porttrees=[myportdir])
101
102 - if portage._global_updates(trees, mtimedb["updates"]):
103 + if _global_updates(trees, mtimedb["updates"]):
104 mtimedb.commit()
105 # Reload the whole config from scratch.
106 settings, trees, mtimedb = load_emerge_config(trees=trees)
107
108 Modified: main/branches/prefix/pym/_emerge/clear_caches.py
109 ===================================================================
110 --- main/branches/prefix/pym/_emerge/clear_caches.py 2010-02-27 20:02:45 UTC (rev 15484)
111 +++ main/branches/prefix/pym/_emerge/clear_caches.py 2010-02-27 20:11:56 UTC (rev 15485)
112 @@ -4,6 +4,7 @@
113
114 import gc
115 import portage
116 +from portage.util.listdir import dircache
117
118 def clear_caches(trees):
119 for d in trees.values():
120 @@ -12,5 +13,5 @@
121 d["bintree"].dbapi._aux_cache.clear()
122 d["bintree"].dbapi._clear_cache()
123 d["vartree"].dbapi.linkmap._clear_cache()
124 - portage.dircache.clear()
125 + dircache.clear()
126 gc.collect()
127
128 Modified: main/branches/prefix/pym/_emerge/main.py
129 ===================================================================
130 --- main/branches/prefix/pym/_emerge/main.py 2010-02-27 20:02:45 UTC (rev 15484)
131 +++ main/branches/prefix/pym/_emerge/main.py 2010-02-27 20:11:56 UTC (rev 15485)
132 @@ -37,6 +37,7 @@
133 from portage.util import normalize_path as normpath
134 from portage.util import writemsg, writemsg_level, writemsg_stdout
135 from portage.sets import SETPREFIX
136 +from portage._global_updates import _global_updates
137
138 from _emerge.actions import action_config, action_sync, action_metadata, \
139 action_regen, action_search, action_uninstall, action_info, action_build, \
140 @@ -1185,7 +1186,7 @@
141 return rval
142
143 if myaction not in ('help', 'info', 'version') and \
144 - portage._global_updates(trees, mtimedb["updates"]):
145 + _global_updates(trees, mtimedb["updates"]):
146 mtimedb.commit()
147 # Reload the whole config from scratch.
148 settings, trees, mtimedb = load_emerge_config(trees=trees)
149
150 Modified: main/branches/prefix/pym/portage/__init__.py
151 ===================================================================
152 --- main/branches/prefix/pym/portage/__init__.py 2010-02-27 20:02:45 UTC (rev 15484)
153 +++ main/branches/prefix/pym/portage/__init__.py 2010-02-27 20:11:56 UTC (rev 15485)
154 @@ -331,89 +331,8 @@
155 # END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END
156 # ===========================================================================
157
158 -def _gen_missing_encodings(missing_encodings):
159 -
160 - encodings = {}
161 -
162 - if 'ascii' in missing_encodings:
163 -
164 - class AsciiIncrementalEncoder(codecs.IncrementalEncoder):
165 - def encode(self, input, final=False):
166 - return codecs.ascii_encode(input, self.errors)[0]
167 -
168 - class AsciiIncrementalDecoder(codecs.IncrementalDecoder):
169 - def decode(self, input, final=False):
170 - return codecs.ascii_decode(input, self.errors)[0]
171 -
172 - class AsciiStreamWriter(codecs.StreamWriter):
173 - encode = codecs.ascii_encode
174 -
175 - class AsciiStreamReader(codecs.StreamReader):
176 - decode = codecs.ascii_decode
177 -
178 - codec_info = codecs.CodecInfo(
179 - name='ascii',
180 - encode=codecs.ascii_encode,
181 - decode=codecs.ascii_decode,
182 - incrementalencoder=AsciiIncrementalEncoder,
183 - incrementaldecoder=AsciiIncrementalDecoder,
184 - streamwriter=AsciiStreamWriter,
185 - streamreader=AsciiStreamReader,
186 - )
187 -
188 - for alias in ('ascii', '646', 'ansi_x3.4_1968', 'ansi_x3_4_1968',
189 - 'ansi_x3.4_1986', 'cp367', 'csascii', 'ibm367', 'iso646_us',
190 - 'iso_646.irv_1991', 'iso_ir_6', 'us', 'us_ascii'):
191 - encodings[alias] = codec_info
192 -
193 - if 'utf_8' in missing_encodings:
194 -
195 - def utf8decode(input, errors='strict'):
196 - return codecs.utf_8_decode(input, errors, True)
197 -
198 - class Utf8IncrementalEncoder(codecs.IncrementalEncoder):
199 - def encode(self, input, final=False):
200 - return codecs.utf_8_encode(input, self.errors)[0]
201 -
202 - class Utf8IncrementalDecoder(codecs.BufferedIncrementalDecoder):
203 - _buffer_decode = codecs.utf_8_decode
204 -
205 - class Utf8StreamWriter(codecs.StreamWriter):
206 - encode = codecs.utf_8_encode
207 -
208 - class Utf8StreamReader(codecs.StreamReader):
209 - decode = codecs.utf_8_decode
210 -
211 - codec_info = codecs.CodecInfo(
212 - name='utf-8',
213 - encode=codecs.utf_8_encode,
214 - decode=utf8decode,
215 - incrementalencoder=Utf8IncrementalEncoder,
216 - incrementaldecoder=Utf8IncrementalDecoder,
217 - streamreader=Utf8StreamReader,
218 - streamwriter=Utf8StreamWriter,
219 - )
220 -
221 - for alias in ('utf_8', 'u8', 'utf', 'utf8', 'utf8_ucs2', 'utf8_ucs4'):
222 - encodings[alias] = codec_info
223 -
224 - return encodings
225 -
226 def _ensure_default_encoding():
227 - """
228 - The python that's inside stage 1 or 2 is built with a minimal
229 - configuration which does not include the /usr/lib/pythonX.Y/encodings
230 - directory. This results in error like the following:
231
232 - LookupError: no codec search functions registered: can't find encoding
233 -
234 - In order to solve this problem, detect it early and manually register
235 - a search function for the ascii and utf_8 codecs. Starting with python-3.0
236 - this problem is more noticeable because of stricter handling of encoding
237 - and decoding between strings of characters and bytes.
238 - """
239 -
240 - default_fallback = 'utf_8'
241 default_encoding = sys.getdefaultencoding().lower().replace('-', '_')
242 filesystem_encoding = _encodings['merge'].lower().replace('-', '_')
243 required_encodings = set(['ascii', 'utf_8'])
244 @@ -429,50 +348,10 @@
245 if not missing_encodings:
246 return
247
248 - encodings = _gen_missing_encodings(missing_encodings)
249 + from portage import _ensure_encodings
250 + _ensure_encodings._setup_encodings(default_encoding,
251 + filesystem_encoding, missing_encodings)
252
253 - if default_encoding in missing_encodings and \
254 - default_encoding not in encodings:
255 - # Make the fallback codec correspond to whatever name happens
256 - # to be returned by sys.getfilesystemencoding().
257 -
258 - try:
259 - encodings[default_encoding] = codecs.lookup(default_fallback)
260 - except LookupError:
261 - encodings[default_encoding] = encodings[default_fallback]
262 -
263 - if filesystem_encoding in missing_encodings and \
264 - filesystem_encoding not in encodings:
265 - # Make the fallback codec correspond to whatever name happens
266 - # to be returned by sys.getdefaultencoding().
267 -
268 - try:
269 - encodings[filesystem_encoding] = codecs.lookup(default_fallback)
270 - except LookupError:
271 - encodings[filesystem_encoding] = encodings[default_fallback]
272 -
273 - def search_function(name):
274 - name = name.lower()
275 - name = name.replace('-', '_')
276 - codec_info = encodings.get(name)
277 - if codec_info is not None:
278 - return codecs.CodecInfo(
279 - name=codec_info.name,
280 - encode=codec_info.encode,
281 - decode=codec_info.decode,
282 - incrementalencoder=codec_info.incrementalencoder,
283 - incrementaldecoder=codec_info.incrementaldecoder,
284 - streamreader=codec_info.streamreader,
285 - streamwriter=codec_info.streamwriter,
286 - )
287 - return None
288 -
289 - codecs.register(search_function)
290 -
291 - del codec_name, default_encoding, default_fallback, \
292 - filesystem_encoding, missing_encodings, \
293 - required_encodings, search_function
294 -
295 # Do this ASAP since writemsg() might not work without it.
296 _ensure_default_encoding()
297
298 @@ -685,146 +564,6 @@
299
300 atexit_register(portageexit)
301
302 -def _global_updates(trees, prev_mtimes):
303 - """
304 - Perform new global updates if they exist in $PORTDIR/profiles/updates/.
305 -
306 - @param trees: A dictionary containing portage trees.
307 - @type trees: dict
308 - @param prev_mtimes: A dictionary containing mtimes of files located in
309 - $PORTDIR/profiles/updates/.
310 - @type prev_mtimes: dict
311 - @rtype: None or List
312 - @return: None if no were no updates, otherwise a list of update commands
313 - that have been performed.
314 - """
315 - # only do this if we're root and not running repoman/ebuild digest
316 - global secpass
317 - if secpass < 2 or "SANDBOX_ACTIVE" in os.environ:
318 - return
319 - root = "/"
320 - mysettings = trees["/"]["vartree"].settings
321 - updpath = os.path.join(mysettings["PORTDIR"], "profiles", "updates")
322 -
323 - try:
324 - if mysettings["PORTAGE_CALLER"] == "fixpackages":
325 - update_data = grab_updates(updpath)
326 - else:
327 - update_data = grab_updates(updpath, prev_mtimes)
328 - except portage.exception.DirectoryNotFound:
329 - writemsg(_("--- 'profiles/updates' is empty or "
330 - "not available. Empty portage tree?\n"), noiselevel=1)
331 - return
332 - myupd = None
333 - if len(update_data) > 0:
334 - do_upgrade_packagesmessage = 0
335 - myupd = []
336 - timestamps = {}
337 - for mykey, mystat, mycontent in update_data:
338 - writemsg_stdout("\n\n")
339 - writemsg_stdout(colorize("GOOD",
340 - _("Performing Global Updates: "))+bold(mykey)+"\n")
341 - writemsg_stdout(_("(Could take a couple of minutes if you have a lot of binary packages.)\n"))
342 - writemsg_stdout(_(" %s='update pass' %s='binary update' "
343 - "%s='/var/db update' %s='/var/db move'\n"
344 - " %s='/var/db SLOT move' %s='binary move' "
345 - "%s='binary SLOT move'\n %s='update /etc/portage/package.*'\n") % \
346 - (bold("."), bold("*"), bold("#"), bold("@"), bold("s"), bold("%"), bold("S"), bold("p")))
347 - valid_updates, errors = parse_updates(mycontent)
348 - myupd.extend(valid_updates)
349 - writemsg_stdout(len(valid_updates) * "." + "\n")
350 - if len(errors) == 0:
351 - # Update our internal mtime since we
352 - # processed all of our directives.
353 - timestamps[mykey] = mystat[stat.ST_MTIME]
354 - else:
355 - for msg in errors:
356 - writemsg("%s\n" % msg, noiselevel=-1)
357 -
358 - world_file = os.path.join(root, EPREFIX_LSTRIP, WORLD_FILE)
359 - world_list = grabfile(world_file)
360 - world_modified = False
361 - for update_cmd in myupd:
362 - for pos, atom in enumerate(world_list):
363 - new_atom = update_dbentry(update_cmd, atom)
364 - if atom != new_atom:
365 - world_list[pos] = new_atom
366 - world_modified = True
367 - if world_modified:
368 - world_list.sort()
369 - write_atomic(world_file,
370 - "".join("%s\n" % (x,) for x in world_list))
371 -
372 - update_config_files("/",
373 - mysettings.get("CONFIG_PROTECT","").split(),
374 - mysettings.get("CONFIG_PROTECT_MASK","").split(),
375 - myupd)
376 -
377 - trees["/"]["bintree"] = binarytree("/", mysettings["PKGDIR"],
378 - settings=mysettings)
379 - vardb = trees["/"]["vartree"].dbapi
380 - bindb = trees["/"]["bintree"].dbapi
381 - if not os.access(bindb.bintree.pkgdir, os.W_OK):
382 - bindb = None
383 - for update_cmd in myupd:
384 - if update_cmd[0] == "move":
385 - moves = vardb.move_ent(update_cmd)
386 - if moves:
387 - writemsg_stdout(moves * "@")
388 - if bindb:
389 - moves = bindb.move_ent(update_cmd)
390 - if moves:
391 - writemsg_stdout(moves * "%")
392 - elif update_cmd[0] == "slotmove":
393 - moves = vardb.move_slot_ent(update_cmd)
394 - if moves:
395 - writemsg_stdout(moves * "s")
396 - if bindb:
397 - moves = bindb.move_slot_ent(update_cmd)
398 - if moves:
399 - writemsg_stdout(moves * "S")
400 -
401 - # The above global updates proceed quickly, so they
402 - # are considered a single mtimedb transaction.
403 - if len(timestamps) > 0:
404 - # We do not update the mtime in the mtimedb
405 - # until after _all_ of the above updates have
406 - # been processed because the mtimedb will
407 - # automatically commit when killed by ctrl C.
408 - for mykey, mtime in timestamps.items():
409 - prev_mtimes[mykey] = mtime
410 -
411 - # We gotta do the brute force updates for these now.
412 - if mysettings["PORTAGE_CALLER"] == "fixpackages" or \
413 - "fixpackages" in mysettings.features:
414 - def onUpdate(maxval, curval):
415 - if curval > 0:
416 - writemsg_stdout("#")
417 - vardb.update_ents(myupd, onUpdate=onUpdate)
418 - if bindb:
419 - def onUpdate(maxval, curval):
420 - if curval > 0:
421 - writemsg_stdout("*")
422 - bindb.update_ents(myupd, onUpdate=onUpdate)
423 - else:
424 - do_upgrade_packagesmessage = 1
425 -
426 - # Update progress above is indicated by characters written to stdout so
427 - # we print a couple new lines here to separate the progress output from
428 - # what follows.
429 - print()
430 - print()
431 -
432 - if do_upgrade_packagesmessage and bindb and \
433 - bindb.cpv_all():
434 - writemsg_stdout(_(" ** Skipping packages. Run 'fixpackages' or set it in FEATURES to fix the tbz2's in the packages directory.\n"))
435 - writemsg_stdout(bold(_("Note: This can take a very long time.")))
436 - writemsg_stdout("\n")
437 - if myupd:
438 - return myupd
439 -
440 -#continue setting up other trees
441 -
442 class MtimeDB(dict):
443 def __init__(self, filename):
444 dict.__init__(self)
445 @@ -1010,7 +749,7 @@
446
447 global db, settings, root, portdb, selinux_enabled, mtimedbfile, mtimedb, \
448 archlist, features, groups, pkglines, thirdpartymirrors, usedefaults, \
449 - profiledir, flushmtimedb
450 + profiledir
451
452 # Portage needs to ensure a sane umask for the files it creates.
453 os.umask(0o22)
454 @@ -1049,8 +788,6 @@
455 profiledir = os.path.join(settings["PORTAGE_CONFIGROOT"], PROFILE_PATH)
456 if not os.path.isdir(profiledir):
457 profiledir = None
458 - def flushmtimedb(record):
459 - writemsg("portage.flushmtimedb() is DEPRECATED\n")
460 # ========================================================================
461 # COMPATIBILITY
462 # These attributes should not be used
463 @@ -1070,13 +807,5 @@
464
465 for k in ("db", "settings", "root", "selinux_enabled",
466 "archlist", "features", "groups",
467 - "pkglines", "thirdpartymirrors", "usedefaults", "profiledir",
468 - "flushmtimedb"):
469 + "pkglines", "thirdpartymirrors", "usedefaults", "profiledir"):
470 globals()[k] = _LegacyGlobalProxy(k)
471 -
472 -# Clear the cache
473 -dircache={}
474 -
475 -# ============================================================================
476 -# ============================================================================
477 -
478
479 Copied: main/branches/prefix/pym/portage/_ensure_encodings.py (from rev 15477, main/trunk/pym/portage/_ensure_encodings.py)
480 ===================================================================
481 --- main/branches/prefix/pym/portage/_ensure_encodings.py (rev 0)
482 +++ main/branches/prefix/pym/portage/_ensure_encodings.py 2010-02-27 20:11:56 UTC (rev 15485)
483 @@ -0,0 +1,133 @@
484 +# Copyright 2010 Gentoo Foundation
485 +# Distributed under the terms of the GNU General Public License v2
486 +# $Id$
487 +
488 +import codecs
489 +
490 +_codec_map = None
491 +
492 +def _setup_encodings(default_encoding, filesystem_encoding, missing_encodings):
493 + """
494 + The <python-2.6.4 that's inside stage 1 or 2 is built with a minimal
495 + configuration which does not include the /usr/lib/pythonX.Y/encodings
496 + directory. This results in error like the following:
497 +
498 + LookupError: no codec search functions registered: can't find encoding
499 +
500 + In order to solve this problem, detect it early and manually register
501 + a search function for the ascii and utf_8 codecs. Starting with python-3.0
502 + this problem is more noticeable because of stricter handling of encoding
503 + and decoding between strings of characters and bytes.
504 + """
505 +
506 + global _codec_map
507 + _codec_map = _gen_missing_encodings(missing_encodings)
508 +
509 + default_fallback = 'utf_8'
510 +
511 + if default_encoding in missing_encodings and \
512 + default_encoding not in _codec_map:
513 + # Make the fallback codec correspond to whatever name happens
514 + # to be returned by sys.getfilesystemencoding().
515 +
516 + try:
517 + _codec_map[default_encoding] = codecs.lookup(default_fallback)
518 + except LookupError:
519 + _codec_map[default_encoding] = _codec_map[default_fallback]
520 +
521 + if filesystem_encoding in missing_encodings and \
522 + filesystem_encoding not in _codec_map:
523 + # Make the fallback codec correspond to whatever name happens
524 + # to be returned by sys.getdefaultencoding().
525 +
526 + try:
527 + _codec_map[filesystem_encoding] = codecs.lookup(default_fallback)
528 + except LookupError:
529 + _codec_map[filesystem_encoding] = _codec_map[default_fallback]
530 +
531 + codecs.register(_search_function)
532 +
533 +def _gen_missing_encodings(missing_encodings):
534 +
535 + codec_map = {}
536 +
537 + if 'ascii' in missing_encodings:
538 +
539 + class AsciiIncrementalEncoder(codecs.IncrementalEncoder):
540 + def encode(self, input, final=False):
541 + return codecs.ascii_encode(input, self.errors)[0]
542 +
543 + class AsciiIncrementalDecoder(codecs.IncrementalDecoder):
544 + def decode(self, input, final=False):
545 + return codecs.ascii_decode(input, self.errors)[0]
546 +
547 + class AsciiStreamWriter(codecs.StreamWriter):
548 + encode = codecs.ascii_encode
549 +
550 + class AsciiStreamReader(codecs.StreamReader):
551 + decode = codecs.ascii_decode
552 +
553 + codec_info = codecs.CodecInfo(
554 + name='ascii',
555 + encode=codecs.ascii_encode,
556 + decode=codecs.ascii_decode,
557 + incrementalencoder=AsciiIncrementalEncoder,
558 + incrementaldecoder=AsciiIncrementalDecoder,
559 + streamwriter=AsciiStreamWriter,
560 + streamreader=AsciiStreamReader,
561 + )
562 +
563 + for alias in ('ascii', '646', 'ansi_x3.4_1968', 'ansi_x3_4_1968',
564 + 'ansi_x3.4_1986', 'cp367', 'csascii', 'ibm367', 'iso646_us',
565 + 'iso_646.irv_1991', 'iso_ir_6', 'us', 'us_ascii'):
566 + codec_map[alias] = codec_info
567 +
568 + if 'utf_8' in missing_encodings:
569 +
570 + def utf8decode(input, errors='strict'):
571 + return codecs.utf_8_decode(input, errors, True)
572 +
573 + class Utf8IncrementalEncoder(codecs.IncrementalEncoder):
574 + def encode(self, input, final=False):
575 + return codecs.utf_8_encode(input, self.errors)[0]
576 +
577 + class Utf8IncrementalDecoder(codecs.BufferedIncrementalDecoder):
578 + _buffer_decode = codecs.utf_8_decode
579 +
580 + class Utf8StreamWriter(codecs.StreamWriter):
581 + encode = codecs.utf_8_encode
582 +
583 + class Utf8StreamReader(codecs.StreamReader):
584 + decode = codecs.utf_8_decode
585 +
586 + codec_info = codecs.CodecInfo(
587 + name='utf-8',
588 + encode=codecs.utf_8_encode,
589 + decode=utf8decode,
590 + incrementalencoder=Utf8IncrementalEncoder,
591 + incrementaldecoder=Utf8IncrementalDecoder,
592 + streamreader=Utf8StreamReader,
593 + streamwriter=Utf8StreamWriter,
594 + )
595 +
596 + for alias in ('utf_8', 'u8', 'utf', 'utf8', 'utf8_ucs2', 'utf8_ucs4'):
597 + codec_map[alias] = codec_info
598 +
599 + return codec_map
600 +
601 +def _search_function(name):
602 + global _codec_map
603 + name = name.lower()
604 + name = name.replace('-', '_')
605 + codec_info = _codec_map.get(name)
606 + if codec_info is not None:
607 + return codecs.CodecInfo(
608 + name=codec_info.name,
609 + encode=codec_info.encode,
610 + decode=codec_info.decode,
611 + incrementalencoder=codec_info.incrementalencoder,
612 + incrementaldecoder=codec_info.incrementaldecoder,
613 + streamreader=codec_info.streamreader,
614 + streamwriter=codec_info.streamwriter,
615 + )
616 + return None
617
618 Copied: main/branches/prefix/pym/portage/_global_updates.py (from rev 15477, main/trunk/pym/portage/_global_updates.py)
619 ===================================================================
620 --- main/branches/prefix/pym/portage/_global_updates.py (rev 0)
621 +++ main/branches/prefix/pym/portage/_global_updates.py 2010-02-27 20:11:56 UTC (rev 15485)
622 @@ -0,0 +1,152 @@
623 +# Copyright 2010 Gentoo Foundation
624 +# Distributed under the terms of the GNU General Public License v2
625 +# $Id$
626 +
627 +from __future__ import print_function
628 +
629 +import stat
630 +
631 +from portage import os
632 +from portage.const import WORLD_FILE
633 +from portage.data import secpass
634 +from portage.exception import DirectoryNotFound
635 +from portage.localization import _
636 +from portage.output import bold, colorize
637 +from portage.update import grab_updates, parse_updates, update_config_files, update_dbentry
638 +from portage.util import grabfile, writemsg, writemsg_stdout, write_atomic
639 +
640 +def _global_updates(trees, prev_mtimes):
641 + """
642 + Perform new global updates if they exist in $PORTDIR/profiles/updates/.
643 +
644 + @param trees: A dictionary containing portage trees.
645 + @type trees: dict
646 + @param prev_mtimes: A dictionary containing mtimes of files located in
647 + $PORTDIR/profiles/updates/.
648 + @type prev_mtimes: dict
649 + @rtype: None or List
650 + @return: None if no were no updates, otherwise a list of update commands
651 + that have been performed.
652 + """
653 + # only do this if we're root and not running repoman/ebuild digest
654 +
655 + if secpass < 2 or "SANDBOX_ACTIVE" in os.environ:
656 + return
657 + root = "/"
658 + mysettings = trees["/"]["vartree"].settings
659 + updpath = os.path.join(mysettings["PORTDIR"], "profiles", "updates")
660 +
661 + try:
662 + if mysettings["PORTAGE_CALLER"] == "fixpackages":
663 + update_data = grab_updates(updpath)
664 + else:
665 + update_data = grab_updates(updpath, prev_mtimes)
666 + except DirectoryNotFound:
667 + writemsg(_("--- 'profiles/updates' is empty or "
668 + "not available. Empty portage tree?\n"), noiselevel=1)
669 + return
670 + myupd = None
671 + if len(update_data) > 0:
672 + do_upgrade_packagesmessage = 0
673 + myupd = []
674 + timestamps = {}
675 + for mykey, mystat, mycontent in update_data:
676 + writemsg_stdout("\n\n")
677 + writemsg_stdout(colorize("GOOD",
678 + _("Performing Global Updates: "))+bold(mykey)+"\n")
679 + writemsg_stdout(_("(Could take a couple of minutes if you have a lot of binary packages.)\n"))
680 + writemsg_stdout(_(" %s='update pass' %s='binary update' "
681 + "%s='/var/db update' %s='/var/db move'\n"
682 + " %s='/var/db SLOT move' %s='binary move' "
683 + "%s='binary SLOT move'\n %s='update /etc/portage/package.*'\n") % \
684 + (bold("."), bold("*"), bold("#"), bold("@"), bold("s"), bold("%"), bold("S"), bold("p")))
685 + valid_updates, errors = parse_updates(mycontent)
686 + myupd.extend(valid_updates)
687 + writemsg_stdout(len(valid_updates) * "." + "\n")
688 + if len(errors) == 0:
689 + # Update our internal mtime since we
690 + # processed all of our directives.
691 + timestamps[mykey] = mystat[stat.ST_MTIME]
692 + else:
693 + for msg in errors:
694 + writemsg("%s\n" % msg, noiselevel=-1)
695 +
696 + world_file = os.path.join(root, EPREFIX_LSTRIP, WORLD_FILE)
697 + world_list = grabfile(world_file)
698 + world_modified = False
699 + for update_cmd in myupd:
700 + for pos, atom in enumerate(world_list):
701 + new_atom = update_dbentry(update_cmd, atom)
702 + if atom != new_atom:
703 + world_list[pos] = new_atom
704 + world_modified = True
705 + if world_modified:
706 + world_list.sort()
707 + write_atomic(world_file,
708 + "".join("%s\n" % (x,) for x in world_list))
709 +
710 + update_config_files("/",
711 + mysettings.get("CONFIG_PROTECT","").split(),
712 + mysettings.get("CONFIG_PROTECT_MASK","").split(),
713 + myupd)
714 +
715 + vardb = trees["/"]["vartree"].dbapi
716 + bindb = trees["/"]["bintree"].dbapi
717 + if not os.access(bindb.bintree.pkgdir, os.W_OK):
718 + bindb = None
719 + for update_cmd in myupd:
720 + if update_cmd[0] == "move":
721 + moves = vardb.move_ent(update_cmd)
722 + if moves:
723 + writemsg_stdout(moves * "@")
724 + if bindb:
725 + moves = bindb.move_ent(update_cmd)
726 + if moves:
727 + writemsg_stdout(moves * "%")
728 + elif update_cmd[0] == "slotmove":
729 + moves = vardb.move_slot_ent(update_cmd)
730 + if moves:
731 + writemsg_stdout(moves * "s")
732 + if bindb:
733 + moves = bindb.move_slot_ent(update_cmd)
734 + if moves:
735 + writemsg_stdout(moves * "S")
736 +
737 + # The above global updates proceed quickly, so they
738 + # are considered a single mtimedb transaction.
739 + if len(timestamps) > 0:
740 + # We do not update the mtime in the mtimedb
741 + # until after _all_ of the above updates have
742 + # been processed because the mtimedb will
743 + # automatically commit when killed by ctrl C.
744 + for mykey, mtime in timestamps.items():
745 + prev_mtimes[mykey] = mtime
746 +
747 + # We gotta do the brute force updates for these now.
748 + if mysettings["PORTAGE_CALLER"] == "fixpackages" or \
749 + "fixpackages" in mysettings.features:
750 + def onUpdate(maxval, curval):
751 + if curval > 0:
752 + writemsg_stdout("#")
753 + vardb.update_ents(myupd, onUpdate=onUpdate)
754 + if bindb:
755 + def onUpdate(maxval, curval):
756 + if curval > 0:
757 + writemsg_stdout("*")
758 + bindb.update_ents(myupd, onUpdate=onUpdate)
759 + else:
760 + do_upgrade_packagesmessage = 1
761 +
762 + # Update progress above is indicated by characters written to stdout so
763 + # we print a couple new lines here to separate the progress output from
764 + # what follows.
765 + print()
766 + print()
767 +
768 + if do_upgrade_packagesmessage and bindb and \
769 + bindb.cpv_all():
770 + writemsg_stdout(_(" ** Skipping packages. Run 'fixpackages' or set it in FEATURES to fix the tbz2's in the packages directory.\n"))
771 + writemsg_stdout(bold(_("Note: This can take a very long time.")))
772 + writemsg_stdout("\n")
773 + if myupd:
774 + return myupd