From 10c4aa37d346536219bf98021ae45f71cc2b737d Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 22 Jun 2007 08:46:32 +0000 Subject: [PATCH] Merged from trunk 6889:6917 +------------------------------------------------------------------------+ | 6889 | Make the progress bar percentage indicator stop at 100% | | zmedico | instead of just 99%. | |----------+-------------------------------------------------------------| | 6890 | Use the the optparse options for --ignore-default-opts | | zmedico | since that allows option abreviation to work. | |----------+-------------------------------------------------------------| | 6892 | Add an --ignore-default-opts option that is analogous to | | zmedico | the corresponding emerge option. | |----------+-------------------------------------------------------------| | 6894 | In dblink._security_check(), use os.path.realpath to make | | zmedico | sure that the same path isn't counted twice. | |----------+-------------------------------------------------------------| | 6896 | as noted by Josh Saddler on the gentoo-dev mailing list, | | SpankMan | issue a warning if we try to create a binpkg for something | | | that has IUSE=bindist but was emerged with USE=-bindist | |----------+-------------------------------------------------------------| | 6897 | Make IUSE handling safe for IUSE defaults. | | zmedico | | |----------+-------------------------------------------------------------| | 6907 | Don't call digraph.hasallzeros() in --resume mode because | | zmedico | the digraph isn't currently populated in that case. | |----------+-------------------------------------------------------------| | 6909 | Don't generate a list of keys for a containment test. | | zmedico | | |----------+-------------------------------------------------------------| | 6911 | Remove lots of unnecessary list generation via dict.keys(). | | zmedico | | |----------+-------------------------------------------------------------| | 6912 | Remove more unnecessary list generation. | | zmedico | | |----------+-------------------------------------------------------------| | 6913 | Remove more unnecessary list generation. | | zmedico | | |----------+-------------------------------------------------------------| | 6914 | Implement UserConfigKlass.__iter__() so that tests pass. | | zmedico | | |----------+-------------------------------------------------------------| | 6915 | Fix the test so that it can run inside a sandbox. | | zmedico | | |----------+-------------------------------------------------------------| | 6916 | Implement config.has_key() on top of __contains__ instead | | zmedico | of vice versa. | |----------+-------------------------------------------------------------| | 6917 | Autodetect if sandbox is active in order to prevent | | zmedico | recursive sandbox invocation. Thanks to Brian Harring for | | | the suggestion. | +------------------------------------------------------------------------+ svn path=/main/branches/prefix/; revision=6944 --- bin/fix-db.py | 4 +- bin/md5check.py | 8 ++-- bin/portageq | 4 +- bin/quickpkg | 17 +++++-- bin/repoman | 6 +-- pym/emerge/__init__.py | 30 ++++++------ pym/portage/__init__.py | 47 +++++++++++-------- pym/portage/cache/template.py | 2 +- pym/portage/cache/util.py | 7 +-- pym/portage/checksum.py | 6 +-- pym/portage/cvstree.py | 20 ++++---- pym/portage/dbapi/bintree.py | 3 +- pym/portage/dbapi/porttree.py | 6 +-- pym/portage/dbapi/vartree.py | 20 +++++--- pym/portage/dbapi/virtual.py | 2 +- pym/portage/elog/__init__.py | 5 +- pym/portage/elog/filtering.py | 2 +- pym/portage/elog/messages.py | 2 +- pym/portage/elog/mod_custom.py | 3 +- pym/portage/elog/mod_echo.py | 2 +- pym/portage/elog/mod_mail_summary.py | 2 +- pym/portage/env/config.py | 3 ++ pym/portage/getbinpkg.py | 3 +- pym/portage/locks.py | 4 +- pym/portage/manifest.py | 7 ++- .../tests/env/config/test_PackageMaskFile.py | 3 +- .../env/config/test_PortageModulesFile.py | 2 +- pym/portage/tests/util/test_varExpand.py | 2 +- pym/portage/util.py | 6 +-- 29 files changed, 126 insertions(+), 102 deletions(-) diff --git a/bin/fix-db.py b/bin/fix-db.py index 3ea0fc602..223fad30a 100755 --- a/bin/fix-db.py +++ b/bin/fix-db.py @@ -137,7 +137,7 @@ for cat in os.listdir(vardbdir): actions = {} writemsg("\n\n") -for catpkg in bad.keys(): +for catpkg in bad: bad[catpkg].sort() mystr = "" @@ -156,7 +156,7 @@ for catpkg in bad.keys(): if (len(sys.argv) > 1) and (sys.argv[1] == "--fix"): writemsg("These are only directions, at the moment.") - for catpkg in actions.keys(): + for catpkg in actions: action = actions[catpkg] writemsg("We will now '%s' '%s'..." % (action, catpkg)) #if action == diff --git a/bin/md5check.py b/bin/md5check.py index f977e764a..f574de3cf 100755 --- a/bin/md5check.py +++ b/bin/md5check.py @@ -68,10 +68,10 @@ for mycpv in hugelist: else: continue - if mybn not in md5sums.keys(): + if mybn not in md5sums: portage.util.writemsg("Missing md5sum: %s in %s\n" % (mybn, mycpv)) else: - if mybn in md5_list.keys(): + if mybn in md5_list: if (md5_list[mybn]["MD5"] != md5sums[mybn]["MD5"]) or \ (md5_list[mybn]["size"] != md5sums[mybn]["size"]): @@ -89,12 +89,12 @@ for mycpv in hugelist: del md5sums[mybn] #portage.writemsg(str(bn_list)+"\n") - for x in md5sums.keys(): + for x in md5sums: if x not in bn_list: portage.writemsg("Extra md5sum: %s in %s\n" % (x, mycpv)) print col_list print -print str(len(md5_list.keys()))+" unique distfile md5s." +print str(len(md5_list))+" unique distfile md5s." print str(len(bn_list))+" unique distfile names." diff --git a/bin/portageq b/bin/portageq index 653bcf229..e0fef37b4 100755 --- a/bin/portageq +++ b/bin/portageq @@ -295,7 +295,7 @@ def list_preserved_libs(argv): sys.exit(2) mylibs = portage.db[argv[0]]["vartree"].dbapi.plib_registry.getPreservedLibs() rValue = 0 - for cpv in mylibs.keys(): + for cpv in mylibs: for path in mylibs[cpv]: print "%s: %s" % (cpv, path) rValue = 1 @@ -318,7 +318,7 @@ def usage(argv): # Show our commands -- we do this by scanning the functions in this # file, and formatting each functions documentation. # - commands = [x for x in globals().keys() if x not in \ + commands = [x for x in globals() if x not in \ ("usage", "__doc__", "__name__", "main", "os", "portage", \ "sys", "__builtins__", "types", "string","exithandler")] commands.sort() diff --git a/bin/quickpkg b/bin/quickpkg index 0dd9c7fc8..366eb1faa 100755 --- a/bin/quickpkg +++ b/bin/quickpkg @@ -54,6 +54,12 @@ 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 = [ x.lstrip("+-") for x in iuse.split() ] + use = use.split() + 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) eout.ebegin("Building package for %s" % cpv) pkgs_for_arg += 1 contents = dblnk.getcontents() @@ -124,9 +130,14 @@ if __name__ == "__main__": parser.add_option("--umask", default="0077", help="umask used during package creation (default is 0077)") - from portage import settings - default_opts = settings.get("QUICKPKG_DEFAULT_OPTS","").split() - options, args = parser.parse_args(default_opts + sys.argv[1:]) + parser.add_option("--ignore-default-opts", + action="store_true", + help="do not use the QUICKPKG_DEFAULT_OPTS environment variable") + options, args = parser.parse_args(sys.argv[1:]) + if not options.ignore_default_opts: + from portage import settings + default_opts = settings.get("QUICKPKG_DEFAULT_OPTS","").split() + options, args = parser.parse_args(default_opts + sys.argv[1:]) if not args: parser.error("no packages atoms given") try: diff --git a/bin/repoman b/bin/repoman index 7410d8b4c..751a4ffde 100755 --- a/bin/repoman +++ b/bin/repoman @@ -353,9 +353,9 @@ myoptions=[] if len(sys.argv)>1: x=1 while x < len(sys.argv): - if sys.argv[x] in shortmodes.keys(): + if sys.argv[x] in shortmodes: sys.argv[x]=shortmodes[sys.argv[x]] - elif sys.argv[x] in repoman_shortoptions.keys(): + elif sys.argv[x] in repoman_shortoptions: sys.argv[x] = repoman_shortoptions[sys.argv[x]] if sys.argv[x] in modes: if mymode is None: @@ -1597,7 +1597,7 @@ def grouplist(mylist,seperator="/"): xs=x.split(seperator) if xs[0]==".": xs=xs[1:] - if xs[0] not in mygroups.keys(): + if xs[0] not in mygroups: mygroups[xs[0]]=[seperator.join(xs[1:])] else: mygroups[xs[0]]+=[seperator.join(xs[1:])] diff --git a/pym/emerge/__init__.py b/pym/emerge/__init__.py index 23d29c6bb..e150ca49b 100644 --- a/pym/emerge/__init__.py +++ b/pym/emerge/__init__.py @@ -209,7 +209,7 @@ def emergelog(xterm_titles, mystr, short_msg=None): if xterm_titles: if short_msg == None: short_msg = mystr - if "HOSTNAME" in os.environ.keys(): + if "HOSTNAME" in os.environ: short_msg = os.environ["HOSTNAME"]+": "+short_msg xtermTitle(short_msg) try: @@ -442,7 +442,7 @@ class search(object): if self.searchre.search(full_desc): self.matches["desc"].append([full_package,masked]) self.mlen=0 - for mtype in self.matches.keys(): + for mtype in self.matches: self.matches[mtype].sort() self.mlen += len(self.matches[mtype]) @@ -451,7 +451,7 @@ class search(object): print "\b\b \n[ Results for search key : "+white(self.searchkey)+" ]" print "[ Applications found : "+white(str(self.mlen))+" ]" print " " - for mtype in self.matches.keys(): + for mtype in self.matches: for match,masked in self.matches[mtype]: if mtype=="pkg": catpack=match @@ -2215,7 +2215,7 @@ class depgraph(object): mylist = getlist(self.settings, "system") worlddict=genericdict(worldlist) - for x in worlddict.keys(): + for x in worlddict: if not portage.isvalidatom(x): world_problems = True continue @@ -2698,7 +2698,7 @@ class depgraph(object): if myfilesdict is None: myfilesdict="[empty/missing/bad digest]" else: - for myfetchfile in myfilesdict.keys(): + for myfetchfile in myfilesdict: if myfetchfile not in myfetchlist: mysize+=myfilesdict[myfetchfile] myfetchlist.append(myfetchfile) @@ -3613,7 +3613,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files, if not slotmap.has_key(myslot): slotmap[myslot]={} slotmap[myslot][localtree.dbapi.cpv_counter(mypkg)]=mypkg - for myslot in slotmap.keys(): + for myslot in slotmap: counterkeys=slotmap[myslot].keys() counterkeys.sort() if not counterkeys: @@ -3640,7 +3640,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files, finally: if vdb_lock: portage.locks.unlockdir(vdb_lock) - for x in pkgmap.keys(): + for x in pkgmap: for y in localtree.dep_match(x): if y not in pkgmap[x]["omitted"] and \ y not in pkgmap[x]["selected"] and \ @@ -3696,7 +3696,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files, if not autoclean: countdown(int(settings["CLEAN_DELAY"]), ">>> Unmerging") - for x in pkgmap.keys(): + for x in pkgmap: for y in pkgmap[x]["selected"]: print ">>> Unmerging "+y+"..." emergelog(xterm_titles, "=== Unmerging... ("+y+")") @@ -3880,7 +3880,7 @@ def post_emerge(trees, mtimedb, retval): if vardbapi.plib_registry.hasEntries(): print colorize("WARN", "!!!") + " existing preserved libs:" plibdata = vardbapi.plib_registry.getPreservedLibs() - for cpv in plibdata.keys(): + for cpv in plibdata: print colorize("WARN", ">>>") + " package: %s" % cpv for f in plibdata[cpv]: print colorize("WARN", " * ") + " - %s" % f @@ -5188,11 +5188,11 @@ def action_build(settings, trees, mtimedb, else: mydepgraph.display( mydepgraph.altlist(reversed=("--tree" in myopts))) - if ("--buildpkgonly" in myopts): - if not mydepgraph.digraph.hasallzeros(ignore_priority=DepPriority.MEDIUM): - print "\n!!! --buildpkgonly requires all dependencies to be merged." - print "!!! You have to merge the dependencies before you can build this package.\n" - sys.exit(1) + if "--buildpkgonly" in myopts and \ + not mydepgraph.digraph.hasallzeros(ignore_priority=DepPriority.MEDIUM): + print "\n!!! --buildpkgonly requires all dependencies to be merged." + print "!!! You have to merge the dependencies before you can build this package.\n" + sys.exit(1) else: if ("--buildpkgonly" in myopts): if not mydepgraph.digraph.hasallzeros(ignore_priority=DepPriority.MEDIUM): @@ -5510,7 +5510,7 @@ def emerge_main(): xterm_titles = "notitles" not in settings.features tmpcmdline = [] - if "--ignore-default-opts" not in sys.argv: + if "--ignore-default-opts" not in myopts: tmpcmdline.extend(settings["EMERGE_DEFAULT_OPTS"].split()) tmpcmdline.extend(sys.argv[1:]) myaction, myopts, myfiles = parse_opts(tmpcmdline) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index bd27baa7c..534972666 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1653,9 +1653,8 @@ class config(object): def load_infodir(self,infodir): self.modifying() - if self.configdict.has_key("pkg"): - for x in self.configdict["pkg"].keys(): - del self.configdict["pkg"][x] + if "pkg" in self.configdict: + self.configdict["pkg"].clear() else: writemsg("No pkg setup for settings instance?\n", noiselevel=-1) @@ -2114,8 +2113,7 @@ class config(object): return self.virts_p virts = self.getvirtuals(myroot) if virts: - myvkeys = virts.keys() - for x in myvkeys: + for x in virts: vkeysplit = x.split("/") if not self.virts_p.has_key(vkeysplit[1]): self.virts_p[vkeysplit[1]] = virts[x] @@ -2213,14 +2211,14 @@ class config(object): return match def has_key(self,mykey): - for x in self.lookuplist: - if x.has_key(mykey): - return 1 - return 0 + return mykey in self def __contains__(self, mykey): """Called to implement membership test operators (in and not in).""" - return bool(self.has_key(mykey)) + for d in self.lookuplist: + if mykey in d: + return True + return False def setdefault(self, k, x=None): if k in self: @@ -2236,7 +2234,16 @@ class config(object): return x def keys(self): - return unique_array(flatten([x.keys() for x in self.lookuplist])) + 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 def __setitem__(self,mykey,myvalue): "set a value; will be thrown away at reset() time" @@ -2249,7 +2256,7 @@ class config(object): def environ(self): "return our locally-maintained environment" mydict={} - for x in self.keys(): + for x in self: myvalue = self[x] if not isinstance(myvalue, basestring): writemsg("!!! Non-string value in config: %s=%s\n" % \ @@ -2425,7 +2432,7 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, **keyw (not droppriv and "sandbox" not in features and \ "usersandbox" not in features)) - if free: + if free or "SANDBOX_ACTIVE" in os.environ: keywords["opt_name"] += " bash" spawn_func = portage.process.spawn_bash else: @@ -2648,7 +2655,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", noiselevel=-1) return 0 del distlocks_subdir - for myfile in filedict.keys(): + for myfile in filedict: """ fetched status 0 nonexistent @@ -2879,7 +2886,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", else: eout = portage.output.EOutput() eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1" - for x_key in mydigests[myfile].keys(): + for x_key in mydigests[myfile]: eout.ebegin("%s %s ;-)" % (myfile, x_key)) eout.eend(0) fetched=2 @@ -3135,7 +3142,7 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0): def spawnebuild(mydo,actionmap,mysettings,debug,alwaysdep=0,logfile=None): if alwaysdep or "noauto" not in mysettings.features: # process dependency first - if "dep" in actionmap[mydo].keys(): + if "dep" in actionmap[mydo]: retval=spawnebuild(actionmap[mydo]["dep"],actionmap,mysettings,debug,alwaysdep=alwaysdep,logfile=logfile) if retval: return retval @@ -3944,11 +3951,11 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, # merge the deps in so we have again a 'full' actionmap # be glad when this can die. - for x in actionmap.keys(): + for x in actionmap: if len(actionmap_deps.get(x, [])): actionmap[x]["dep"] = ' '.join(actionmap_deps[x]) - if mydo in actionmap.keys(): + if mydo in actionmap: retval = spawnebuild(mydo, actionmap, mysettings, debug, logfile=logfile) elif mydo=="qmerge": @@ -4954,9 +4961,11 @@ class FetchlistDict(UserDict.DictMixin): """Returns the complete fetch list for a given package.""" return self.portdb.getfetchlist(pkg_key, mysettings=self.settings, all=True, mytree=self.mytree)[1] + def __contains__(self): + return pkg_key in self.keys() def has_key(self, pkg_key): """Returns true if the given package exists within pkgdir.""" - return pkg_key in self.keys() + return pkg_key in self def keys(self): """Returns keys for all packages within pkgdir""" return self.portdb.cp_list(self.cp, mytree=self.mytree) diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index c0aea17ac..5034fc8cb 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -145,7 +145,7 @@ class database(object): if key not in self.__known_keys: raise InvalidRestriction(key, match, "Key isn't valid") - for cpv in self.keys(): + for cpv in self.iterkeys(): cont = True vals = self[cpv] for key, match in restricts.iteritems(): diff --git a/pym/portage/cache/util.py b/pym/portage/cache/util.py index c31dc9163..8884562ee 100644 --- a/pym/portage/cache/util.py +++ b/pym/portage/cache/util.py @@ -18,8 +18,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, else: noise=verbose_instance - dead_nodes = {} - dead_nodes = dict.fromkeys(trg_cache.keys()) + dead_nodes = set(trg_cache.iterkeys()) count=0 if not trg_cache.autocommits: @@ -28,8 +27,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, for x in valid_nodes_iterable: # print "processing x=",x count+=1 - if dead_nodes.has_key(x): - del dead_nodes[x] + dead_nodes.discard(x) try: entry = src_cache[x] except KeyError, e: noise.missing_entry(x) @@ -99,7 +97,6 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, except cache_errors.CacheError, ce: noise.exception(ce) del ce - dead_nodes.clear() noise.finish() diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index de4be208c..576d502b2 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -79,7 +79,7 @@ def perform_md5(x, calc_prelink=0): def perform_all(x, calc_prelink=0): mydict = {} - for k in hashfunc_map.keys(): + for k in hashfunc_map: mydict[k] = perform_checksum(x, hashfunc_map[k], calc_prelink)[0] return mydict @@ -131,10 +131,10 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0): got = " ".join(got) return False, ("Insufficient data for checksum verification", got, expected) - for x in mydict.keys(): + for x in mydict: if x == "size": continue - elif x in hashfunc_map.keys(): + elif x in hashfunc_map: myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0] if mydict[x] != myhash: if strict: diff --git a/pym/portage/cvstree.py b/pym/portage/cvstree.py index 8a9450afd..ede3ad589 100644 --- a/pym/portage/cvstree.py +++ b/pym/portage/cvstree.py @@ -64,12 +64,12 @@ def findnew(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "0" == entries["files"][myfile]["revision"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findnew(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -81,14 +81,14 @@ def findchanged(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "current" not in entries["files"][myfile]["status"]: if "exists" in entries["files"][myfile]["status"]: if entries["files"][myfile]["revision"]!="0": mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findchanged(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -100,13 +100,13 @@ def findmissing(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "exists" not in entries["files"][myfile]["status"]: if "removed" not in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findmissing(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -120,11 +120,11 @@ def findunadded(entries,recursive=0,basedir=""): mylist=[] #ignore what cvs ignores. - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" not in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findunadded(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -135,11 +135,11 @@ def findremoved(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "removed" in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findremoved(entries["dirs"][mydir],recursive,basedir+mydir) return mylist diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 713a8c612..3242cc158 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -506,8 +506,7 @@ class binarytree(object): # since it will provide no benefit due to the need to read CATEGORY # from xpak. if update_pkgindex and os.access(self.pkgdir, os.W_OK): - cpv_all = self._pkg_paths.keys() - stale = set(metadata).difference(cpv_all) + stale = [cpv for cpv in metadata if cpv not in self._pkg_paths] for cpv in stale: del metadata[cpv] from portage.util import atomic_ofstream diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 0f23ce70e..524a36fa2 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -144,7 +144,7 @@ class portdbapi(dbapi): if not hasattr(self, "auxdb"): # unhandled exception thrown from constructor return - for x in self.auxdb.keys(): + for x in self.auxdb: self.auxdb[x].sync() self.auxdb.clear() @@ -192,7 +192,7 @@ class portdbapi(dbapi): repository ID's TreeMap = {id: path} """ - return [k for k in self.treemap.keys() if k] + return [k for k in self.treemap if k] def findname2(self, mycpv, mytree=None): """ @@ -348,7 +348,7 @@ class portdbapi(dbapi): returnme = [] for x in mylist: if x == "INHERITED": - returnme.append(' '.join(mydata.get("_eclasses_", {}).keys())) + returnme.append(' '.join(mydata.get("_eclasses_", []))) else: returnme.append(mydata.get(x,"")) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 35ed7fe08..7a3cf5768 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -106,7 +106,7 @@ class PreservedLibsRegistry(object): def hasEntries(self): """ Check if this registry contains any records. """ - return (len(self._data.keys()) > 0) + return len(self._data) > 0 def getPreservedLibs(self): """ Return a mapping of packages->preserved objects. @@ -114,7 +114,7 @@ class PreservedLibsRegistry(object): @rtype Dict cpv->list-of-paths """ rValue = {} - for cps in self._data.keys(): + for cps in self._data: rValue[self._data[cps][0]] = self._data[cps][2] return rValue @@ -154,7 +154,7 @@ class LibraryPackageMap(object): else: obj_dict[lib].append(mysplit[0]) mapfile = open(self._filename, "w") - for lib in obj_dict.keys(): + for lib in obj_dict: mapfile.write(lib+" "+",".join(obj_dict[lib])+"\n") mapfile.close() @@ -1337,10 +1337,10 @@ class dblink(object): # get list of libraries from old package instance old_contents = self._installed_instance.getcontents().keys() - old_libs = set([os.path.basename(x) for x in old_contents]).intersection(libmap.keys()) + old_libs = set([os.path.basename(x) for x in old_contents]).intersection(libmap) # get list of libraries from new package instance - mylibs = set([os.path.basename(x) for x in mycontents]).intersection(libmap.keys()) + mylibs = set([os.path.basename(x) for x in mycontents]).intersection(libmap) # check which libs are present in the old, but not the new package instance preserve_libs = old_libs.difference(mylibs) @@ -1506,6 +1506,7 @@ class dblink(object): for dblnk in installed_instances: file_paths.update(dblnk.getcontents()) inode_map = {} + real_paths = set() for path in file_paths: try: s = os.lstat(path) @@ -1514,8 +1515,13 @@ class dblink(object): raise del e continue - if stat.S_ISREG(s.st_mode) and \ - s.st_nlink > 1 and \ + if not stat.S_ISREG(s.st_mode): + continue + path = os.path.realpath(path) + if path in real_paths: + continue + real_paths.add(path) + if s.st_nlink > 1 and \ s.st_mode & (stat.S_ISUID | stat.S_ISGID): k = (s.st_dev, s.st_ino) inode_map.setdefault(k, []).append((path, s)) diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py index 055503ab8..983e39b7f 100644 --- a/pym/portage/dbapi/virtual.py +++ b/pym/portage/dbapi/virtual.py @@ -40,7 +40,7 @@ class fakedbapi(dbapi): def cp_all(self): returnme=[] - for x in self.cpdict.keys(): + for x in self.cpdict: returnme.extend(self.cpdict[x]) return returnme diff --git a/pym/portage/elog/__init__.py b/pym/portage/elog/__init__.py index 77bdd1b94..5b8ac44c3 100644 --- a/pym/portage/elog/__init__.py +++ b/pym/portage/elog/__init__.py @@ -15,7 +15,8 @@ import os def _merge_logentries(a, b): rValue = {} - phases = set(a.keys()+b.keys()) + phases = set(a) + phases.update(b) for p in phases: rValue[p] = [] if a.has_key(p): @@ -51,7 +52,7 @@ def elog_process(cpv, mysettings): my_elog_classes = set(mysettings.get("PORTAGE_ELOG_CLASSES", "").split()) - for key in all_logentries.keys(): + for key in all_logentries: default_logentries = filter_loglevels(all_logentries[key], my_elog_classes) # in case the filters matched all messages and no module overrides exist diff --git a/pym/portage/elog/filtering.py b/pym/portage/elog/filtering.py index f4748fede..e8a5430fd 100644 --- a/pym/portage/elog/filtering.py +++ b/pym/portage/elog/filtering.py @@ -7,7 +7,7 @@ def filter_loglevels(logentries, loglevels): # remove unwanted entries from all logentries rValue = {} loglevels = map(str.upper, loglevels) - for phase in logentries.keys(): + for phase in logentries: for msgtype, msgcontent in logentries[phase]: if msgtype.upper() in loglevels or "*" in loglevels: if not rValue.has_key(phase): diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py index bfe428030..c2b21ac80 100644 --- a/pym/portage/elog/messages.py +++ b/pym/portage/elog/messages.py @@ -84,6 +84,6 @@ def _make_msgfunction(level, color): return _elog import sys -for f in _functions.keys(): +for f in _functions: setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1])) del f, _functions diff --git a/pym/portage/elog/mod_custom.py b/pym/portage/elog/mod_custom.py index a486c8931..09d981a0c 100644 --- a/pym/portage/elog/mod_custom.py +++ b/pym/portage/elog/mod_custom.py @@ -8,8 +8,7 @@ import portage.elog_modules.mod_save, portage.process, portage.exception def process(mysettings, key, logentries, fulltext): elogfilename = portage.elog_modules.mod_save.process(mysettings, key, logentries, fulltext) - if (not "PORTAGE_ELOG_COMMAND" in mysettings.keys()) \ - or len(mysettings["PORTAGE_ELOG_COMMAND"]) == 0: + if not mysettings.get("PORTAGE_ELOG_COMMAND"): raise portage.exception.MissingParameter("!!! Custom logging requested but PORTAGE_ELOG_COMMAND is not defined") else: mylogcmd = mysettings["PORTAGE_ELOG_COMMAND"] diff --git a/pym/portage/elog/mod_echo.py b/pym/portage/elog/mod_echo.py index 125a8c40e..6dcc65233 100644 --- a/pym/portage/elog/mod_echo.py +++ b/pym/portage/elog/mod_echo.py @@ -12,7 +12,7 @@ def process(mysettings, key, logentries, fulltext): def finalize(mysettings): printer = EOutput() - for key in _items.keys(): + for key in _items: print printer.einfo("Messages for package %s:" % key) print diff --git a/pym/portage/elog/mod_mail_summary.py b/pym/portage/elog/mod_mail_summary.py index a8e694935..0a39b17b1 100644 --- a/pym/portage/elog/mod_mail_summary.py +++ b/pym/portage/elog/mod_mail_summary.py @@ -31,7 +31,7 @@ def finalize(mysettings): mybody = "elog messages for the following packages generated by " + \ "process %d on host %s:\n" % (os.getpid(), socket.getfqdn()) - for key in _items.keys(): + for key in _items: mybody += "- %s\n" % key mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, mybody, attachments=_items.values()) diff --git a/pym/portage/env/config.py b/pym/portage/env/config.py index 192d10852..a354dcf7d 100644 --- a/pym/portage/env/config.py +++ b/pym/portage/env/config.py @@ -30,6 +30,9 @@ class UserConfigKlass(UserDict,object): self.data, self.errors = self._loader.load() + def __iter__(self): + return iter(self.data) + class PackageKeywordsFile(UserConfigKlass): """ Inherits from UserConfigKlass; implements a file-based backend. diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 79ddca545..760fa103c 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -516,8 +516,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= for x in tbz2list: x = os.path.basename(x) binpkg_filenames.add(x) - if ((not metadata[baseurl]["data"].has_key(x)) or \ - (x not in metadata[baseurl]["data"].keys())): + if x not in metadata[baseurl]["data"]: sys.stderr.write(yellow("x")) metadata[baseurl]["modified"] = 1 myid = None diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 836b8306a..bed8ed36a 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -285,13 +285,13 @@ def hardlock_cleanup(path, remove_all_locks=False): results.append("Found %(count)s locks" % {"count":mycount}) - for x in mylist.keys(): + for x in mylist: if mylist[x].has_key(myhost) or remove_all_locks: mylockname = hardlock_name(path+"/"+x) if hardlink_is_mine(mylockname, path+"/"+x) or \ not os.path.exists(path+"/"+x) or \ remove_all_locks: - for y in mylist[x].keys(): + for y in mylist[x]: for z in mylist[x][y]: filename = path+"/"+x+".hardlock-"+y+"-"+z if filename == mylockname: diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index cd03dc293..5add55c81 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -79,8 +79,7 @@ class ManifestEntry(object): class Manifest1Entry(ManifestEntry): def __str__(self): - myhashkeys = self.hashes.keys() - for hashkey in myhashkeys: + for hashkey in self.hashes: if hashkey != "size": break hashvalue = self.hashes[hashkey] @@ -345,9 +344,9 @@ class Manifest(object): pass def checkIntegrity(self): - for t in self.fhashdict.keys(): + for t in self.fhashdict: for f in self.fhashdict[t]: - if not portage.const.MANIFEST2_REQUIRED_HASH in self.fhashdict[t][f].keys(): + if portage.const.MANIFEST2_REQUIRED_HASH not in self.fhashdict[t][f]: raise MissingParameter("Missing %s checksum: %s %s" % (portage.const.MANIFEST2_REQUIRED_HASH, t, f)) def write(self, sign=False, force=False): diff --git a/pym/portage/tests/env/config/test_PackageMaskFile.py b/pym/portage/tests/env/config/test_PackageMaskFile.py index ad87d5a56..e8357f7e6 100644 --- a/pym/portage/tests/env/config/test_PackageMaskFile.py +++ b/pym/portage/tests/env/config/test_PackageMaskFile.py @@ -18,7 +18,8 @@ class PackageMaskFileTestCase(TestCase): try: f = PackageMaskFile(self.fname) f.load() - [atom for atom in f.keys() if self.assertTrue(atom in self.atoms)] + for atom in f: + self.assertTrue(atom in self.atoms) finally: self.NukeFile() diff --git a/pym/portage/tests/env/config/test_PortageModulesFile.py b/pym/portage/tests/env/config/test_PortageModulesFile.py index b523cbe7b..03104cff5 100644 --- a/pym/portage/tests/env/config/test_PortageModulesFile.py +++ b/pym/portage/tests/env/config/test_PortageModulesFile.py @@ -18,7 +18,7 @@ class PortageModulesFileTestCase(TestCase): def testPortageModulesFile(self): self.BuildFile() f = PortageModulesFile(self.fname) - for k in f.keys(): + for k in f: self.assertEqual( f[k], self.items[k] ) self.NukeFile() diff --git a/pym/portage/tests/util/test_varExpand.py b/pym/portage/tests/util/test_varExpand.py index ee0f573c9..e4f85ef43 100644 --- a/pym/portage/tests/util/test_varExpand.py +++ b/pym/portage/tests/util/test_varExpand.py @@ -11,7 +11,7 @@ class VarExpandTestCase(TestCase): def testVarExpandPass(self): varDict = { "a":"5", "b":"7", "c":"-5" } - for key in varDict.keys(): + for key in varDict: result = varexpand( "$%s" % key, varDict ) self.failIf( result != varDict[key], diff --git a/pym/portage/util.py b/pym/portage/util.py index bf1bbe9df..ebaafd70d 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -77,7 +77,7 @@ def map_dictlist_vals(func,myDict): """Performs a function on each value of each key in a dictlist. Returns a new dictlist.""" new_dl = {} - for key in myDict.keys(): + for key in myDict: new_dl[key] = [] new_dl[key] = map(func,myDict[key]) return new_dl @@ -119,7 +119,7 @@ def stack_dictlist(original_dicts, incremental=0, incrementals=[], ignore_none=0 for mydict in original_dicts: if mydict is None: continue - for y in mydict.keys(): + for y in mydict: if not y in final_dict: final_dict[y] = [] @@ -281,7 +281,7 @@ def writedict(mydict,myfilename,writekey=True): for x in mydict.values(): myfile.write(x+"\n") else: - for x in mydict.keys(): + for x in mydict: myfile.write("%s %s\n" % (x, " ".join(mydict[x]))) myfile.close() except IOError: -- 2.26.2