From: Fabian Groffen Date: Fri, 22 Jun 2007 08:49:49 +0000 (-0000) Subject: Merged from trunk 6917:6937 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=80b1a9dcdf2b739ecb4dcbf6dc0a6bc0bbfed5b6;p=portage.git Merged from trunk 6917:6937 +------------------------------------------------------------------------+ | 6917 | Autodetect if sandbox is active in order to prevent | | zmedico | recursive sandbox invocation. Thanks to Brian Harring for | | | the suggestion. | |----------+-------------------------------------------------------------| | 6918 | Implement iterkeys on top of __iter__ instead of vice | | zmedico | versa. Thanks to Brian Harring for the suggestion. | |----------+-------------------------------------------------------------| | 6919 | Simplify the implementation of config.__iter__ and also | | zmedico | implement iterkeys(). | |----------+-------------------------------------------------------------| | 6920 | Clean up config.__getitem__(), get() and setdefault() | | zmedico | implementions. | |----------+-------------------------------------------------------------| | 6922 | cache the result of --suffix to reduce testing overhead as | | SpankMan | suggested by Mr_Bones_ | |----------+-------------------------------------------------------------| | 6937 | Make quickpkg print a warning if "bindist" is in RESTRICT. | | zmedico | | +------------------------------------------------------------------------+ svn path=/main/branches/prefix/; revision=6946 --- diff --git a/bin/ecompress b/bin/ecompress index 0b1f0a8e5..aeb16eab8 100755 --- a/bin/ecompress +++ b/bin/ecompress @@ -24,20 +24,23 @@ case $1 in --suffix) [[ -n $2 ]] && vecho "${0##*/}: --suffix takes no additional arguments" 1>&2 - set -e - tmpdir="${T}"/.ecompress$$.${RANDOM} - mkdir "${tmpdir}" - cd "${tmpdir}" - # we have to fill the file enough so that there is something - # to compress as some programs will refuse to do compression - # if it cannot actually compress the file - echo {0..1000} > compressme - ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null - suffix=$(ls compressme*) - suffix=${suffix#compressme} - cd / - rm -rf "${tmpdir}" - echo "${suffix}" + if [[ ! -e ${T}/.ecompress.suffix ]] ; then + set -e + tmpdir="${T}"/.ecompress$$.${RANDOM} + mkdir "${tmpdir}" + cd "${tmpdir}" + # we have to fill the file enough so that there is something + # to compress as some programs will refuse to do compression + # if it cannot actually compress the file + echo {0..1000} > compressme + ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null + suffix=$(ls compressme*) + suffix=${suffix#compressme} + cd / + rm -rf "${tmpdir}" + echo "${suffix}" > "${T}/.ecompress.suffix" + fi + cat "${T}/.ecompress.suffix" ;; --bin) [[ -n $2 ]] && vecho "${0##*/}: --bin takes no additional arguments" 1>&2 diff --git a/bin/quickpkg b/bin/quickpkg index 366eb1faa..88d7a9c03 100755 --- a/bin/quickpkg +++ b/bin/quickpkg @@ -6,10 +6,11 @@ import errno, signal, sys, os def quickpkg_main(options, args, eout): - from portage import dblink, dep_expand, catsplit, isvalidatom, xpak + from portage import catsplit, dep_expand, flatten, isvalidatom, xpak + from portage.dep import use_reduce, paren_reduce from portage.util import ensure_dirs - from portage.exception import InvalidData - from portage.dbapi.vartree import tar_contents + from portage.exception import InvalidData, InvalidDependString + from portage.dbapi.vartree import dblink, tar_contents import tarfile import portage root = portage.settings["ROOT"] @@ -54,12 +55,24 @@ def quickpkg_main(options, args, eout): if not dblnk.exists(): # unmerged by a concurrent process continue - iuse, use = vardb.aux_get(cpv, ["IUSE","USE"]) + iuse, use, restrict = vardb.aux_get(cpv, + ["IUSE","USE","RESTRICT"]) iuse = [ x.lstrip("+-") for x in iuse.split() ] use = use.split() + try: + restrict = flatten(use_reduce( + paren_reduce(restrict), uselist=use)) + except InvalidDependString, e: + eout.eerror("Invalid RESTRICT metadata " + \ + "for '%s': %s; skipping" % (cpv, str(e))) + del e + continue if "bindist" in iuse and "bindist" not in use: eout.ewarn("%s: package was emerged with USE=-bindist!" % cpv) eout.ewarn("%s: it may not be legal to redistribute this." % cpv) + elif "bindist" in restrict: + eout.ewarn("%s: package has RESTRICT=bindist!" % cpv) + eout.ewarn("%s: it may not be legal to redistribute this." % cpv) eout.ebegin("Building package for %s" % cpv) pkgs_for_arg += 1 contents = dblnk.getcontents() diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 534972666..907a27f3e 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2201,14 +2201,16 @@ class config(object): del x[mykey] def __getitem__(self,mykey): - match = '' - for x in self.lookuplist: - if x is None: - writemsg("!!! lookuplist is null.\n") - elif x.has_key(mykey): - match = x[mykey] - break - return match + for d in self.lookuplist: + if mykey in d: + return d[mykey] + return '' # for backward compat, don't raise KeyError + + def get(self, k, x=None): + for d in self.lookuplist: + if k in d: + return d[k] + return x def has_key(self,mykey): return mykey in self @@ -2221,29 +2223,24 @@ class config(object): return False def setdefault(self, k, x=None): - if k in self: - return self[k] + v = self.get(k) + if v is not None: + return v else: self[k] = x return x - def get(self, k, x=None): - if k in self: - return self[k] - else: - return x - def keys(self): return list(self) def __iter__(self): keys = set() for d in self.lookuplist: - for k in d: - if k in keys: - continue - keys.add(k) - yield k + keys.update(d) + return iter(keys) + + def iterkeys(self): + return iter(self) def __setitem__(self,mykey,myvalue): "set a value; will be thrown away at reset() time" diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py index 9d9effb63..3c213e496 100644 --- a/pym/portage/cache/anydbm.py +++ b/pym/portage/cache/anydbm.py @@ -60,7 +60,7 @@ class database(fs_template.FsBased): def _delitem(self, cpv): del self.__db[cpv] - def iterkeys(self): + def __iter__(self): return iter(self.__db) def __contains__(self, cpv): diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py index f9c575811..afaea94ad 100644 --- a/pym/portage/cache/flat_hash.py +++ b/pym/portage/cache/flat_hash.py @@ -102,7 +102,7 @@ class database(fs_template.FsBased): return os.path.exists(os.path.join(self.location, cpv)) - def iterkeys(self): + def __iter__(self): """generator for walking the dir struct""" dirs = [self.location] len_base = len(self.location) diff --git a/pym/portage/cache/flat_list.py b/pym/portage/cache/flat_list.py index 6dbbba96b..d3e480f96 100644 --- a/pym/portage/cache/flat_list.py +++ b/pym/portage/cache/flat_list.py @@ -86,7 +86,7 @@ class database(fs_template.FsBased): return os.path.exists(os.path.join(self._base, cpv)) - def iterkeys(self): + def __iter__(self): """generator for walking the dir struct""" dirs = [self._base] len_base = len(self._base) diff --git a/pym/portage/cache/metadata_overlay.py b/pym/portage/cache/metadata_overlay.py index ffc508e4e..db13f57b3 100644 --- a/pym/portage/cache/metadata_overlay.py +++ b/pym/portage/cache/metadata_overlay.py @@ -75,14 +75,14 @@ class database(template.database): return False return True - def iterkeys(self): + def __iter__(self): s = set() - for cpv in self.db_rw.iterkeys(): - if self.has_key(cpv): # validates whiteout when necessary + for cpv in self.db_rw: + if cpv in self: # validates whiteout when necessary yield cpv # set includes whiteouts so they won't be yielded later s.add(cpv) - for cpv in self.db_ro.iterkeys(): + for cpv in self.db_ro: if cpv not in s: yield cpv diff --git a/pym/portage/cache/sql_template.py b/pym/portage/cache/sql_template.py index 958195854..439990161 100644 --- a/pym/portage/cache/sql_template.py +++ b/pym/portage/cache/sql_template.py @@ -209,7 +209,7 @@ class SQLDatabase(template.database): return self.con.rowcount > 0 - def iterkeys(self): + def __iter__(self): if not self.autocommits: try: self.commit() except self._BaseError, e: diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index 1cab49978..dae9d4c1d 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -223,7 +223,7 @@ class database(fs_template.FsBased): else: raise cache_errors.CacheCorruption(cpv, "key is not unique") - def iterkeys(self): + def __iter__(self): """generator for walking the dir struct""" cursor = self._db_cursor cursor.execute("SELECT %s FROM %s" % \ diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index 5034fc8cb..b3994deb7 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -95,7 +95,7 @@ class database(object): return tuple(self.iterkeys()) def iterkeys(self): - raise NotImplementedError + return iter(self) def iteritems(self): for x in self.iterkeys(): @@ -123,6 +123,22 @@ class database(object): raise NotImplementedError return self.has_key(cpv) + def __iter__(self): + """This method should always be overridden. It is provided only for + backward compatibility with modules that override iterkeys instead. It + will automatically raise a NotImplementedError if iterkeys has not been + overridden.""" + if self.iterkeys is database.iterkeys: + # prevent a possible recursive loop + raise NotImplementedError(self) + return self.iterkeys() + + def get(self, k, x=None): + try: + return self[k] + except KeyError: + return x + def get_matches(self, match_dict): """generic function for walking the entire cache db, matching restrictions to filter what cpv's are returned. Derived classes should override this if they diff --git a/pym/portage/cache/util.py b/pym/portage/cache/util.py index 8884562ee..5c8f27056 100644 --- a/pym/portage/cache/util.py +++ b/pym/portage/cache/util.py @@ -18,7 +18,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, else: noise=verbose_instance - dead_nodes = set(trg_cache.iterkeys()) + dead_nodes = set(trg_cache) count=0 if not trg_cache.autocommits: diff --git a/pym/portage/cache/volatile.py b/pym/portage/cache/volatile.py index 555eafc5a..12c23dd56 100644 --- a/pym/portage/cache/volatile.py +++ b/pym/portage/cache/volatile.py @@ -16,7 +16,7 @@ class database(template.database): config.pop("gid", None) super(database, self).__init__(*args, **config) self._data = {} - self.iterkeys = self._data.iterkeys + self.__iter__ = self._data.__iter__ self._delitem = self._data.__delitem__ self.__contains__ = self._data.__contains__