From cea664c68e658ab10031ce65b66964e684671ede Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Thu, 24 Sep 2009 17:25:35 +0000 Subject: [PATCH] Merged from trunk -r14378:14388 | 14379 | Replace doct.keys() usage with __iter__(), since it behaves | | zmedico | identically in both python 2.x and 3.x. | | 14380 | Replace dict.keys() usage with __iter__(), since it behaves | | zmedico | identically in both python 2.x and 3.x. | | 14381 | Fix for python 3.x compatibility. | | zmedico | | | 14382 | Replace dict.keys() usage with __iter__(), since it behaves | | zmedico | identically in both python 2.x and 3.x. | | 14383 | Remove code that's been commented out. | | zmedico | | | 14384 | Replace dict.keys() usage with __iter__(), since it behaves | | zmedico | identically in both python 2.x and 3.x. | | 14385 | Replace dict.keys() usage with __iter__(), since it behaves | | zmedico | identically in both python 2.x and 3.x. | | 14386 | Disable the ignore_none parameter for stack_dicts() since | | zmedico | having it return None instead of a dict sometimes is | | | hazardous. | | 14387 | Clean up stack_dicts() a little. | | zmedico | | | 14388 | Don't pass the ignore_none parameter to stack_dicts() since | | zmedico | it does nothing now. | svn path=/main/branches/prefix/; revision=14405 --- bin/egencache | 4 ++-- bin/emaint | 2 +- bin/glsa-check | 4 ++-- bin/repoman | 8 ++++---- pym/_emerge/MetadataRegen.py | 4 ++-- pym/_emerge/PollSelectAdapter.py | 2 +- pym/_emerge/actions.py | 4 ++-- pym/_emerge/unmerge.py | 2 +- pym/portage/__init__.py | 24 ++++++++++++------------ pym/portage/cache/anydbm.py | 18 +++++++++++++----- pym/portage/cache/mappings.py | 4 ++-- pym/portage/cache/template.py | 10 +++++----- pym/portage/checksum.py | 2 +- pym/portage/cvstree.py | 18 ------------------ pym/portage/dbapi/bintree.py | 2 +- pym/portage/dbapi/porttree.py | 4 ++-- pym/portage/dbapi/vartree.py | 10 +++++----- pym/portage/dbapi/virtual.py | 2 +- pym/portage/elog/__init__.py | 2 +- pym/portage/elog/mod_mail.py | 4 ++-- pym/portage/getbinpkg.py | 4 ++-- pym/portage/glsa.py | 6 +++--- pym/portage/manifest.py | 8 ++++---- pym/portage/sets/base.py | 2 +- pym/portage/sets/dbapi.py | 2 +- pym/portage/sets/files.py | 10 +++++----- pym/portage/util.py | 21 ++++++++------------- 27 files changed, 84 insertions(+), 99 deletions(-) diff --git a/bin/egencache b/bin/egencache index 79b12dc7a..47f93c792 100755 --- a/bin/egencache +++ b/bin/egencache @@ -204,7 +204,7 @@ class GenCache(object): dead_nodes = set() if self._global_cleanse: try: - for cpv in trg_cache.keys(): + for cpv in trg_cache: cp = cpv_getkey(cpv) if cp is None: self.returncode |= 1 @@ -224,7 +224,7 @@ class GenCache(object): else: cp_set = self._cp_set try: - for cpv in trg_cache.keys(): + for cpv in trg_cache: cp = cpv_getkey(cpv) if cp is None: self.returncode |= 1 diff --git a/bin/emaint b/bin/emaint index 3279bc321..76257eb2c 100755 --- a/bin/emaint +++ b/bin/emaint @@ -477,7 +477,7 @@ def emaint_main(myargv): "cleanresume":CleanResume } - module_names = list(modules.keys()) + module_names = list(modules) module_names.sort() module_names.insert(0, "all") diff --git a/bin/glsa-check b/bin/glsa-check index 0bcecc092..14258823c 100755 --- a/bin/glsa-check +++ b/bin/glsa-check @@ -174,12 +174,12 @@ def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr): fd1.write(color(myglsa.nr) + " " + color(status) + " " + color(access) + myglsa.title + " (") if not verbose: - for pkg in list(myglsa.packages.keys())[:3]: + for pkg in list(myglsa.packages)[:3]: fd1.write(" " + pkg + " ") if len(myglsa.packages) > 3: fd1.write("... ") else: - for pkg in myglsa.packages.keys(): + for pkg in myglsa.packages: mylist = vardb.match(portage.dep_getkey(str(pkg))) if len(mylist) > 0: pkg = color(" ".join(mylist)) diff --git a/bin/repoman b/bin/repoman index 715f5649a..de78f903b 100755 --- a/bin/repoman +++ b/bin/repoman @@ -151,7 +151,7 @@ def ParseArgs(args, qahelp): 'scan' : 'Scan directory tree for QA issues' } - mode_keys = list(modes.keys()) + mode_keys = list(modes) mode_keys.sort() parser = RepomanOptionParser(formatter=RepomanHelpFormatter(), usage="%prog [options] [mode]") @@ -196,7 +196,7 @@ def ParseArgs(args, qahelp): parser.add_option('--without-mask', dest='without_mask', action='store_true', default=False, help='behave as if no package.mask entries exist (not allowed with commit mode)') - parser.add_option('--mode', type='choice', dest='mode', choices=list(modes.keys()), + parser.add_option('--mode', type='choice', dest='mode', choices=list(modes), help='specify which mode repoman will run in (default=full)') parser.on_tail("\n " + green("Modes".ljust(20) + " Description\n")) @@ -206,7 +206,7 @@ def ParseArgs(args, qahelp): parser.on_tail("\n " + green("QA keyword".ljust(20) + " Description\n")) - sorted_qa = list(qahelp.keys()) + sorted_qa = list(qahelp) sorted_qa.sort() for k in sorted_qa: parser.on_tail(" %s %s\n" % (k.ljust(20), qahelp[k])) @@ -328,7 +328,7 @@ qahelp={ "upstream.workaround":"The ebuild works around an upstream bug, an upstream bug should be filed and tracked in bugs.gentoo.org" } -qacats = list(qahelp.keys()) +qacats = list(qahelp) qacats.sort() qawarnings = set(( diff --git a/pym/_emerge/MetadataRegen.py b/pym/_emerge/MetadataRegen.py index 6bfd722c2..287312e17 100644 --- a/pym/_emerge/MetadataRegen.py +++ b/pym/_emerge/MetadataRegen.py @@ -89,7 +89,7 @@ class MetadataRegen(PollScheduler): if self._global_cleanse: for mytree in portdb.porttrees: try: - dead_nodes[mytree] = set(portdb.auxdb[mytree].keys()) + dead_nodes[mytree] = set(portdb.auxdb[mytree]) except CacheError as e: portage.writemsg("Error listing cache entries for " + \ "'%s': %s, continuing...\n" % (mytree, e), @@ -103,7 +103,7 @@ class MetadataRegen(PollScheduler): for mytree in portdb.porttrees: try: dead_nodes[mytree] = set(cpv for cpv in \ - portdb.auxdb[mytree].keys() \ + portdb.auxdb[mytree] \ if cpv_getkey(cpv) in cp_set) except CacheError as e: portage.writemsg("Error listing cache entries for " + \ diff --git a/pym/_emerge/PollSelectAdapter.py b/pym/_emerge/PollSelectAdapter.py index 7b7d3d95a..b136e7eb0 100644 --- a/pym/_emerge/PollSelectAdapter.py +++ b/pym/_emerge/PollSelectAdapter.py @@ -48,7 +48,7 @@ class PollSelectAdapter(PollConstants): select_args = self._select_args if select_args is None: - select_args = [list(self._registered.keys()), [], []] + select_args = [list(self._registered), [], []] if timeout is not None: select_args = select_args[:] diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index fcf0453c9..31d85dd40 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -1290,7 +1290,7 @@ def action_info(settings, trees, myopts, myfiles): libtool_vers = ",".join(trees["/"]["vartree"].dbapi.match("sys-devel/libtool")) if "--verbose" in myopts: - myvars=list(settings.keys()) + myvars = list(settings) else: myvars = ['GENTOO_MIRRORS', 'CONFIG_PROTECT', 'CONFIG_PROTECT_MASK', 'PORTDIR', 'DISTDIR', 'PKGDIR', 'PORTAGE_TMPDIR', @@ -1650,7 +1650,7 @@ def action_metadata(settings, portdb, myopts, porttrees=None): for tree_data in porttrees_data: try: - dead_nodes = set(tree_data.dest_db.keys()) + dead_nodes = set(tree_data.dest_db) except CacheError as e: writemsg_level("Error listing cache entries for " + \ "'%s': %s, continuing...\n" % (tree_data.path, e), diff --git a/pym/_emerge/unmerge.py b/pym/_emerge/unmerge.py index b97207d68..4d2a546c5 100644 --- a/pym/_emerge/unmerge.py +++ b/pym/_emerge/unmerge.py @@ -243,7 +243,7 @@ def unmerge(root_config, myopts, unmerge_action, slotmap[myslot][vartree.dbapi.cpv_counter(mypkg)] = mypkg for myslot in slotmap: - counterkeys = list(slotmap[myslot].keys()) + counterkeys = list(slotmap[myslot]) if not counterkeys: continue counterkeys.sort() diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 71c496b29..fe1acf30d 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1894,7 +1894,7 @@ class config(object): else: self.make_defaults_use.append("") self.mygcfg = stack_dicts(mygcfg_dlists, - incrementals=portage.const.INCREMENTALS, ignore_none=1) + incrementals=portage.const.INCREMENTALS) if self.mygcfg is None: self.mygcfg = {} self.configlist.append(self.mygcfg) @@ -2635,7 +2635,7 @@ class config(object): for i, pkgprofileuse_dict in enumerate(self.pkgprofileuse): cpdict = pkgprofileuse_dict.get(cp) if cpdict: - keys = list(cpdict.keys()) + keys = list(cpdict) while keys: bestmatch = best_match_to_list(cpv_slot, keys) if bestmatch: @@ -2665,7 +2665,7 @@ class config(object): self.puse = "" cpdict = self.pusedict.get(cp) if cpdict: - keys = list(cpdict.keys()) + keys = list(cpdict) while keys: self.pusekey = best_match_to_list(cpv_slot, keys) if self.pusekey: @@ -2818,7 +2818,7 @@ class config(object): for i, pusemask_dict in enumerate(self.pusemask_list): cpdict = pusemask_dict.get(cp) if cpdict: - keys = list(cpdict.keys()) + keys = list(cpdict) while keys: best_match = best_match_to_list(pkg, keys) if best_match: @@ -2841,7 +2841,7 @@ class config(object): for i, puseforce_dict in enumerate(self.puseforce_list): cpdict = puseforce_dict.get(cp) if cpdict: - keys = list(cpdict.keys()) + keys = list(cpdict) while keys: best_match = best_match_to_list(pkg, keys) if best_match: @@ -3026,7 +3026,7 @@ class config(object): if cpdict: accept_license = list(self._accept_license) cpv_slot = "%s:%s" % (cpv, metadata["SLOT"]) - for atom in match_to_list(cpv_slot, list(cpdict.keys())): + for atom in match_to_list(cpv_slot, list(cpdict)): accept_license.extend(cpdict[atom]) licenses = set(flatten(dep.use_reduce(dep.paren_reduce( @@ -3107,7 +3107,7 @@ class config(object): if cpdict: accept_properties = list(self._accept_properties) cpv_slot = "%s:%s" % (cpv, metadata["SLOT"]) - for atom in match_to_list(cpv_slot, list(cpdict.keys())): + for atom in match_to_list(cpv_slot, list(cpdict)): accept_properties.extend(cpdict[atom]) properties = set(flatten(dep.use_reduce(dep.paren_reduce( @@ -4729,7 +4729,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", mysettings.get("PORTAGE_QUIET", None) == "1" digests = mydigests.get(myfile) if digests: - digests = list(digests.keys()) + digests = list(digests) digests.sort() eout.ebegin( "%s %s ;-)" % (myfile, " ".join(digests))) @@ -5236,7 +5236,7 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=-1) return 0 if "assume-digests" not in mysettings.features: - distlist = list(mf.fhashdict.get("DIST", {}).keys()) + distlist = list(mf.fhashdict.get("DIST", {})) distlist.sort() auto_assumed = [] for filename in distlist: @@ -8455,9 +8455,9 @@ class FetchlistDict(portage.cache.mappings.Mapping): self.portdb = mydbapi def __getitem__(self, pkg_key): """Returns the complete fetch list for a given package.""" - return list(self.portdb.getFetchMap(pkg_key, mytree=self.mytree).keys()) + return list(self.portdb.getFetchMap(pkg_key, mytree=self.mytree)) def __contains__(self, cpv): - return cpv in list(self.keys()) + return cpv in self.__iter__() def has_key(self, pkg_key): """Returns true if the given package exists within pkgdir.""" return pkg_key in self @@ -8864,7 +8864,7 @@ class MtimeDB(dict): mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup", "starttime", "updates", "version")) - for k in list(d.keys()): + for k in list(d): if k not in mtimedbkeys: writemsg(_("Deleting invalid mtimedb key: %s\n") % str(k)) del d[k] diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py index 143c321e1..6add2da60 100644 --- a/pym/portage/cache/anydbm.py +++ b/pym/portage/cache/anydbm.py @@ -3,7 +3,11 @@ # License: GPL2 # $Id$ -anydbm_module = __import__("anydbm") +try: + anydbm_module = __import__("anydbm") +except ImportError: + # python 3.x + import dbm as anydbm_module try: import cPickle as pickle except ImportError: @@ -31,8 +35,10 @@ class database(fs_template.FsBased): self._db_path = os.path.join(self.location, fs_template.gen_label(self.location, self.label)+default_db) self.__db = None try: - self.__db = anydbm_module.open( - _unicode_encode(self._db_path), 'w', self._perms) + # dbm.open() will not work with bytes in python-3.1: + # TypeError: can't concat bytes to str + self.__db = anydbm_module.open(self._db_path, + 'w', self._perms) except anydbm_module.error: # XXX handle this at some point try: @@ -44,8 +50,10 @@ class database(fs_template.FsBased): # try again if failed try: if self.__db == None: - self.__db = anydbm_module.open( - _unicode_encode(self._db_path), 'c', self._perms) + # dbm.open() will not work with bytes in python-3.1: + # TypeError: can't concat bytes to str + self.__db = anydbm_module.open(self._db_path, + 'c', self._perms) except anydbm_module.error as e: raise cache_errors.InitializationError(self.__class__, e) self._ensure_access(self._db_path) diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index b777ed1d0..a6c111897 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -226,9 +226,9 @@ class ProtectedDict(MutableMapping): def __iter__(self): - for k in self.new.keys(): + for k in self.new: yield k - for k in self.orig.keys(): + for k in self.orig: if k not in self.blacklist and k not in self.new: yield k diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index 9e779520b..3b003b1f6 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -68,8 +68,8 @@ class database(object): raise cache_errors.ReadOnlyRestriction() if self.cleanse_keys: d=ProtectedDict(values) - for k in list(d.keys()): - if d[k] == '': + for k, v in list(d.items()): + if not v: del d[k] if self.serialize_eclasses and "_eclasses_" in values: d["_eclasses_"] = serialize_eclasses(d["_eclasses_"]) @@ -110,13 +110,13 @@ class database(object): return cpv in self def keys(self): - return tuple(self.keys()) + return list(self) def iterkeys(self): return iter(self) def iteritems(self): - for x in self.keys(): + for x in self: yield (x, self[x]) def items(self): @@ -182,7 +182,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: cont = True vals = self[cpv] for key, match in restricts.items(): diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 9cc2d82e7..6b849d5d7 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -134,7 +134,7 @@ def perform_all(x, calc_prelink=0): return mydict def get_valid_checksum_keys(): - return list(hashfunc_map.keys()) + return list(hashfunc_map) def get_hash_origin(hashtype): if hashtype not in hashfunc_map: diff --git a/pym/portage/cvstree.py b/pym/portage/cvstree.py index 87724adf1..da8b40e15 100644 --- a/pym/portage/cvstree.py +++ b/pym/portage/cvstree.py @@ -235,9 +235,6 @@ def getentries(mydir,recursive=0): entries["dirs"][mysplit[1]]["flags"]=mysplit[2:] if recursive: rentries=getentries(mydir+"/"+mysplit[1],recursive) - #print rentries.keys() - #print entries["files"].keys() - #print entries["files"][mysplit[1]] entries["dirs"][mysplit[1]]["dirs"]=rentries["dirs"] entries["dirs"][mysplit[1]]["files"]=rentries["files"] else: @@ -315,18 +312,3 @@ def getentries(mydir,recursive=0): print("File of unknown type:",mydir+"/"+file) print() return entries - -#class cvstree: -# def __init__(self,basedir): -# self.refdir=os.cwd() -# self.basedir=basedir -# self.entries={} -# self.entries["dirs"]={} -# self.entries["files"]={} -# self.entries["dirs"][self.basedir]=getentries(self.basedir) -# self.getrealdirs(self.dirs, self.files) -# def getrealdirs(self,dirs,files): -# for mydir in dirs.keys(): -# list = os.listdir( - - diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index cd3f3470e..0f1de429a 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -786,7 +786,7 @@ class binarytree(object): self.settings["PORTAGE_BINHOST"], chunk_size=chunk_size) #writemsg(green(" -- DONE!\n\n")) - for mypkg in self.remotepkgs.keys(): + for mypkg in list(self.remotepkgs): if "CATEGORY" not in self.remotepkgs[mypkg]: #old-style or corrupt package writemsg(_("!!! Invalid remote binary package: %s\n") % mypkg, diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 7f20e66fd..b073e4268 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -876,7 +876,7 @@ class portdbapi(dbapi): y == "CVS": continue d[x+"/"+y] = None - l = list(d.keys()) + l = list(d) l.sort() return l @@ -933,7 +933,7 @@ class portdbapi(dbapi): (mycp, self.mysettings["PORTAGE_CONFIGROOT"]), noiselevel=-1) mylist = [] else: - mylist = list(d.keys()) + mylist = list(d) # Always sort in ascending order here since it's handy # and the result can be easily cached and reused. self._cpv_sort_ascending(mylist) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 5d88f5b99..24e93dc20 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -154,7 +154,7 @@ class PreservedLibsRegistry(object): os = _os_merge - for cps in self._data.keys(): + for cps in list(self._data): cpv, counter, paths = self._data[cps] paths = [f for f in paths \ if os.path.exists(os.path.join(self._root, f.lstrip(os.sep)))] @@ -1736,7 +1736,7 @@ class vardbapi(dbapi): self.invalidentry(self.getpath(y)) continue d[mysplit[0]+"/"+mysplit[1]] = None - return list(d.keys()) + return list(d) def checkblockers(self, origdep): pass @@ -1809,7 +1809,7 @@ class vardbapi(dbapi): secpass >= 2: self._owners.populate() # index any unindexed contents valid_nodes = set(self.cpv_all()) - for cpv in self._aux_cache["packages"].keys(): + for cpv in list(self._aux_cache["packages"]): if cpv not in valid_nodes: del self._aux_cache["packages"][cpv] del self._aux_cache["modified"] @@ -3076,7 +3076,7 @@ class dblink(object): if pkgfiles: self.updateprotect() - mykeys = list(pkgfiles.keys()) + mykeys = list(pkgfiles) mykeys.sort() mykeys.reverse() @@ -5160,7 +5160,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): curval = 0 if onProgress: onProgress(maxval, 0) - paths = list(contents.keys()) + paths = list(contents) paths.sort() for path in paths: curval += 1 diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py index 5d1e933a1..6c567a072 100644 --- a/pym/portage/dbapi/virtual.py +++ b/pym/portage/dbapi/virtual.py @@ -59,7 +59,7 @@ class fakedbapi(dbapi): return list(self.cpdict) def cpv_all(self): - return list(self.cpvdict.keys()) + return list(self.cpvdict) def cpv_inject(self, mycpv, metadata=None): """Adds a cpv to the list of available packages. See the diff --git a/pym/portage/elog/__init__.py b/pym/portage/elog/__init__.py index 53c0a85f7..15e8c9bce 100644 --- a/pym/portage/elog/__init__.py +++ b/pym/portage/elog/__init__.py @@ -100,7 +100,7 @@ def elog_process(cpv, mysettings, phasefilter=None): else: all_logentries[cpv] = ebuild_logentries - for key in list(_preserve_logentries.keys()): + for key in list(_preserve_logentries): if key in all_logentries: all_logentries[key] = _merge_logentries(_preserve_logentries[key], all_logentries[key]) else: diff --git a/pym/portage/elog/mod_mail.py b/pym/portage/elog/mod_mail.py index ac96f3b20..96e45ba21 100644 --- a/pym/portage/elog/mod_mail.py +++ b/pym/portage/elog/mod_mail.py @@ -22,14 +22,14 @@ def process(mysettings, key, logentries, fulltext): # look at the phases listed in our logentries to figure out what action was performed action = _("merged") - for phase in logentries.keys(): + for phase in logentries: # if we found a *rm phase assume that the package was unmerged if phase in ["postrm", "prerm"]: action = _("unmerged") # if we think that the package was unmerged, make sure there was no unexpected # phase recorded to avoid misinformation if action == _("unmerged"): - for phase in logentries.keys(): + for phase in logentries: if phase not in ["postrm", "prerm", "other"]: action = _("unknown") diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 62e76b4f3..47095afff 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -818,7 +818,7 @@ class PackageIndex(object): if self.modified: self.header["TIMESTAMP"] = str(long(time.time())) self.header["PACKAGES"] = str(len(self.packages)) - keys = list(self.header.keys()) + keys = list(self.header) keys.sort() self._writepkgindex(pkgfile, [(k, self.header[k]) \ for k in keys if self.header[k]]) @@ -835,7 +835,7 @@ class PackageIndex(object): for k, v in self._default_pkg_data.items(): if metadata.get(k) == v: metadata.pop(k, None) - keys = list(metadata.keys()) + keys = list(metadata) keys.sort() self._writepkgindex(pkgfile, [(k, metadata[k]) for k in keys if metadata[k]]) diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 1f061b231..4049efc2d 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -581,7 +581,7 @@ class Glsa: outstream.write(_("Announced on: %s\n") % self.announced) outstream.write(_("Last revised on: %s : %02d\n\n") % (self.revised, self.count)) if self.glsatype == "ebuild": - for k in self.packages.keys(): + for k in self.packages: pkg = self.packages[k] for path in pkg: vul_vers = "".join(path["vul_vers"]) @@ -626,7 +626,7 @@ class Glsa: @returns: True if the system is affected, False if not """ rValue = False - for k in self.packages.keys(): + for k in self.packages: pkg = self.packages[k] for path in pkg: if path["arch"] == "*" or self.config["ARCH"] in path["arch"].split(): @@ -679,7 +679,7 @@ class Glsa: @return: list of package-versions that have to be merged """ rValue = [] - for pkg in self.packages.keys(): + for pkg in self.packages: for path in self.packages[pkg]: update = getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], \ self.portdbapi, self.vardbapi, minimize=least_change) diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 7b20a3c2d..cb81b8933 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -74,7 +74,7 @@ class ManifestEntry(object): class Manifest2Entry(ManifestEntry): def __str__(self): myline = " ".join([self.type, self.name, str(self.hashes["size"])]) - myhashkeys = list(self.hashes.keys()) + myhashkeys = list(self.hashes) myhashkeys.remove("size") myhashkeys.sort() for h in myhashkeys: @@ -202,15 +202,15 @@ class Manifest(object): return myhashdict def _createManifestEntries(self): - mytypes = list(self.fhashdict.keys()) + mytypes = list(self.fhashdict) mytypes.sort() for t in mytypes: - myfiles = list(self.fhashdict[t].keys()) + myfiles = list(self.fhashdict[t]) myfiles.sort() for f in myfiles: myentry = Manifest2Entry( type=t, name=f, hashes=self.fhashdict[t][f].copy()) - myhashkeys = list(myentry.hashes.keys()) + myhashkeys = list(myentry.hashes) myhashkeys.sort() for h in myhashkeys: if h not in ["size"] + portage.const.MANIFEST2_HASH_FUNCTIONS: diff --git a/pym/portage/sets/base.py b/pym/portage/sets/base.py index 0c08ee194..d58b5f297 100644 --- a/pym/portage/sets/base.py +++ b/pym/portage/sets/base.py @@ -126,7 +126,7 @@ class PackageSet(object): rev_transform[atom] = atom else: rev_transform[Atom(atom.replace(atom.cp, pkg.cp, 1))] = atom - best_match = best_match_to_list(pkg, iter(rev_transform.keys())) + best_match = best_match_to_list(pkg, iter(rev_transform)) if best_match: return rev_transform[best_match] return None diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 06ebcadfd..f2e7dd110 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -132,7 +132,7 @@ class VariableSet(EverythingSet): raise SetConfigError(_("no includes or excludes given")) metadatadb = options.get("metadata-source", "vartree") - if not metadatadb in trees.keys(): + if not metadatadb in trees: raise SetConfigError(_("invalid value '%s' for option metadata-source") % metadatadb) return cls(trees["vartree"].dbapi, diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index b0d13fbd5..ba56e7b0f 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -83,7 +83,7 @@ class StaticFileSet(EditablePackageSet): data = {} if self.greedy: atoms = [] - for a in data.keys(): + for a in data: matches = self.dbapi.match(a) for cpv in matches: atoms.append("%s:%s" % (cpv_getkey(cpv), @@ -92,7 +92,7 @@ class StaticFileSet(EditablePackageSet): # in the latest new slot that may be available. atoms.append(a) else: - atoms = list(data.keys()) + atoms = iter(data) self._setAtoms(atoms) self._mtime = mtime @@ -182,7 +182,7 @@ class ConfigFileSet(PackageSet): def load(self): data, errors = self.loader.load() - self._setAtoms(list(data.keys())) + self._setAtoms(iter(data)) def singleBuilder(self, options, settings, trees): if not "filename" in options: @@ -253,7 +253,7 @@ class WorldSet(EditablePackageSet): raise del e data = {} - atoms = list(data.keys()) + atoms = list(data) self._mtime = mtime atoms_changed = True else: @@ -273,7 +273,7 @@ class WorldSet(EditablePackageSet): raise del e data = {} - nonatoms = list(data.keys()) + nonatoms = list(data) self._mtime2 = mtime atoms_changed = True else: diff --git a/pym/portage/util.py b/pym/portage/util.py index 57a14c25f..bae33a05f 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -219,20 +219,15 @@ def stack_dicts(dicts, incremental=0, incrementals=[], ignore_none=0): Returns a single dict.""" final_dict = None for mydict in dicts: - if mydict is None: - if ignore_none: - continue - else: - return None + if not mydict: + continue if final_dict is None: final_dict = {} - for y in list(mydict.keys()): - if True: - if y in final_dict and (incremental or (y in incrementals)): - final_dict[y] += " "+mydict[y][:] - else: - final_dict[y] = mydict[y][:] - mydict[y] = " ".join(mydict[y].split()) # Remove extra spaces. + for k, v in mydict.items(): + if k in final_dict and (incremental or (k in incrementals)): + final_dict[k] += " " + v + else: + final_dict[k] = v return final_dict def stack_lists(lists, incremental=1): @@ -253,7 +248,7 @@ def stack_lists(lists, incremental=1): new_list[y] = True else: new_list[y] = True - return list(new_list.keys()) + return list(new_list) def grabdict(myfilename, juststrings=0, empty=0, recursive=0, incremental=1): """ -- 2.26.2