2 # Copyright 2009-2012 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 from __future__ import print_function
10 # This block ensures that ^C interrupts are handled quietly.
13 def exithandler(signum,frame):
14 signal.signal(signal.SIGINT, signal.SIG_IGN)
15 signal.signal(signal.SIGTERM, signal.SIG_IGN)
16 sys.exit(128 + signum)
18 signal.signal(signal.SIGINT, exithandler)
19 signal.signal(signal.SIGTERM, exithandler)
21 except KeyboardInterrupt:
22 sys.exit(128 + signal.SIGINT)
24 def debug_signal(signum, frame):
28 if platform.python_implementation() == 'Jython':
29 debug_signum = signal.SIGUSR2 # bug #424259
31 debug_signum = signal.SIGUSR1
33 signal.signal(debug_signum, debug_signal)
43 from os import path as osp
44 pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
45 sys.path.insert(0, pym_path)
47 from portage import os, _encodings, _unicode_encode, _unicode_decode
48 from _emerge.MetadataRegen import MetadataRegen
49 from portage.cache.cache_errors import CacheError, StatCollision
50 from portage.manifest import guessManifestFileType
51 from portage.package.ebuild._parallel_manifest.ManifestScheduler import ManifestScheduler
52 from portage.util import cmp_sort_key, writemsg_level
53 from portage.util._async.run_main_scheduler import run_main_scheduler
54 from portage.util._eventloop.global_event_loop import global_event_loop
55 from portage import cpv_getkey
56 from portage.dep import Atom, isjustname
57 from portage.versions import pkgsplit, vercmp
60 from xml.etree import ElementTree
65 from xml.parsers.expat import ExpatError
69 from repoman.utilities import parse_metadata_use
71 from repoman.utilities import FindVCS
73 if sys.hexversion >= 0x3000000:
77 usage = "egencache [options] <action> ... [atom] ..."
78 parser = optparse.OptionParser(usage=usage)
80 actions = optparse.OptionGroup(parser, 'Actions')
81 actions.add_option("--update",
83 help="update metadata/cache/ (generate as necessary)")
84 actions.add_option("--update-use-local-desc",
86 help="update the use.local.desc file from metadata.xml")
87 actions.add_option("--update-changelogs",
89 help="update the ChangeLog files from SCM logs")
90 actions.add_option("--update-manifests",
92 help="update manifests")
93 parser.add_option_group(actions)
95 common = optparse.OptionGroup(parser, 'Common options')
96 common.add_option("--repo",
98 help="name of repo to operate on (default repo is located at $PORTDIR)")
99 common.add_option("--config-root",
100 help="location of portage config files",
101 dest="portage_configroot")
102 common.add_option("--gpg-dir",
103 help="override the PORTAGE_GPG_DIR variable",
105 common.add_option("--gpg-key",
106 help="override the PORTAGE_GPG_KEY variable",
108 common.add_option("--portdir",
109 help="override the portage tree location",
111 common.add_option("--portdir-overlay",
112 help="override the PORTDIR_OVERLAY variable (requires that --repo is also specified)",
113 dest="portdir_overlay")
114 common.add_option("--sign-manifests",
118 help="manually override layout.conf sign-manifests setting")
119 common.add_option("--strict-manifests",
123 help="manually override \"strict\" FEATURES setting")
124 common.add_option("--thin-manifests",
128 help="manually override layout.conf thin-manifests setting")
129 common.add_option("--tolerant",
131 help="exit successfully if only minor errors occurred")
132 common.add_option("--ignore-default-opts",
134 help="do not use the EGENCACHE_DEFAULT_OPTS environment variable")
135 parser.add_option_group(common)
137 update = optparse.OptionGroup(parser, '--update options')
138 update.add_option("--cache-dir",
139 help="location of the metadata cache",
141 update.add_option("-j", "--jobs",
143 help="max ebuild processes to spawn")
144 update.add_option("--load-average",
146 help="max load allowed when spawning multiple jobs",
148 update.add_option("--rsync",
150 help="enable rsync stat collision workaround " + \
151 "for bug 139134 (use with --update)")
152 parser.add_option_group(update)
154 uld = optparse.OptionGroup(parser, '--update-use-local-desc options')
155 uld.add_option("--preserve-comments",
157 help="preserve the comments from the existing use.local.desc file")
158 uld.add_option("--use-local-desc-output",
159 help="output file for use.local.desc data (or '-' for stdout)",
161 parser.add_option_group(uld)
163 options, args = parser.parse_args(args)
168 jobs = int(options.jobs)
173 parser.error("Invalid: --jobs='%s'" % \
181 if options.load_average:
183 load_average = float(options.load_average)
187 if load_average <= 0.0:
188 parser.error("Invalid: --load-average='%s'" % \
189 (options.load_average,))
191 options.load_average = load_average
194 options.load_average = None
196 options.config_root = options.portage_configroot
197 if options.config_root is not None and \
198 not os.path.isdir(options.config_root):
199 parser.error("Not a directory: --config-root='%s'" % \
200 (options.config_root,))
202 if options.cache_dir is not None:
203 if not os.path.isdir(options.cache_dir):
204 parser.error("Not a directory: --cache-dir='%s'" % \
205 (options.cache_dir,))
206 if not os.access(options.cache_dir, os.W_OK):
207 parser.error("Write access denied: --cache-dir='%s'" % \
208 (options.cache_dir,))
210 if options.portdir_overlay is not None and \
211 options.repo is None:
212 parser.error("--portdir-overlay option requires --repo option")
216 atom = portage.dep.Atom(atom)
217 except portage.exception.InvalidAtom:
218 parser.error('Invalid atom: %s' % (atom,))
220 if not isjustname(atom):
221 parser.error('Atom is too specific: %s' % (atom,))
223 if options.update_use_local_desc:
228 parser.error('--update-use-local-desc requires python with USE=xml!')
230 if options.uld_output == '-' and options.preserve_comments:
231 parser.error('--preserve-comments can not be used when outputting to stdout')
233 return parser, options, args
235 class GenCache(object):
236 def __init__(self, portdb, cp_iter=None, max_jobs=None, max_load=None,
238 # The caller must set portdb.porttrees in order to constrain
239 # findname, cp_list, and cpv_list to the desired tree.
240 tree = portdb.porttrees[0]
241 self._portdb = portdb
242 self._eclass_db = portdb.repositories.get_repo_for_location(tree).eclass_db
243 self._auxdbkeys = portdb._known_keys
244 # We can globally cleanse stale cache only if we
245 # iterate over every single cp.
246 self._global_cleanse = cp_iter is None
247 if cp_iter is not None:
248 self._cp_set = set(cp_iter)
249 cp_iter = iter(self._cp_set)
250 self._cp_missing = self._cp_set.copy()
253 self._cp_missing = set()
254 write_auxdb = "metadata-transfer" in portdb.settings.features
255 self._regen = MetadataRegen(portdb, cp_iter=cp_iter,
256 consumer=self._metadata_callback,
257 max_jobs=max_jobs, max_load=max_load,
258 write_auxdb=write_auxdb, main=True)
259 self.returncode = os.EX_OK
260 conf = portdb.repositories.get_repo_for_location(tree)
261 self._trg_caches = tuple(conf.iter_pregenerated_caches(
262 self._auxdbkeys, force=True, readonly=False))
263 if not self._trg_caches:
264 raise Exception("cache formats '%s' aren't supported" %
265 (" ".join(conf.cache_formats),))
268 for trg_cache in self._trg_caches:
269 if hasattr(trg_cache, 'raise_stat_collision'):
270 trg_cache.raise_stat_collision = True
271 # Make _metadata_callback write this cache first, in case
272 # it raises a StatCollision and triggers mtime
274 self._trg_caches = tuple([trg_cache] +
275 [x for x in self._trg_caches if x is not trg_cache])
277 self._existing_nodes = set()
279 def _metadata_callback(self, cpv, repo_path, metadata,
280 ebuild_hash, eapi_supported):
281 self._existing_nodes.add(cpv)
282 self._cp_missing.discard(cpv_getkey(cpv))
284 # Since we're supposed to be able to efficiently obtain the
285 # EAPI from _parse_eapi_ebuild_head, we don't write cache
286 # entries for unsupported EAPIs.
287 if metadata is not None and eapi_supported:
288 if metadata.get('EAPI') == '0':
290 for trg_cache in self._trg_caches:
291 self._write_cache(trg_cache,
292 cpv, repo_path, metadata, ebuild_hash)
294 def _write_cache(self, trg_cache, cpv, repo_path, metadata, ebuild_hash):
296 if not hasattr(trg_cache, 'raise_stat_collision'):
297 # This cache does not avoid redundant writes automatically,
298 # so check for an identical existing entry before writing.
299 # This prevents unnecessary disk writes and can also prevent
300 # unnecessary rsync transfers.
302 dest = trg_cache[cpv]
303 except (KeyError, CacheError):
306 if trg_cache.validate_entry(dest,
307 ebuild_hash, self._eclass_db):
309 for k in self._auxdbkeys:
310 if dest.get(k, '') != metadata.get(k, ''):
317 chf = trg_cache.validation_chf
318 metadata['_%s_' % chf] = getattr(ebuild_hash, chf)
320 trg_cache[cpv] = metadata
321 except StatCollision as sc:
322 # If the content of a cache entry changes and neither the
323 # file mtime nor size changes, it will prevent rsync from
324 # detecting changes. Cache backends may raise this
325 # exception from _setitem() if they detect this type of stat
326 # collision. These exceptions are handled by bumping the
327 # mtime on the ebuild (and the corresponding cache entry).
328 # See bug #139134. It is convenient to include checks for
329 # redundant writes along with the internal StatCollision
330 # detection code, so for caches with the
331 # raise_stat_collision attribute, we do not need to
332 # explicitly check for redundant writes like we do for the
333 # other cache types above.
335 for ec, ec_hash in metadata['_eclasses_'].items():
336 if max_mtime < ec_hash.mtime:
337 max_mtime = ec_hash.mtime
338 if max_mtime == sc.mtime:
340 max_mtime = long(max_mtime)
342 os.utime(ebuild_hash.location, (max_mtime, max_mtime))
346 "%s writing target: %s\n" % (cpv, e),
347 level=logging.ERROR, noiselevel=-1)
349 ebuild_hash.mtime = max_mtime
350 metadata['_mtime_'] = max_mtime
351 trg_cache[cpv] = metadata
352 self._portdb.auxdb[repo_path][cpv] = metadata
354 except CacheError as ce:
357 "%s writing target: %s\n" % (cpv, ce),
358 level=logging.ERROR, noiselevel=-1)
361 signum = run_main_scheduler(self._regen)
362 if signum is not None:
363 sys.exit(128 + signum)
365 self.returncode |= self._regen.returncode
367 for trg_cache in self._trg_caches:
368 self._cleanse_cache(trg_cache)
370 def _cleanse_cache(self, trg_cache):
371 cp_missing = self._cp_missing
373 if self._global_cleanse:
375 for cpv in trg_cache:
380 "Unable to parse cp for '%s'\n" % (cpv,),
381 level=logging.ERROR, noiselevel=-1)
384 except CacheError as ce:
387 "Error listing cache entries for " + \
388 "'%s/metadata/cache': %s, continuing...\n" % \
389 (self._portdb.porttree_root, ce),
390 level=logging.ERROR, noiselevel=-1)
393 cp_set = self._cp_set
395 for cpv in trg_cache:
400 "Unable to parse cp for '%s'\n" % (cpv,),
401 level=logging.ERROR, noiselevel=-1)
403 cp_missing.discard(cp)
406 except CacheError as ce:
409 "Error listing cache entries for " + \
410 "'%s/metadata/cache': %s, continuing...\n" % \
411 (self._portdb.porttree_root, ce),
412 level=logging.ERROR, noiselevel=-1)
416 for cp in sorted(cp_missing):
418 "No ebuilds or cache entries found for '%s'\n" % (cp,),
419 level=logging.ERROR, noiselevel=-1)
422 dead_nodes.difference_update(self._existing_nodes)
428 except CacheError as ce:
431 "%s deleting stale cache: %s\n" % (k, ce),
432 level=logging.ERROR, noiselevel=-1)
434 if not trg_cache.autocommits:
437 except CacheError as ce:
440 "committing target: %s\n" % (ce,),
441 level=logging.ERROR, noiselevel=-1)
443 if hasattr(trg_cache, '_prune_empty_dirs'):
444 trg_cache._prune_empty_dirs()
446 class GenUseLocalDesc(object):
447 def __init__(self, portdb, output=None,
448 preserve_comments=False):
449 self.returncode = os.EX_OK
450 self._portdb = portdb
451 self._output = output
452 self._preserve_comments = preserve_comments
455 repo_path = self._portdb.porttrees[0]
456 ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
458 if self._output is None or self._output != '-':
459 if self._output is None:
460 prof_path = os.path.join(repo_path, 'profiles')
461 desc_path = os.path.join(prof_path, 'use.local.desc')
467 desc_path = self._output
470 if self._preserve_comments:
471 # Probe in binary mode, in order to avoid
472 # potential character encoding issues.
473 output = open(_unicode_encode(desc_path,
474 encoding=_encodings['fs'], errors='strict'), 'r+b')
476 output = io.open(_unicode_encode(desc_path,
477 encoding=_encodings['fs'], errors='strict'),
478 mode='w', encoding=_encodings['repo.content'],
479 errors='backslashreplace')
481 if not self._preserve_comments or \
482 os.path.isfile(desc_path):
484 "ERROR: failed to open output file %s: %s\n" \
485 % (desc_path, e), level=logging.ERROR, noiselevel=-1)
489 # Open in r+b mode failed because the file doesn't
490 # exist yet. We can probably recover if we disable
491 # preserve_comments mode now.
493 "WARNING: --preserve-comments enabled, but " + \
494 "output file not found: %s\n" % (desc_path,),
495 level=logging.WARNING, noiselevel=-1)
496 self._preserve_comments = False
498 output = io.open(_unicode_encode(desc_path,
499 encoding=_encodings['fs'], errors='strict'),
500 mode='w', encoding=_encodings['repo.content'],
501 errors='backslashreplace')
504 "ERROR: failed to open output file %s: %s\n" \
505 % (desc_path, e), level=logging.ERROR, noiselevel=-1)
511 if self._preserve_comments:
514 if not output.readline().startswith(b'#'):
520 # Finished probing comments in binary mode, now append
522 output = io.open(_unicode_encode(desc_path,
523 encoding=_encodings['fs'], errors='strict'),
524 mode='a', encoding=_encodings['repo.content'],
525 errors='backslashreplace')
526 output.write(_unicode_decode('\n'))
528 output.write(textwrap.dedent(_unicode_decode('''\
529 # This file is deprecated as per GLEP 56 in favor of metadata.xml. Please add
530 # your descriptions to your package's metadata.xml ONLY.
531 # * generated automatically using egencache *
535 # The cmp function no longer exists in python3, so we'll
536 # implement our own here under a slightly different name
537 # since we don't want any confusion given that we never
538 # want to rely on the builtin cmp function.
540 if a is None or b is None:
541 # None can't be compared with other types in python3.
542 if a is None and b is None:
548 return (a > b) - (a < b)
550 class _MetadataTreeBuilder(ElementTree.TreeBuilder):
552 Implements doctype() as required to avoid deprecation warnings
555 def doctype(self, name, pubid, system):
558 for cp in self._portdb.cp_all():
559 metadata_path = os.path.join(repo_path, cp, 'metadata.xml')
561 metadata = ElementTree.parse(_unicode_encode(metadata_path,
562 encoding=_encodings['fs'], errors='strict'),
563 parser=ElementTree.XMLParser(
564 target=_MetadataTreeBuilder()))
567 except (ExpatError, EnvironmentError) as e:
569 "ERROR: failed parsing %s/metadata.xml: %s\n" % (cp, e),
570 level=logging.ERROR, noiselevel=-1)
574 usedict = parse_metadata_use(metadata)
575 except portage.exception.ParseError as e:
577 "ERROR: failed parsing %s/metadata.xml: %s\n" % (cp, e),
578 level=logging.ERROR, noiselevel=-1)
581 for flag in sorted(usedict):
582 def atomcmp(atoma, atomb):
583 # None is better than an atom, that's why we reverse the args
584 if atoma is None or atomb is None:
585 return cmp_func(atomb, atoma)
586 # Same for plain PNs (.operator is None then)
587 elif atoma.operator is None or atomb.operator is None:
588 return cmp_func(atomb.operator, atoma.operator)
590 elif atoma.cpv != atomb.cpv:
591 return vercmp(atoma.version, atomb.version)
592 # Versions match, let's fallback to operator matching
594 return cmp_func(ops.get(atoma.operator, -1),
595 ops.get(atomb.operator, -1))
602 resdict = usedict[flag]
603 if len(resdict) == 1:
604 resdesc = next(iter(resdict.items()))[1]
607 reskeys = dict((_Atom(k), k) for k in resdict)
608 except portage.exception.InvalidAtom as e:
610 "ERROR: failed parsing %s/metadata.xml: %s\n" % (cp, e),
611 level=logging.ERROR, noiselevel=-1)
613 resdesc = next(iter(resdict.items()))[1]
615 resatoms = sorted(reskeys, key=cmp_sort_key(atomcmp))
616 resdesc = resdict[reskeys[resatoms[-1]]]
618 output.write(_unicode_decode(
619 '%s:%s - %s\n' % (cp, flag, resdesc)))
623 if sys.hexversion < 0x3000000:
624 _filename_base = unicode
628 class _special_filename(_filename_base):
630 Helps to sort file names by file type and other criteria.
632 def __new__(cls, status_change, file_name):
633 return _filename_base.__new__(cls, status_change + file_name)
635 def __init__(self, status_change, file_name):
636 _filename_base.__init__(status_change + file_name)
637 self.status_change = status_change
638 self.file_name = file_name
639 self.file_type = guessManifestFileType(file_name)
641 def file_type_lt(self, a, b):
643 Defines an ordering between file types.
650 if first == "EBUILD":
652 elif first == "MISC":
653 return second in ("EBUILD",)
655 return second in ("EBUILD", "MISC")
656 elif first == "DIST":
657 return second in ("EBUILD", "MISC", "AUX")
661 raise ValueError("Unknown file type '%s'" % first)
663 def __lt__(self, other):
665 Compare different file names, first by file type and then
666 for ebuilds by version and lexicographically for others.
667 EBUILD < MISC < AUX < DIST < None
669 if self.__class__ != other.__class__:
670 raise NotImplementedError
672 # Sort by file type as defined by file_type_lt().
673 if self.file_type_lt(self, other):
675 elif self.file_type_lt(other, self):
678 # Files have the same type.
679 if self.file_type == "EBUILD":
680 # Sort by version. Lowest first.
681 ver = "-".join(pkgsplit(self.file_name[:-7])[1:3])
682 other_ver = "-".join(pkgsplit(other.file_name[:-7])[1:3])
683 return vercmp(ver, other_ver) < 0
685 # Sort lexicographically.
686 return self.file_name < other.file_name
688 class GenChangeLogs(object):
689 def __init__(self, portdb):
690 self.returncode = os.EX_OK
691 self._portdb = portdb
692 self._wrapper = textwrap.TextWrapper(
694 initial_indent = ' ',
695 subsequent_indent = ' '
700 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
701 return _unicode_decode(p.communicate()[0],
702 encoding=_encodings['stdio'], errors='strict')
704 def generate_changelog(self, cp):
706 output = io.open('ChangeLog',
707 mode='w', encoding=_encodings['repo.content'],
708 errors='backslashreplace')
711 "ERROR: failed to open ChangeLog for %s: %s\n" % (cp,e,),
712 level=logging.ERROR, noiselevel=-1)
716 output.write(textwrap.dedent(_unicode_decode('''\
718 # Copyright 1999-%s Gentoo Foundation; Distributed under the GPL v2
721 ''' % (cp, time.strftime('%Y')))))
723 # now grab all the commits
724 commits = self.grab(['git', 'rev-list', 'HEAD', '--', '.']).split()
727 # Explaining the arguments:
728 # --name-status to get a list of added/removed files
729 # --no-renames to avoid getting more complex records on the list
730 # --format to get the timestamp, author and commit description
731 # --root to make it work fine even with the initial commit
732 # --relative to get paths relative to ebuilddir
733 # -r (recursive) to get per-file changes
734 # then the commit-id and path.
736 cinfo = self.grab(['git', 'diff-tree', '--name-status', '--no-renames',
737 '--format=%ct %cN <%cE>%n%B', '--root', '--relative', '-r',
738 c, '--', '.']).rstrip('\n').split('\n')
741 # timestamp Author Name <author@email>
751 for n, l in enumerate(reversed(cinfo)):
757 if f[1] == 'Manifest':
758 pass # XXX: remanifest commits?
759 elif f[1] == 'ChangeLog':
761 elif f[0].startswith('A'):
762 changed.append(_special_filename("+", f[1]))
763 elif f[0].startswith('D'):
764 changed.append(_special_filename("-", f[1]))
765 elif f[0].startswith('M'):
766 changed.append(_special_filename("", f[1]))
769 "ERROR: unexpected git file status for %s: %s\n" % (cp,f,),
770 level=logging.ERROR, noiselevel=-1)
776 (ts, author) = cinfo[0].split(' ', 1)
777 date = time.strftime('%d %b %Y', time.gmtime(float(ts)))
779 changed = [str(x) for x in sorted(changed)]
782 # Reverse the sort order for headers.
783 for c in reversed(changed):
784 if c.startswith('+') and c.endswith('.ebuild'):
785 output.write(_unicode_decode(
786 '*%s (%s)\n' % (c[1:-7], date)))
789 output.write(_unicode_decode('\n'))
791 # strip '<cp>: ', '[<cp>] ', and similar
792 body[0] = re.sub(r'^\W*' + re.escape(cp) + r'\W+', '', body[0])
793 # strip trailing newline
797 if body[-1].startswith('git-svn-id:') and not body[-2]:
799 # strip the repoman version/manifest note
800 if body[-1] == ' (Signed Manifest commit)' or body[-1] == ' (Unsigned Manifest commit)':
802 if body[-1].startswith('(Portage version:') and body[-1].endswith(')'):
807 # don't break filenames on hyphens
808 self._wrapper.break_on_hyphens = False
809 output.write(_unicode_decode(
811 '%s; %s %s:' % (date, author, ', '.join(changed)))))
812 # but feel free to break commit messages there
813 self._wrapper.break_on_hyphens = True
814 output.write(_unicode_decode(
815 '\n%s\n\n' % '\n'.join(self._wrapper.fill(x) for x in body)))
820 repo_path = self._portdb.porttrees[0]
823 if 'git' not in FindVCS():
825 "ERROR: --update-changelogs supported only in git repos\n",
826 level=logging.ERROR, noiselevel=-1)
827 self.returncode = 127
830 for cp in self._portdb.cp_all():
831 os.chdir(os.path.join(repo_path, cp))
832 # Determine whether ChangeLog is up-to-date by comparing
833 # the newest commit timestamp with the ChangeLog timestamp.
834 lmod = self.grab(['git', 'log', '--format=%ct', '-1', '.'])
836 # This cp has not been added to the repo.
840 cmod = os.stat('ChangeLog').st_mtime
844 if float(cmod) < float(lmod):
845 self.generate_changelog(cp)
847 def egencache_main(args):
848 parser, options, atoms = parse_args(args)
850 config_root = options.config_root
852 # The calling environment is ignored, so the program is
853 # completely controlled by commandline arguments.
856 if options.repo is None:
857 env['PORTDIR_OVERLAY'] = ''
858 elif options.portdir_overlay:
859 env['PORTDIR_OVERLAY'] = options.portdir_overlay
861 if options.cache_dir is not None:
862 env['PORTAGE_DEPCACHEDIR'] = options.cache_dir
864 if options.portdir is not None:
865 env['PORTDIR'] = options.portdir
867 settings = portage.config(config_root=config_root,
868 local_config=False, env=env)
871 if not options.ignore_default_opts:
872 default_opts = settings.get('EGENCACHE_DEFAULT_OPTS', '').split()
875 parser, options, args = parse_args(default_opts + args)
877 if options.cache_dir is not None:
878 env['PORTAGE_DEPCACHEDIR'] = options.cache_dir
880 settings = portage.config(config_root=config_root,
881 local_config=False, env=env)
883 if not (options.update or options.update_use_local_desc or
884 options.update_changelogs or options.update_manifests):
885 parser.error('No action specified')
889 if options.repo is not None:
890 repo_path = settings.repositories.treemap.get(options.repo)
891 if repo_path is None:
892 parser.error("Unable to locate repository named '%s'" % \
896 repo_path = settings.repositories.mainRepoLocation()
898 parser.error("PORTDIR is undefined")
901 repo_config = settings.repositories.get_repo_for_location(repo_path)
903 if options.strict_manifests is not None:
904 if options.strict_manifests == "y":
905 settings.features.add("strict")
907 settings.features.discard("strict")
909 if options.update and 'metadata-transfer' not in settings.features:
910 # Forcibly enable metadata-transfer if portdbapi has a pregenerated
911 # cache that does not support eclass validation.
912 cache = repo_config.get_pregenerated_cache(
913 portage.dbapi.dbapi._known_keys, readonly=True)
914 if cache is not None and not cache.complete_eclass_entries:
915 settings.features.add('metadata-transfer')
920 portdb = portage.portdbapi(mysettings=settings)
922 # Limit ebuilds to the specified repo.
923 portdb.porttrees = [repo_path]
926 if options.cache_dir is not None:
927 # already validated earlier
930 # We check write access after the portdbapi constructor
931 # has had an opportunity to create it. This ensures that
932 # we don't use the cache in the "volatile" mode which is
933 # undesirable for egencache.
934 if not os.access(settings["PORTAGE_DEPCACHEDIR"], os.W_OK):
935 writemsg_level("ecachegen: error: " + \
936 "write access denied: %s\n" % (settings["PORTAGE_DEPCACHEDIR"],),
937 level=logging.ERROR, noiselevel=-1)
940 if options.sign_manifests is not None:
941 repo_config.sign_manifest = options.sign_manifests == 'y'
943 if options.thin_manifests is not None:
944 repo_config.thin_manifest = options.thin_manifests == 'y'
948 force_sign_key = None
950 if options.update_manifests:
951 if repo_config.sign_manifest:
955 gpg_cmd = settings.get("PORTAGE_GPG_SIGNING_COMMAND")
957 writemsg_level("egencache: error: "
958 "PORTAGE_GPG_SIGNING_COMMAND is unset! "
959 "Is make.globals missing?\n",
960 level=logging.ERROR, noiselevel=-1)
962 elif "${PORTAGE_GPG_KEY}" in gpg_cmd and \
963 options.gpg_key is None and \
964 "PORTAGE_GPG_KEY" not in settings:
965 writemsg_level("egencache: error: "
966 "PORTAGE_GPG_KEY is unset!\n",
967 level=logging.ERROR, noiselevel=-1)
969 elif "${PORTAGE_GPG_DIR}" in gpg_cmd:
970 if options.gpg_dir is not None:
971 gpg_dir = options.gpg_dir
972 elif "PORTAGE_GPG_DIR" not in settings:
973 gpg_dir = os.path.expanduser("~/.gnupg")
975 gpg_dir = os.path.expanduser(settings["PORTAGE_GPG_DIR"])
976 if not os.access(gpg_dir, os.X_OK):
977 writemsg_level(("egencache: error: "
978 "Unable to access directory: "
979 "PORTAGE_GPG_DIR='%s'\n") % gpg_dir,
980 level=logging.ERROR, noiselevel=-1)
984 writemsg_level("egencache: You may disable manifest "
985 "signatures with --sign-manifests=n or by setting "
986 "\"sign-manifests = false\" in metadata/layout.conf\n",
987 level=logging.ERROR, noiselevel=-1)
991 if gpg_dir is not None:
992 gpg_vars["PORTAGE_GPG_DIR"] = gpg_dir
994 if options.gpg_key is None:
995 gpg_var_names.append("PORTAGE_GPG_KEY")
997 gpg_vars["PORTAGE_GPG_KEY"] = options.gpg_key
999 for k in gpg_var_names:
1004 force_sign_key = gpg_vars.get("PORTAGE_GPG_KEY")
1011 cp_iter = iter(atoms)
1013 gen_cache = GenCache(portdb, cp_iter=cp_iter,
1014 max_jobs=options.jobs,
1015 max_load=options.load_average,
1016 rsync=options.rsync)
1018 if options.tolerant:
1019 ret.append(os.EX_OK)
1021 ret.append(gen_cache.returncode)
1023 if options.update_manifests:
1027 cp_iter = iter(atoms)
1029 event_loop = global_event_loop()
1030 scheduler = ManifestScheduler(portdb, cp_iter=cp_iter,
1031 gpg_cmd=gpg_cmd, gpg_vars=gpg_vars,
1032 force_sign_key=force_sign_key,
1033 max_jobs=options.jobs,
1034 max_load=options.load_average,
1035 event_loop=event_loop)
1037 signum = run_main_scheduler(scheduler)
1038 if signum is not None:
1039 sys.exit(128 + signum)
1041 if options.tolerant:
1042 ret.append(os.EX_OK)
1044 ret.append(scheduler.returncode)
1046 if options.update_use_local_desc:
1047 gen_desc = GenUseLocalDesc(portdb,
1048 output=options.uld_output,
1049 preserve_comments=options.preserve_comments)
1051 ret.append(gen_desc.returncode)
1053 if options.update_changelogs:
1054 gen_clogs = GenChangeLogs(portdb)
1056 ret.append(gen_clogs.returncode)
1060 if __name__ == "__main__":
1061 portage._disable_legacy_globals()
1062 portage.util.noiselimit = -1
1063 sys.exit(egencache_main(sys.argv[1:]))