From 7cb8fb941f09d1ac646be334745f90e16ebd46eb Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sun, 20 Sep 2009 10:57:44 +0000 Subject: [PATCH] Update syntax of 'except' statements for compatibility with Python 3. (2to3-3.1 -f except -nw ${FILES}) svn path=/main/trunk/; revision=14289 --- bin/archive-conf | 2 +- bin/clean_locks | 2 +- bin/dispatch-conf | 4 +- bin/ebuild | 6 +- bin/egencache | 14 +-- bin/emaint | 2 +- bin/emerge | 4 +- bin/env-update | 2 +- bin/fixpackages | 2 +- bin/glsa-check | 10 +- bin/portageq | 6 +- bin/quickpkg | 6 +- bin/regenworld | 2 +- bin/repoman | 30 ++--- pym/_emerge/BinpkgVerifier.py | 2 +- pym/_emerge/BlockerCache.py | 4 +- pym/_emerge/EbuildBuildDir.py | 2 +- pym/_emerge/EbuildFetchonly.py | 2 +- pym/_emerge/MetadataRegen.py | 4 +- pym/_emerge/Package.py | 2 +- pym/_emerge/PackageUninstall.py | 2 +- pym/_emerge/PollScheduler.py | 2 +- pym/_emerge/Scheduler.py | 2 +- pym/_emerge/SpawnProcess.py | 2 +- pym/_emerge/SubProcess.py | 6 +- pym/_emerge/actions.py | 52 ++++---- pym/_emerge/changelog.py | 2 +- pym/_emerge/depgraph.py | 38 +++--- pym/_emerge/emergelog.py | 2 +- pym/_emerge/main.py | 16 +-- pym/_emerge/search.py | 4 +- pym/_emerge/unmerge.py | 2 +- pym/portage/__init__.py | 166 ++++++++++++------------- pym/portage/cache/anydbm.py | 4 +- pym/portage/cache/ebuild_xattr.py | 10 +- pym/portage/cache/flat_hash.py | 14 +-- pym/portage/cache/flat_list.py | 12 +- pym/portage/cache/metadata.py | 8 +- pym/portage/cache/sql_template.py | 24 ++-- pym/portage/cache/sqlite.py | 4 +- pym/portage/cache/template.py | 2 +- pym/portage/cache/util.py | 10 +- pym/portage/checksum.py | 10 +- pym/portage/cvstree.py | 6 +- pym/portage/dbapi/bintree.py | 20 +-- pym/portage/dbapi/porttree.py | 12 +- pym/portage/dbapi/vartree.py | 68 +++++----- pym/portage/dispatch_conf.py | 8 +- pym/portage/eclass_cache.py | 2 +- pym/portage/elog/__init__.py | 4 +- pym/portage/elog/mod_mail.py | 2 +- pym/portage/elog/mod_mail_summary.py | 2 +- pym/portage/env/loaders.py | 2 +- pym/portage/getbinpkg.py | 32 ++--- pym/portage/locks.py | 12 +- pym/portage/mail.py | 4 +- pym/portage/manifest.py | 8 +- pym/portage/output.py | 6 +- pym/portage/process.py | 2 +- pym/portage/sets/__init__.py | 4 +- pym/portage/sets/dbapi.py | 2 +- pym/portage/sets/files.py | 6 +- pym/portage/tests/ebuild/test_spawn.py | 2 +- pym/portage/update.py | 4 +- pym/portage/util.py | 36 +++--- pym/portage/xpak.py | 8 +- pym/repoman/utilities.py | 4 +- 67 files changed, 379 insertions(+), 379 deletions(-) diff --git a/bin/archive-conf b/bin/archive-conf index f9a4d5724..680a99cb5 100755 --- a/bin/archive-conf +++ b/bin/archive-conf @@ -72,7 +72,7 @@ def archive_conf(): file = file.rstrip() try: contents = open(file, "r") - except IOError, e: + except IOError as e: print >> sys.stderr, 'archive-conf: Unable to open %s: %s' % (file, e) sys.exit(1) lines = contents.readlines() diff --git a/bin/clean_locks b/bin/clean_locks index 9799ad999..ec593a311 100755 --- a/bin/clean_locks +++ b/bin/clean_locks @@ -38,7 +38,7 @@ for x in sys.argv[1:]: print y print - except OSError, e: + except OSError as e: if e.errno in (errno.ENOENT, errno.ENOTDIR): print "!!! %s is not a directory or does not exist" % x else: diff --git a/bin/dispatch-conf b/bin/dispatch-conf index 68fd3e899..d0309701e 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -51,7 +51,7 @@ while SCRATCH_DIR is None: continue os.mkdir(mydir) SCRATCH_DIR = mydir - except OSError, e: + except OSError as e: if e.errno != 17: raise os.umask(oldmask) @@ -305,7 +305,7 @@ class dispatch: os.system((DIFF_CONTENTS % (curconf, newconf)) + '>>' + self.options["log-file"]) try: os.rename(newconf, curconf) - except (IOError, os.error), why: + except (IOError, os.error) as why: print >> sys.stderr, 'dispatch-conf: Error renaming %s to %s: %s; fatal' % \ (newconf, curconf, str(why)) diff --git a/bin/ebuild b/bin/ebuild index 18abb00e8..e41764b8e 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -255,17 +255,17 @@ for arg in pargs: except KeyError: # aux_get error a = 1 - except UnsupportedAPIException, e: + except UnsupportedAPIException as e: from textwrap import wrap msg = wrap(str(e), 70) del e for x in msg: portage.writemsg("!!! %s\n" % x, noiselevel=-1) a = 1 - except PortagePackageException, e: + except PortagePackageException as e: portage.writemsg("!!! %s\n" % (e,), noiselevel=-1) a = 1 - except PermissionDenied, e: + except PermissionDenied as e: portage.writemsg("!!! Permission Denied: %s\n" % (e,), noiselevel=-1) a = 1 if a == None: diff --git a/bin/egencache b/bin/egencache index 2b3af4e50..6c46896c0 100755 --- a/bin/egencache +++ b/bin/egencache @@ -157,7 +157,7 @@ class GenCache(object): try: try: self._trg_cache[cpv] = metadata - except StatCollision, sc: + except StatCollision as sc: # If the content of a cache entry changes and neither the # file mtime nor size changes, it will prevent rsync from # detecting changes. Cache backends may raise this @@ -174,7 +174,7 @@ class GenCache(object): max_mtime = long(max_mtime) try: os.utime(ebuild_path, (max_mtime, max_mtime)) - except OSError, e: + except OSError as e: self.returncode |= 1 writemsg_level( "%s writing target: %s\n" % (cpv, e), @@ -184,7 +184,7 @@ class GenCache(object): self._trg_cache[cpv] = metadata self._portdb.auxdb[repo_path][cpv] = metadata - except CacheError, ce: + except CacheError as ce: self.returncode |= 1 writemsg_level( "%s writing target: %s\n" % (cpv, ce), @@ -208,7 +208,7 @@ class GenCache(object): level=logging.ERROR, noiselevel=-1) else: dead_nodes.add(cpv) - except CacheError, ce: + except CacheError as ce: self.returncode |= 1 writemsg_level( "Error listing cache entries for " + \ @@ -230,7 +230,7 @@ class GenCache(object): cp_missing.discard(cp) if cp in cp_set: dead_nodes.add(cpv) - except CacheError, ce: + except CacheError as ce: self.returncode |= 1 writemsg_level( "Error listing cache entries for " + \ @@ -252,7 +252,7 @@ class GenCache(object): del trg_cache[k] except KeyError: pass - except CacheError, ce: + except CacheError as ce: self.returncode |= 1 writemsg_level( "%s deleting stale cache: %s\n" % (k, ce), @@ -261,7 +261,7 @@ class GenCache(object): if not trg_cache.autocommits: try: trg_cache.commit() - except CacheError, ce: + except CacheError as ce: self.returncode |= 1 writemsg_level( "committing target: %s\n" % (ce,), diff --git a/bin/emaint b/bin/emaint index 6652b6ed5..ac791c14c 100755 --- a/bin/emaint +++ b/bin/emaint @@ -383,7 +383,7 @@ class VdbKeyHandler(object): keyfile = open(mydir+os.sep+k, "w") keyfile.write(s+"\n") keyfile.close() - except (IOError, OSError), e: + except (IOError, OSError) as e: errors.append("Could not write %s, reason was: %s" % (mydir+k, e)) return errors diff --git a/bin/emerge b/bin/emerge index 03cf171cd..fca852d02 100755 --- a/bin/emerge +++ b/bin/emerge @@ -38,10 +38,10 @@ if __name__ == "__main__": from portage.exception import ParseError, PermissionDenied try: retval = emerge_main() - except PermissionDenied, e: + except PermissionDenied as e: sys.stderr.write("Permission denied: '%s'\n" % str(e)) sys.exit(e.errno) - except ParseError, e: + except ParseError as e: sys.stderr.write("%s\n" % str(e)) sys.exit(1) except SystemExit: diff --git a/bin/env-update b/bin/env-update index 30e25d0b2..3fa21c7fa 100755 --- a/bin/env-update +++ b/bin/env-update @@ -31,7 +31,7 @@ except ImportError: import portage try: portage.env_update(makelinks) -except IOError, e: +except IOError as e: if e.errno == errno.EACCES: print "env-update: Need superuser access" sys.exit(1) diff --git a/bin/fixpackages b/bin/fixpackages index a5f24a7e5..dc7a5d24f 100755 --- a/bin/fixpackages +++ b/bin/fixpackages @@ -19,7 +19,7 @@ mtimedb = portage.mtimedb try: os.nice(int(mysettings.get("PORTAGE_NICENESS", "0"))) -except (OSError, ValueError), e: +except (OSError, ValueError) as e: portage.writemsg("!!! Failed to change nice value to '%s'\n" % \ mysettings["PORTAGE_NICENESS"]) portage.writemsg("!!! %s\n" % str(e)) diff --git a/bin/glsa-check b/bin/glsa-check index ad06136e2..d1fdb2070 100755 --- a/bin/glsa-check +++ b/bin/glsa-check @@ -124,7 +124,7 @@ if "affected" in params: for x in todolist: try: myglsa = Glsa(x, portage.settings, vardb, portdb) - except (GlsaTypeException, GlsaFormatException), e: + except (GlsaTypeException, GlsaFormatException) as e: if verbose: sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (x, e))) continue @@ -149,7 +149,7 @@ def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr): for myid in myglsalist: try: myglsa = Glsa(myid, portage.settings, vardb, portdb) - except (GlsaTypeException, GlsaFormatException), e: + except (GlsaTypeException, GlsaFormatException) as e: if verbose: fd2.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e))) continue @@ -195,7 +195,7 @@ if mode in ["dump", "fix", "inject", "pretend"]: for myid in glsalist: try: myglsa = Glsa(myid, portage.settings, vardb, portdb) - except (GlsaTypeException, GlsaFormatException), e: + except (GlsaTypeException, GlsaFormatException) as e: if verbose: sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e))) continue @@ -247,7 +247,7 @@ if mode == "test": for myid in glsalist: try: myglsa = Glsa(myid, portage.settings, vardb, portdb) - except (GlsaTypeException, GlsaFormatException), e: + except (GlsaTypeException, GlsaFormatException) as e: if verbose: sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e))) continue @@ -296,7 +296,7 @@ if mode == "mail": for myid in glsalist: try: myglsa = Glsa(myid, portage.settings, vardb, portdb) - except (GlsaTypeException, GlsaFormatException), e: + except (GlsaTypeException, GlsaFormatException) as e: if verbose: sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e))) continue diff --git a/bin/portageq b/bin/portageq index 8cb7a2b13..04c0ca034 100755 --- a/bin/portageq +++ b/bin/portageq @@ -618,13 +618,13 @@ def main(): retval = function(args) if retval: sys.exit(retval) - except portage.exception.PermissionDenied, e: + except portage.exception.PermissionDenied as e: sys.stderr.write("Permission denied: '%s'\n" % str(e)) sys.exit(e.errno) - except portage.exception.ParseError, e: + except portage.exception.ParseError as e: sys.stderr.write("%s\n" % str(e)) sys.exit(1) - except ValueError, e: + except ValueError as e: if not e.args or \ not hasattr(e.args[0], "__len__") or \ len(e.args[0]) < 2: diff --git a/bin/quickpkg b/bin/quickpkg index 53f7e9b27..e0aaf63bd 100755 --- a/bin/quickpkg +++ b/bin/quickpkg @@ -45,7 +45,7 @@ def quickpkg_main(options, args, eout): for arg in args: try: atom = dep_expand(arg, mydb=vardb, settings=vartree.settings) - except ValueError, e: + except ValueError as e: # Multiple matches thrown from cpv_expand eout.eerror("Please use a more specific atom: %s" % \ " ".join(e.args[0])) @@ -83,7 +83,7 @@ def quickpkg_main(options, args, eout): try: restrict = flatten(use_reduce( paren_reduce(restrict), uselist=use)) - except InvalidDependString, e: + except InvalidDependString as e: eout.eerror("Invalid RESTRICT metadata " + \ "for '%s': %s; skipping" % (cpv, str(e))) del e @@ -140,7 +140,7 @@ def quickpkg_main(options, args, eout): binpkg_path = bintree.getname(cpv) try: s = os.stat(binpkg_path) - except OSError, e: + except OSError as e: # Sanity check, shouldn't happen normally. eout.eend(1) eout.eerror(str(e)) diff --git a/bin/regenworld b/bin/regenworld index e8eb1253d..932995d5a 100755 --- a/bin/regenworld +++ b/bin/regenworld @@ -89,7 +89,7 @@ for mykey in biglist: except (portage.exception.InvalidAtom, KeyError): if "--debug" in sys.argv: print "* ignoring broken log entry for %s (likely injected)" % mykey - except ValueError, e: + except ValueError as e: print "* %s is an ambigous package name, candidates are:\n%s" % (mykey, e) continue if mylist: diff --git a/bin/repoman b/bin/repoman index 0537c3172..570c0b936 100755 --- a/bin/repoman +++ b/bin/repoman @@ -778,7 +778,7 @@ else: else: must_fetch=0 - except (OSError,IOError), e: + except (OSError,IOError) as e: if e.errno != 2: print red("!!!")+" caught exception '%s' for %s/metadata.dtd, bailing" % (str(e), portage.CACHE_PATH) sys.exit(1) @@ -791,16 +791,16 @@ else: try: try: os.unlink(metadata_dtd) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e val=portage.fetch(['http://www.gentoo.org/dtd/metadata.dtd'],repoman_settings,fetchonly=0, \ try_mirrors=0) - except SystemExit, e: + except SystemExit as e: raise # Need to propogate this - except Exception,e: + except Exception as e: print print red("!!!")+" attempting to fetch 'http://www.gentoo.org/dtd/metadata.dtd', caught" print red("!!!")+" exception '%s' though." % str(e) @@ -999,7 +999,7 @@ for x in scanlist: encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content']): line +=1 - except UnicodeDecodeError, ue: + except UnicodeDecodeError as ue: stats["file.UTF8"] += 1 s = ue.object[:ue.start] l2 = s.count("\n") @@ -1071,7 +1071,7 @@ for x in scanlist: for mykey in fetchlist_dict: try: myfiles_all.extend(fetchlist_dict[mykey]) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: src_uri_error = True try: portdb.aux_get(mykey, ["SRC_URI"]) @@ -1107,7 +1107,7 @@ for x in scanlist: full_path = os.path.join(repodir, relative_path) try: mystat = os.stat(full_path) - except OSError, oe: + except OSError as oe: if oe.errno == 2: # don't worry about it. it likely was removed via fix above. continue @@ -1174,7 +1174,7 @@ for x in scanlist: f = open(os.path.join(checkdir, "metadata.xml")) utilities.parse_metadata_use(f, muselist) f.close() - except (EnvironmentError, ParseError), e: + except (EnvironmentError, ParseError) as e: metadata_bad = True stats["metadata.bad"] += 1 fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e)) @@ -1416,14 +1416,14 @@ for x in scanlist: except ValueError: badsyntax.append("parenthesis mismatch") mydeplist = [] - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: badsyntax.append(str(e)) del e mydeplist = [] try: portage.dep.use_reduce(mydeplist, matchall=1) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: badsyntax.append(str(e)) for token in operator_tokens: @@ -1565,7 +1565,7 @@ for x in scanlist: try: myrestrict = portage.dep.use_reduce( portage.dep.paren_reduce(myaux["RESTRICT"]), matchall=1) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: stats["RESTRICT.syntax"] = stats["RESTRICT.syntax"] + 1 fails["RESTRICT.syntax"].append( "%s: RESTRICT: %s" % (relative_path, e)) @@ -1833,7 +1833,7 @@ else: try: myvcstree=portage.cvstree.getentries("./",recursive=1) myunadded=portage.cvstree.findunadded(myvcstree,recursive=1,basedir="./") - except SystemExit, e: + except SystemExit as e: raise # TODO propogate this except: err("Error retrieving CVS tree; exiting.") @@ -1841,7 +1841,7 @@ else: try: svnstatus=os.popen("svn status --no-ignore").readlines() myunadded = [ "./"+elem.rstrip().split()[1] for elem in svnstatus if elem.startswith("?") or elem.startswith("I") ] - except SystemExit, e: + except SystemExit as e: raise # TODO propogate this except: err("Error retrieving SVN info; exiting.") @@ -2005,7 +2005,7 @@ else: commitmessage = f.read() f.close() del f - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno == errno.ENOENT: portage.writemsg("!!! File Not Found: --commitmsgfile='%s'\n" % options.commitmsgfile) else: @@ -2252,7 +2252,7 @@ else: if not os.path.isdir(repoman_settings["O"]): continue gpgsign(os.path.join(repoman_settings["O"], "Manifest")) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: portage.writemsg("!!! %s\n" % str(e)) portage.writemsg("!!! Disabled FEATURES='sign'\n") signed = False diff --git a/pym/_emerge/BinpkgVerifier.py b/pym/_emerge/BinpkgVerifier.py index 36e1bb8b6..404becf09 100644 --- a/pym/_emerge/BinpkgVerifier.py +++ b/pym/_emerge/BinpkgVerifier.py @@ -42,7 +42,7 @@ class BinpkgVerifier(AsynchronousTask): writemsg("!!! Fetching Binary failed " + \ "for '%s'\n" % pkg.cpv, noiselevel=-1) rval = 1 - except portage.exception.DigestException, e: + except portage.exception.DigestException as e: writemsg("\n!!! Digest verification failed:\n", noiselevel=-1) writemsg("!!! %s\n" % e.value[0], diff --git a/pym/_emerge/BlockerCache.py b/pym/_emerge/BlockerCache.py index 2af47ca85..db16fa83a 100644 --- a/pym/_emerge/BlockerCache.py +++ b/pym/_emerge/BlockerCache.py @@ -55,7 +55,7 @@ class BlockerCache(portage.cache.mappings.MutableMapping): self._cache_data = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError), e: + except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e: if isinstance(e, pickle.UnpicklingError): writemsg("!!! Error loading '%s': %s\n" % \ (self._cache_filename, str(e)), noiselevel=-1) @@ -140,7 +140,7 @@ class BlockerCache(portage.cache.mappings.MutableMapping): f.close() portage.util.apply_secpass_permissions( self._cache_filename, gid=portage.portage_gid, mode=0644) - except (IOError, OSError), e: + except (IOError, OSError) as e: pass self._modified.clear() diff --git a/pym/_emerge/EbuildBuildDir.py b/pym/_emerge/EbuildBuildDir.py index d9f819966..d856d1912 100644 --- a/pym/_emerge/EbuildBuildDir.py +++ b/pym/_emerge/EbuildBuildDir.py @@ -83,7 +83,7 @@ class EbuildBuildDir(SlotObject): if catdir_lock: try: os.rmdir(catdir) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST): raise diff --git a/pym/_emerge/EbuildFetchonly.py b/pym/_emerge/EbuildFetchonly.py index d65e2b2b1..256a06c69 100644 --- a/pym/_emerge/EbuildFetchonly.py +++ b/pym/_emerge/EbuildFetchonly.py @@ -44,7 +44,7 @@ class EbuildFetchonly(SlotObject): from tempfile import mkdtemp try: private_tmpdir = mkdtemp("", "._portage_fetch_.", global_tmpdir) - except OSError, e: + except OSError as e: if e.errno != portage.exception.PermissionDenied.errno: raise raise portage.exception.PermissionDenied(global_tmpdir) diff --git a/pym/_emerge/MetadataRegen.py b/pym/_emerge/MetadataRegen.py index ee6eb997a..4c237d34c 100644 --- a/pym/_emerge/MetadataRegen.py +++ b/pym/_emerge/MetadataRegen.py @@ -90,7 +90,7 @@ class MetadataRegen(PollScheduler): for mytree in portdb.porttrees: try: dead_nodes[mytree] = set(portdb.auxdb[mytree].iterkeys()) - except CacheError, e: + except CacheError as e: portage.writemsg("Error listing cache entries for " + \ "'%s': %s, continuing...\n" % (mytree, e), noiselevel=-1) @@ -105,7 +105,7 @@ class MetadataRegen(PollScheduler): dead_nodes[mytree] = set(cpv for cpv in \ portdb.auxdb[mytree].iterkeys() \ if cpv_getkey(cpv) in cp_set) - except CacheError, e: + except CacheError as e: portage.writemsg("Error listing cache entries for " + \ "'%s': %s, continuing...\n" % (mytree, e), noiselevel=-1) diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index b1d4a11b3..a38edbd0d 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -195,7 +195,7 @@ class _PackageMetadataWrapper(dict): elif k in self._use_conditional_keys: try: use_reduce(paren_reduce(v), matchall=1) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: self._pkg._invalid_metadata(k + ".syntax", "%s: %s" % (k, e)) def __getitem__(self, k): diff --git a/pym/_emerge/PackageUninstall.py b/pym/_emerge/PackageUninstall.py index fdd59e149..59bb50e56 100644 --- a/pym/_emerge/PackageUninstall.py +++ b/pym/_emerge/PackageUninstall.py @@ -23,7 +23,7 @@ class PackageUninstall(AsynchronousTask): [self.pkg.cpv], self.ldpath_mtimes, clean_world=0, clean_delay=0, raise_on_error=1, scheduler=self.scheduler, writemsg_level=self._writemsg_level) - except UninstallFailure, e: + except UninstallFailure as e: self.returncode = e.status else: self.returncode = os.EX_OK diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 8250cb00a..e04b58ae7 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -95,7 +95,7 @@ class PollScheduler(object): try: self._poll_event_queue.extend(self._poll_obj.poll(timeout)) break - except select.error, e: + except select.error as e: writemsg_level("\n!!! select error: %s\n" % (e,), level=logging.ERROR, noiselevel=-1) del e diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index 06074c932..d532335e6 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1498,7 +1498,7 @@ class Scheduler(PollScheduler): success, mydepgraph, dropped_tasks = resume_depgraph( self.settings, self.trees, self._mtimedb, self.myopts, myparams, self._spinner) - except depgraph.UnsatisfiedResumeDep, exc: + except depgraph.UnsatisfiedResumeDep as exc: # rename variable to avoid python-3.0 error: # SyntaxError: can not delete variable 'e' referenced in nested # scope diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py index e6b3cc7a0..70d3ff11d 100644 --- a/pym/_emerge/SpawnProcess.py +++ b/pym/_emerge/SpawnProcess.py @@ -157,7 +157,7 @@ class SpawnProcess(SubProcess): write_successful = True files.stdout.flush() break - except IOError, e: + except IOError as e: if e.errno != errno.EAGAIN: raise del e diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py index 6bd4562d4..0df94b9e7 100644 --- a/pym/_emerge/SubProcess.py +++ b/pym/_emerge/SubProcess.py @@ -27,7 +27,7 @@ class SubProcess(AbstractPollTask): try: retval = os.waitpid(self.pid, os.WNOHANG) - except OSError, e: + except OSError as e: if e.errno != errno.ECHILD: raise del e @@ -42,7 +42,7 @@ class SubProcess(AbstractPollTask): if self.isAlive(): try: os.kill(self.pid, signal.SIGTERM) - except OSError, e: + except OSError as e: if e.errno != errno.ESRCH: raise del e @@ -69,7 +69,7 @@ class SubProcess(AbstractPollTask): try: wait_retval = os.waitpid(self.pid, 0) - except OSError, e: + except OSError as e: if e.errno != errno.ECHILD: raise del e diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index e1f7ffe19..9de19cfbd 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -204,7 +204,7 @@ def action_build(settings, trees, mtimedb, success, mydepgraph, dropped_tasks = resume_depgraph( settings, trees, mtimedb, myopts, myparams, spinner) except (portage.exception.PackageNotFound, - depgraph.UnsatisfiedResumeDep), e: + depgraph.UnsatisfiedResumeDep) as e: if isinstance(e, depgraph.UnsatisfiedResumeDep): mydepgraph = e.depgraph if show_spinner: @@ -298,7 +298,7 @@ def action_build(settings, trees, mtimedb, try: success, mydepgraph, favorites = backtrack_depgraph( settings, trees, myopts, myparams, myaction, myfiles, spinner) - except portage.exception.PackageSetNotFound, e: + except portage.exception.PackageSetNotFound as e: if show_spinner: print "\b\b... done!" root_config = trees[settings["ROOT"]]["root_config"] @@ -484,7 +484,7 @@ def action_config(settings, trees, myopts, myfiles): print try: pkgs = trees[settings["ROOT"]]["vartree"].dbapi.match(myfiles[0]) - except portage.exception.AmbiguousPackageName, e: + except portage.exception.AmbiguousPackageName as e: # Multiple matches thrown from cpv_expand pkgs = e.args[0] if len(pkgs) == 0: @@ -682,7 +682,7 @@ def calc_depclean(settings, trees, ldpath_mtimes, if args_set.findAtomForPackage(pkg) is None: world_temp_set.add("=" + pkg.cpv) continue - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: show_invalid_depstring_notice(pkg, pkg.metadata["PROVIDE"], str(e)) del e @@ -731,7 +731,7 @@ def calc_depclean(settings, trees, ldpath_mtimes, if args_set.findAtomForPackage(pkg) is None: world_temp_set.add("=" + pkg.cpv) continue - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: show_invalid_depstring_notice(pkg, pkg.metadata["PROVIDE"], str(e)) del e @@ -1531,11 +1531,11 @@ def action_metadata(settings, portdb, myopts, porttrees=None): tree_data.valid_nodes.add(cpv) try: src = tree_data.src_db[cpv] - except KeyError, e: + except KeyError as e: noise.missing_entry(cpv) del e continue - except CacheError, ce: + except CacheError as ce: noise.exception(cpv, ce) del ce continue @@ -1585,7 +1585,7 @@ def action_metadata(settings, portdb, myopts, porttrees=None): try: inherited = src.get('INHERITED', '') eclasses = src.get('_eclasses_') - except CacheError, ce: + except CacheError as ce: noise.exception(cpv, ce) del ce continue @@ -1630,7 +1630,7 @@ def action_metadata(settings, portdb, myopts, porttrees=None): try: tree_data.dest_db[cpv] = src - except CacheError, ce: + except CacheError as ce: noise.exception(cpv, ce) del ce @@ -1644,7 +1644,7 @@ def action_metadata(settings, portdb, myopts, porttrees=None): for tree_data in porttrees_data: try: dead_nodes = set(tree_data.dest_db.iterkeys()) - except CacheError, e: + except CacheError as e: writemsg_level("Error listing cache entries for " + \ "'%s': %s, continuing...\n" % (tree_data.path, e), level=logging.ERROR, noiselevel=-1) @@ -1673,7 +1673,7 @@ def action_regen(settings, portdb, max_jobs, max_load): portage.writemsg_stdout("Regenerating cache entries...\n") try: os.close(sys.stdin.fileno()) - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit except: pass @@ -1696,7 +1696,7 @@ def action_search(root_config, myopts, myfiles, spinner): for mysearch in myfiles: try: searchinstance.execute(mysearch) - except re.error, comment: + except re.error as comment: print "\n!!! Regular expression error in \"%s\": %s" % ( mysearch, comment ) sys.exit(1) searchinstance.output() @@ -1888,7 +1888,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): try: maxretries=int(settings["PORTAGE_RSYNC_RETRIES"]) - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit except: maxretries=3 #default number of retries @@ -1928,9 +1928,9 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): ips.append(addrinfo[4][0]) from random import shuffle shuffle(ips) - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit - except Exception, e: + except Exception as e: print "Notice:",str(e) dosyncuri=syncuri @@ -1939,9 +1939,9 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): dosyncuri = syncuri.replace( "//" + user_name + hostname + port + "/", "//" + user_name + ips[0] + port + "/", 1) - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit - except Exception, e: + except Exception as e: print "Notice:",str(e) dosyncuri=syncuri @@ -2008,7 +2008,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): os.unlink(tmpservertimestampfile) except OSError: pass - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: # timed out print e del e @@ -2129,7 +2129,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): sys.exit(1) try: os.rmdir(myportdir) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: sys.stderr.write( "!!! existing '%s' directory; exiting.\n" % myportdir) @@ -2224,7 +2224,7 @@ def action_uninstall(settings, trees, ldpath_mtimes, try: valid_atoms.append( portage.dep_expand(x, mydb=vardb, settings=settings)) - except portage.exception.AmbiguousPackageName, e: + except portage.exception.AmbiguousPackageName as e: msg = "The short ebuild name \"" + x + \ "\" is ambiguous. Please specify " + \ "one of the following " + \ @@ -2326,7 +2326,7 @@ def adjust_config(myopts, settings): CLEAN_DELAY = 5 try: CLEAN_DELAY = int(settings.get("CLEAN_DELAY", str(CLEAN_DELAY))) - except ValueError, e: + except ValueError as e: portage.writemsg("!!! %s\n" % str(e), noiselevel=-1) portage.writemsg("!!! Unable to parse integer: CLEAN_DELAY='%s'\n" % \ settings["CLEAN_DELAY"], noiselevel=-1) @@ -2337,7 +2337,7 @@ def adjust_config(myopts, settings): try: EMERGE_WARNING_DELAY = int(settings.get( "EMERGE_WARNING_DELAY", str(EMERGE_WARNING_DELAY))) - except ValueError, e: + except ValueError as e: portage.writemsg("!!! %s\n" % str(e), noiselevel=-1) portage.writemsg("!!! Unable to parse integer: EMERGE_WARNING_DELAY='%s'\n" % \ settings["EMERGE_WARNING_DELAY"], noiselevel=-1) @@ -2367,7 +2367,7 @@ def adjust_config(myopts, settings): portage.writemsg("!!! PORTAGE_DEBUG must be either 0 or 1\n", noiselevel=-1) PORTAGE_DEBUG = 0 - except ValueError, e: + except ValueError as e: portage.writemsg("!!! %s\n" % str(e), noiselevel=-1) portage.writemsg("!!! Unable to parse integer: PORTAGE_DEBUG='%s'\n" %\ settings["PORTAGE_DEBUG"], noiselevel=-1) @@ -2458,7 +2458,7 @@ def git_sync_timestamps(settings, portdir): try: cache_db = settings.load_best_module("portdbapi.metadbmodule")( portdir, "metadata/cache", portage.auxdbkeys[:], readonly=True) - except CacheError, e: + except CacheError as e: writemsg_level("!!! Unable to instantiate cache: %s\n" % (e,), level=logging.ERROR, noiselevel=-1) return 1 @@ -2467,7 +2467,7 @@ def git_sync_timestamps(settings, portdir): try: ec_names = set(f[:-7] for f in os.listdir(ec_dir) \ if f.endswith(".eclass")) - except OSError, e: + except OSError as e: writemsg_level("!!! Unable to list eclasses: %s\n" % (e,), level=logging.ERROR, noiselevel=-1) return 1 @@ -2508,7 +2508,7 @@ def git_sync_timestamps(settings, portdir): writemsg_level("!!! Missing cache entry: %s\n" % (cpv,), level=logging.ERROR, noiselevel=-1) continue - except CacheError, e: + except CacheError as e: writemsg_level("!!! Unable to access cache entry: %s %s\n" % \ (cpv, e), level=logging.ERROR, noiselevel=-1) continue diff --git a/pym/_emerge/changelog.py b/pym/_emerge/changelog.py index 0fdf5880a..2391a92ab 100644 --- a/pym/_emerge/changelog.py +++ b/pym/_emerge/changelog.py @@ -25,7 +25,7 @@ def calc_changelog(ebuildpath,current,next): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace' ).read() - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit except: return [] diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index e4affdf37..ea7d1b305 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -792,7 +792,7 @@ class depgraph(object): if True: try: arg_atoms = list(self._iter_atoms_for_pkg(pkg)) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: if not pkg.installed: show_invalid_depstring_notice( pkg, pkg.metadata["PROVIDE"], str(e)) @@ -931,7 +931,7 @@ class depgraph(object): settings.unlock() settings.setinst(pkg.cpv, pkg.metadata) settings.lock() - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: show_invalid_depstring_notice( pkg, pkg.metadata["PROVIDE"], str(e)) del e @@ -1079,7 +1079,7 @@ class depgraph(object): dep_string = list(self._queue_disjunctive_deps( pkg, dep_root, dep_priority, dep_string)) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: if pkg.installed: del e continue @@ -1096,7 +1096,7 @@ class depgraph(object): allow_unsatisfied): return 0 - except portage.exception.AmbiguousPackageName, e: + except portage.exception.AmbiguousPackageName as e: pkgs = e.args[0] portage.writemsg("\n\n!!! An atom in the dependencies " + \ "is not fully-qualified. Multiple matches:\n\n", noiselevel=-1) @@ -1135,7 +1135,7 @@ class depgraph(object): selected_atoms = self._select_atoms(dep_root, dep_string, myuse=pkg.use.enabled, parent=pkg, strict=strict, priority=dep_priority) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: show_invalid_depstring_notice(pkg, dep_string, str(e)) del e if pkg.installed: @@ -1678,23 +1678,23 @@ class depgraph(object): "dependencies for %s\n") % atom) return 0, myfavorites - except portage.exception.MissingSignature, e: + except portage.exception.MissingSignature as e: portage.writemsg("\n\n!!! A missing gpg signature is preventing portage from calculating the\n") portage.writemsg("!!! required dependencies. This is a security feature enabled by the admin\n") portage.writemsg("!!! to aid in the detection of malicious intent.\n\n") portage.writemsg("!!! THIS IS A POSSIBLE INDICATION OF TAMPERED FILES -- CHECK CAREFULLY.\n") portage.writemsg("!!! Affected file: %s\n" % (e), noiselevel=-1) return 0, myfavorites - except portage.exception.InvalidSignature, e: + except portage.exception.InvalidSignature as e: portage.writemsg("\n\n!!! An invalid gpg signature is preventing portage from calculating the\n") portage.writemsg("!!! required dependencies. This is a security feature enabled by the admin\n") portage.writemsg("!!! to aid in the detection of malicious intent.\n\n") portage.writemsg("!!! THIS IS A POSSIBLE INDICATION OF TAMPERED FILES -- CHECK CAREFULLY.\n") portage.writemsg("!!! Affected file: %s\n" % (e), noiselevel=-1) return 0, myfavorites - except SystemExit, e: + except SystemExit as e: raise # Needed else can't exit - except Exception, e: + except Exception as e: print >> sys.stderr, "\n\n!!! Problem in '%s' dependencies." % atom print >> sys.stderr, "!!!", str(e), getattr(e, "__module__", None) raise @@ -2648,7 +2648,7 @@ class depgraph(object): success, atoms = portage.dep_check(depstr, final_db, pkgsettings, myuse=pkg.use.enabled, trees=self._dynamic_config._graph_trees, myroot=myroot) - except Exception, e: + except Exception as e: if isinstance(e, SystemExit): raise # This is helpful, for example, if a ValueError @@ -2684,7 +2684,7 @@ class depgraph(object): blocker = Blocker(atom=portage.dep.Atom(atom), eapi=pkg.metadata["EAPI"], root=myroot) self._dynamic_config._blocker_parents.add(blocker, pkg) - except portage.exception.InvalidAtom, e: + except portage.exception.InvalidAtom as e: depstr = " ".join(vardb.aux_get(pkg.cpv, dep_keys)) show_invalid_depstring_notice( pkg, depstr, "Invalid Atom: %s" % (e,)) @@ -3055,7 +3055,7 @@ class depgraph(object): running_root, running_portage.metadata["RDEPEND"], myuse=running_portage.use.enabled, parent=running_portage, strict=False) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: portage.writemsg("!!! Invalid RDEPEND in " + \ "'%svar/db/pkg/%s/RDEPEND': %s\n" % \ (running_root, running_portage.cpv, e), noiselevel=-1) @@ -3291,7 +3291,7 @@ class depgraph(object): try: runtime_dep_atoms = \ list(runtime_deps.iterAtomsForPackage(task)) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: portage.writemsg("!!! Invalid PROVIDE in " + \ "'%svar/db/pkg/%s/PROVIDE': %s\n" % \ (task.root, task.cpv, e), noiselevel=-1) @@ -3326,7 +3326,7 @@ class depgraph(object): "system"].iterAtomsForPackage(task): skip = True break - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: portage.writemsg("!!! Invalid PROVIDE in " + \ "'%svar/db/pkg/%s/PROVIDE': %s\n" % \ (task.root, task.cpv, e), noiselevel=-1) @@ -3361,7 +3361,7 @@ class depgraph(object): skip = True self._dynamic_config._blocked_world_pkgs[inst_pkg] = atom break - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: portage.writemsg("!!! Invalid PROVIDE in " + \ "'%svar/db/pkg/%s/PROVIDE': %s\n" % \ (task.root, task.cpv, e), noiselevel=-1) @@ -4196,7 +4196,7 @@ class depgraph(object): try: myfilesdict = portdb.getfetchsizes(pkg_key, useflags=pkg_use, debug=self._frozen_config.edebug) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: src_uri = portdb.aux_get(pkg_key, ["SRC_URI"])[0] show_invalid_depstring_notice(x, src_uri, str(e)) del e @@ -4252,7 +4252,7 @@ class depgraph(object): if "COLUMNWIDTH" in self._frozen_config.settings: try: mywidth = int(self._frozen_config.settings["COLUMNWIDTH"]) - except ValueError, e: + except ValueError as e: portage.writemsg("!!! %s\n" % str(e), noiselevel=-1) portage.writemsg( "!!! Unable to parse COLUMNWIDTH='%s'\n" % \ @@ -4601,7 +4601,7 @@ class depgraph(object): if myfavkey in added_favorites: continue added_favorites.add(myfavkey) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: writemsg("\n\n!!! '%s' has invalid PROVIDE: %s\n" % \ (pkg_key, str(e)), noiselevel=-1) writemsg("!!! see '%s'\n\n" % os.path.join( @@ -5080,7 +5080,7 @@ def resume_depgraph(settings, trees, mtimedb, myopts, myparams, spinner): try: success = mydepgraph._loadResumeCommand(mtimedb["resume"], skip_masked=skip_masked) - except depgraph.UnsatisfiedResumeDep, e: + except depgraph.UnsatisfiedResumeDep as e: if not skip_unsatisfied: raise diff --git a/pym/_emerge/emergelog.py b/pym/_emerge/emergelog.py index cdc60767b..4e9a2e93e 100644 --- a/pym/_emerge/emergelog.py +++ b/pym/_emerge/emergelog.py @@ -46,6 +46,6 @@ def emergelog(xterm_titles, mystr, short_msg=None): if mylock: portage.locks.unlockfile(mylock) mylogfile.close() - except (IOError,OSError,portage.exception.PortageException), e: + except (IOError,OSError,portage.exception.PortageException) as e: if secpass >= 1: print >> sys.stderr, "emergelog():",e diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index 6307904b7..0df815a02 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -137,7 +137,7 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): try: os.rename(dir_file + ext, dir_file + ext + ".old") moved_old_dir = True - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -164,7 +164,7 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): for ext in dir_extensions: try: os.rename(dir_file + ext + ".old", dir_file + ext) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -174,7 +174,7 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): for ext in dir_extensions: try: os.unlink(dir_file + ext + ".old") - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -213,7 +213,7 @@ def display_preserved_libs(vardbapi, myopts): try: linkmap.rebuild() - except portage.exception.CommandNotFound, e: + except portage.exception.CommandNotFound as e: writemsg_level("!!! Command Not Found: %s\n" % (e,), level=logging.ERROR, noiselevel=-1) del e @@ -783,7 +783,7 @@ def apply_priorities(settings): def nice(settings): try: os.nice(int(settings.get("PORTAGE_NICENESS", "0"))) - except (OSError, ValueError), e: + except (OSError, ValueError) as e: out = portage.output.EOutput() out.eerror("Failed to change nice value to '%s'" % \ settings["PORTAGE_NICENESS"]) @@ -910,7 +910,7 @@ def expand_set_arguments(myfiles, myaction, root_config): setconfig.active.append(s) try: set_atoms = setconfig.getSetAtoms(s) - except portage.exception.PackageSetNotFound, e: + except portage.exception.PackageSetNotFound as e: writemsg_level(("emerge: the given set '%s' " + \ "contains a non-existent set named '%s'.\n") % \ (s, e), level=logging.ERROR, noiselevel=-1) @@ -1281,7 +1281,7 @@ def emerge_main(): try: # At least the parent needs to exist for the lock file. portage.util.ensure_dirs(settings['EMERGE_LOG_DIR']) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: writemsg_level("!!! Error creating directory for " + \ "EMERGE_LOG_DIR='%s':\n!!! %s\n" % \ (settings['EMERGE_LOG_DIR'], e), @@ -1364,7 +1364,7 @@ def emerge_main(): try: valid_atoms.append( portage.dep_expand(x, mydb=vardb, settings=settings)) - except portage.exception.AmbiguousPackageName, e: + except portage.exception.AmbiguousPackageName as e: msg = "The short ebuild name \"" + x + \ "\" is ambiguous. Please specify " + \ "one of the following " + \ diff --git a/pym/_emerge/search.py b/pym/_emerge/search.py index 1f276b47e..9f0811dea 100644 --- a/pym/_emerge/search.py +++ b/pym/_emerge/search.py @@ -315,13 +315,13 @@ class search(object): pkgdir, self.settings["DISTDIR"]) try: uri_map = self.portdb.getFetchMap(mycpv) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: file_size_str = "Unknown (%s)" % (e,) del e else: try: mysum[0] = mf.getDistfilesSize(uri_map) - except KeyError, e: + except KeyError as e: file_size_str = "Unknown (missing " + \ "digest for %s)" % (e,) del e diff --git a/pym/_emerge/unmerge.py b/pym/_emerge/unmerge.py index cfa57bbc7..76b379581 100644 --- a/pym/_emerge/unmerge.py +++ b/pym/_emerge/unmerge.py @@ -171,7 +171,7 @@ def unmerge(root_config, myopts, unmerge_action, # what will and will not get unmerged try: mymatch = vartree.dbapi.match(x) - except portage.exception.AmbiguousPackageName, errpkgs: + except portage.exception.AmbiguousPackageName as errpkgs: print "\n\n!!! The short ebuild name \"" + \ x + "\" is ambiguous. Please specify" print "!!! one of the following fully-qualified " + \ diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index b7c4e9e44..f2a810531 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -42,7 +42,7 @@ try: import shutil del shutil -except ImportError, e: +except ImportError as e: sys.stderr.write("\n\n") sys.stderr.write("!!! Failed to complete python imports. These are internal modules for\n") sys.stderr.write("!!! python and failure here indicates that you have a problem with python\n") @@ -108,7 +108,7 @@ try: from portage.localization import _ -except ImportError, e: +except ImportError as e: sys.stderr.write("\n\n") sys.stderr.write("!!! Failed to complete portage imports. There are internal modules for\n") sys.stderr.write("!!! portage and failure here indicates that you have a problem with your\n") @@ -257,7 +257,7 @@ try: encoding=_encodings['fs']) _selinux_merge = _unicode_module_wrapper(_selinux, encoding=_encodings['merge']) -except OSError, e: +except OSError as e: sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e)) del e except ImportError: @@ -513,7 +513,7 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli mtime = pathstat.st_mtime else: raise portage.exception.DirectoryNotFound(mypath) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno == portage.exception.PermissionDenied.errno: raise portage.exception.PermissionDenied(mypath) del e @@ -530,7 +530,7 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli cacheStale += 1 try: list = os.listdir(mypath) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.EACCES: raise del e @@ -966,7 +966,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, file_path = os.path.join(envd_dir, x) try: myconfig = getconfig(file_path, expand=False) - except portage.exception.ParseError, e: + except portage.exception.ParseError as e: writemsg("!!! '%s'\n" % str(e), noiselevel=-1) del e continue @@ -1027,7 +1027,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, if x[0]=="#": continue oldld.append(x[:-1]) - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno != errno.ENOENT: raise oldld = None @@ -1087,7 +1087,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, try: newldpathtime = long(os.stat(x).st_mtime) lib_dirs.add(normalize_path(x)) - except OSError, oe: + except OSError as oe: if oe.errno == errno.ENOENT: try: del prev_mtimes[x] @@ -1202,17 +1202,17 @@ def ExtractKernelVersion(base_dir): f = codecs.open(_unicode_encode(pathname, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace') - except OSError, details: + except OSError as details: return (None, str(details)) - except IOError, details: + except IOError as details: return (None, str(details)) try: for i in range(4): lines.append(f.readline()) - except OSError, details: + except OSError as details: return (None, str(details)) - except IOError, details: + except IOError as details: return (None, str(details)) lines = [l.strip() for l in lines] @@ -1687,7 +1687,7 @@ class config(object): self.profiles.append(currentPath) try: addProfile(os.path.realpath(self.profile_path)) - except portage.exception.ParseError, e: + except portage.exception.ParseError as e: writemsg(_("!!! Unable to parse profile: '%s'\n") % \ self.profile_path, noiselevel=-1) writemsg("!!! ParseError: %s\n" % str(e), noiselevel=-1) @@ -1999,11 +1999,11 @@ class config(object): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace') ) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e - except ParsingError, e: + except ParsingError as e: portage.util.writemsg_level( _("!!! Error parsing '%s': %s\n") % \ (self._local_repo_conf_path, e), @@ -2198,7 +2198,7 @@ class config(object): continue try: portage.util.ensure_dirs(mydir, gid=gid, mode=mode, mask=modemask) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: writemsg(_("!!! Directory initialization failed: '%s'\n") % mydir, noiselevel=-1) writemsg("!!! %s\n" % str(e), @@ -3138,7 +3138,7 @@ class config(object): elif len(accept_chost) == 1: try: self._accept_chost_re = re.compile(r'^%s$' % accept_chost[0]) - except re.error, e: + except re.error as e: writemsg(_("!!! Invalid ACCEPT_CHOSTS value: '%s': %s\n") % \ (accept_chost[0], e), noiselevel=-1) self._accept_chost_re = re.compile("^$") @@ -3146,7 +3146,7 @@ class config(object): try: self._accept_chost_re = re.compile( r'^(%s)$' % "|".join(accept_chost)) - except re.error, e: + except re.error as e: writemsg(_("!!! Invalid ACCEPT_CHOSTS value: '%s': %s\n") % \ (" ".join(accept_chost), e), noiselevel=-1) self._accept_chost_re = re.compile("^$") @@ -3739,7 +3739,7 @@ def _create_pty_or_pipe(copy_term_size=None): try: master_fd, slave_fd = openpty() got_pty = True - except EnvironmentError, e: + except EnvironmentError as e: _disable_openpty = True writemsg("openpty failed: '%s'\n" % str(e), noiselevel=-1) @@ -4396,7 +4396,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", filemode=filemode, filemask=modemask, onerror=onerror): raise portage.exception.OperationNotPermitted( _("Failed to apply recursive permissions for the portage group.")) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: if not os.path.isdir(mysettings["DISTDIR"]): writemsg("!!! %s\n" % str(e), noiselevel=-1) writemsg(_("!!! Directory Not Found: DISTDIR='%s'\n") % mysettings["DISTDIR"], noiselevel=-1) @@ -4456,7 +4456,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", vfs_stat = os.statvfs(mysettings["DISTDIR"]) try: mysize = os.stat(myfile_path).st_size - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4520,7 +4520,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", apply_secpass_permissions(myfile_path, gid=portage_gid, mode=0664, mask=02, stat_cached=mystat) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: if not os.access(myfile_path, os.R_OK): writemsg(_("!!! Failed to adjust permissions:" " %s\n") % str(e), noiselevel=-1) @@ -4589,7 +4589,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if readonly_file is not None: try: os.unlink(myfile_path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4603,14 +4603,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", shutil.copyfile(mirror_file, myfile_path) writemsg(_("Local mirror has file: %s\n") % myfile) break - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e try: mystat = os.stat(myfile_path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4619,7 +4619,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", apply_secpass_permissions( myfile_path, gid=portage_gid, mode=0664, mask=02, stat_cached=mystat) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: if not os.access(myfile_path, os.R_OK): writemsg(_("!!! Failed to adjust permissions:" " %s\n") % str(e), noiselevel=-1) @@ -4754,7 +4754,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if fetched != 2: try: mysize = os.stat(myfile_path).st_size - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4778,7 +4778,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if fetched == 1: try: mystat = os.stat(myfile_path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4790,7 +4790,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", "ME_MIN_SIZE)\n") % mystat.st_size) try: os.unlink(myfile_path) - except OSError, e: + except OSError as e: if e.errno not in \ (errno.ENOENT, errno.ESTALE): raise @@ -4824,9 +4824,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", try: apply_secpass_permissions(myfile_path, gid=portage_gid, mode=0664, mask=02) - except portage.exception.FileNotFound, e: + except portage.exception.FileNotFound as e: pass - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: if not os.access(myfile_path, os.R_OK): writemsg(_("!!! Failed to adjust permissions:" " %s\n") % str(e), noiselevel=-1) @@ -4845,7 +4845,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if mydigests is not None and myfile in mydigests: try: mystat = os.stat(myfile_path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e @@ -4987,7 +4987,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", try: private_tmpdir = mkdtemp("", "._portage_fetch_.", global_tmpdir) - except OSError, e: + except OSError as e: if e.errno != portage.exception.PermissionDenied.errno: raise raise portage.exception.PermissionDenied(global_tmpdir) @@ -5067,7 +5067,7 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None try: for myfile in fetchlist_dict[cpv]: distfiles_map.setdefault(myfile, []).append(cpv) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: writemsg("!!! %s\n" % str(e), noiselevel=-1) del e return 0 @@ -5106,7 +5106,7 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None try: st = os.stat(os.path.join(mysettings["DISTDIR"], myfile)) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -5169,16 +5169,16 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None assumeDistHashesSometimes=True, assumeDistHashesAlways=( "assume-digests" in mysettings.features)) - except portage.exception.FileNotFound, e: + except portage.exception.FileNotFound as e: writemsg(_("!!! File %s doesn't exist, can't update " "Manifest\n") % e, noiselevel=-1) return 0 - except portage.exception.PortagePackageException, e: + except portage.exception.PortagePackageException as e: writemsg(("!!! %s\n") % (e,), noiselevel=-1) return 0 try: mf.write(sign=False) - except portage.exception.PermissionDenied, e: + except portage.exception.PermissionDenied as e: writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=-1) return 0 if "assume-digests" not in mysettings.features: @@ -5277,16 +5277,16 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0): raise KeyError(f) mf.checkFileHashes(ftype, f) eout.eend(0) - except KeyError, e: + except KeyError as e: eout.eend(1) writemsg(_("\n!!! Missing digest for %s\n") % str(e), noiselevel=-1) return 0 - except portage.exception.FileNotFound, e: + except portage.exception.FileNotFound as e: eout.eend(1) writemsg(_("\n!!! A file listed in the Manifest could not be found: %s\n") % str(e), noiselevel=-1) return 0 - except portage.exception.DigestException, e: + except portage.exception.DigestException as e: eout.eend(1) writemsg(_("\n!!! Digest verification failed:\n"), noiselevel=-1) writemsg("!!! %s\n" % e.value[0], noiselevel=-1) @@ -6035,7 +6035,7 @@ def prepare_build_dirs(myroot, mysettings, cleanup): for clean_dir in clean_dirs: try: shutil.rmtree(clean_dir) - except OSError, oe: + except OSError as oe: if errno.ENOENT == oe.errno: pass elif errno.EPERM == oe.errno: @@ -6049,7 +6049,7 @@ def prepare_build_dirs(myroot, mysettings, cleanup): def makedirs(dir_path): try: os.makedirs(dir_path) - except OSError, oe: + except OSError as oe: if errno.EEXIST == oe.errno: pass elif errno.EPERM == oe.errno: @@ -6080,13 +6080,13 @@ def prepare_build_dirs(myroot, mysettings, cleanup): portage.util.ensure_dirs(mysettings[dir_key], mode=0775) portage.util.apply_secpass_permissions(mysettings[dir_key], uid=portage_uid, gid=portage_gid) - except portage.exception.PermissionDenied, e: + except portage.exception.PermissionDenied as e: writemsg(_("Permission Denied: %s\n") % str(e), noiselevel=-1) return 1 - except portage.exception.OperationNotPermitted, e: + except portage.exception.OperationNotPermitted as e: writemsg(_("Operation Not Permitted: %s\n") % str(e), noiselevel=-1) return 1 - except portage.exception.FileNotFound, e: + except portage.exception.FileNotFound as e: writemsg(_("File Not Found: '%s'\n") % str(e), noiselevel=-1) return 1 @@ -6209,14 +6209,14 @@ def _prepare_features_dirs(mysettings): raise portage.exception.OperationNotPermitted( _("Failed to apply recursive permissions for the portage group.")) - except portage.exception.DirectoryNotFound, e: + except portage.exception.DirectoryNotFound as e: failure = True writemsg(_("\n!!! Directory does not exist: '%s'\n") % \ (e,), noiselevel=-1) writemsg(_("!!! Disabled FEATURES='%s'\n") % myfeature, noiselevel=-1) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: failure = True writemsg("\n!!! %s\n" % str(e), noiselevel=-1) writemsg(_("!!! Failed resetting perms on %s='%s'\n") % \ @@ -6243,9 +6243,9 @@ def _prepare_workdir(mysettings): raise ValueError("Invalid file mode: %s" % mode) else: workdir_mode = parsed_mode - except KeyError, e: + except KeyError as e: writemsg(_("!!! PORTAGE_WORKDIR_MODE is unset, using %s.\n") % oct(workdir_mode)) - except ValueError, e: + except ValueError as e: if len(str(e)) > 0: writemsg("%s\n" % e) writemsg(_("!!! Unable to parse PORTAGE_WORKDIR_MODE='%s', using %s.\n") % \ @@ -6266,7 +6266,7 @@ def _prepare_workdir(mysettings): if modified: apply_secpass_permissions(mysettings["PORT_LOGDIR"], uid=portage_uid, gid=portage_gid, mode=02770) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: writemsg("!!! %s\n" % str(e), noiselevel=-1) writemsg(_("!!! Permission issues with PORT_LOGDIR='%s'\n") % \ mysettings["PORT_LOGDIR"], noiselevel=-1) @@ -6518,7 +6518,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, "could not be found: '%s'") % (myebuild,)) _doebuild_broken_ebuilds.add(myebuild) return 1 - except portage.exception.DigestException, e: + except portage.exception.DigestException as e: out = portage.output.EOutput() out.eerror(_("Digest verification failed:")) out.eerror("%s" % e.value[0]) @@ -6729,7 +6729,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, saved_env = None try: env_stat = os.stat(env_file) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -6745,7 +6745,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, _shell_quote(env_file))) try: env_stat = os.stat(env_file) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -6762,7 +6762,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, saved_env, noiselevel=-1) try: os.unlink(env_file) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -6888,7 +6888,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, alist = mydbapi.getFetchMap(mycpv, useflags=useflags, mytree=mytree) aalist = mydbapi.getFetchMap(mycpv, mytree=mytree) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: writemsg("!!! %s\n" % str(e), noiselevel=-1) writemsg(_("!!! Invalid SRC_URI for '%s'.\n") % mycpv, noiselevel=-1) @@ -6932,7 +6932,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, # for fetch (especially parallel-fetch) since it's not needed # and it can interfere with parallel tasks. digestgen(aalist, mysettings, overwrite=0, myportdb=mydbapi) - except portage.exception.PermissionDenied, e: + except portage.exception.PermissionDenied as e: writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=-1) if mydo in ("digest", "manifest"): return 1 @@ -7131,7 +7131,7 @@ def _validate_deps(mysettings, myroot, mydo, mydbapi): try: portage.dep.use_reduce( portage.dep.paren_reduce(metadata[k]), matchall=True) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: msgs.append(" %s: %s\n %s\n" % ( k, metadata[k], str(e))) @@ -7181,9 +7181,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, if not sstat: sstat=os.lstat(src) - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: print _("!!! Stating source file failed... movefile()") print "!!!",e return None @@ -7209,9 +7209,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, try: os.unlink(dest) destexists=0 - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: pass if stat.S_ISLNK(sstat[stat.ST_MODE]): @@ -7230,9 +7230,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, # utime() only works on the target of a symlink, so it's not # possible to perserve mtime on symlinks. return os.lstat(dest)[stat.ST_MTIME] - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: print _("!!! failed to properly create symlink:") print "!!!",dest,"->",target print "!!!",e @@ -7249,7 +7249,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, (tail, os.getpid())) try: os.unlink(hardlink_tmp) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: writemsg(_("!!! Failed to remove hardlink temp file: %s\n") % \ (hardlink_tmp,), noiselevel=-1) @@ -7264,7 +7264,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, else: try: os.rename(hardlink_tmp, dest) - except OSError, e: + except OSError as e: writemsg(_("!!! Failed to rename %s to %s\n") % \ (hardlink_tmp, dest), noiselevel=-1) writemsg("!!! %s\n" % (e,), noiselevel=-1) @@ -7282,9 +7282,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, else: ret=os.rename(src,dest) renamefailed=0 - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: if e[0]!=errno.EXDEV: # Some random error. print _("!!! Failed to move %(src)s to %(dest)s") % {"src": src, "dest": dest} @@ -7302,9 +7302,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, shutil.copyfile(src,dest+"#new") os.rename(dest+"#new",dest) didcopy=1 - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: print _('!!! copy %(src)s -> %(dest)s failed.') % {"src": src, "dest": dest} print "!!!",e return None @@ -7326,9 +7326,9 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, os.chown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown os.unlink(src) - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: print _("!!! Failed to chown/chmod/unlink in movefile()") print "!!!",dest print "!!!",e @@ -7348,7 +7348,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, # Instead of failing, use stat to return the mtime if possible. try: newmtime = long(os.stat(dest).st_mtime) - except OSError, e: + except OSError as e: writemsg(_("!!! Failed to stat in movefile()\n"), noiselevel=-1) writemsg("!!! %s\n" % dest, noiselevel=-1) writemsg("!!! %s\n" % str(e), noiselevel=-1) @@ -7905,7 +7905,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None, #convert parenthesis to sublists try: mysplit = portage.dep.paren_reduce(depstring) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: return [0, str(e)] mymasks = set() @@ -7927,7 +7927,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None, try: mysplit = portage.dep.use_reduce(mysplit, uselist=myusesplit, masklist=mymasks, matchall=(use=="all"), excludeall=useforce) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: return [0, str(e)] # Do the || conversions @@ -7944,7 +7944,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None, use=use, mode=mode, myuse=myuse, use_force=useforce, use_mask=mymasks, use_cache=use_cache, use_binaries=use_binaries, myroot=myroot, trees=trees) - except portage.exception.ParseError, e: + except portage.exception.ParseError as e: return [0, str(e)] mysplit2=mysplit[:] @@ -7959,7 +7959,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None, try: selected_atoms = dep_zapdeps(mysplit, mysplit2, myroot, use_binaries=use_binaries, trees=trees) - except portage.exception.InvalidAtom, e: + except portage.exception.InvalidAtom as e: if portage.dep._dep_check_strict: raise # This shouldn't happen. # dbapi.match() failed due to an invalid atom in @@ -8323,7 +8323,7 @@ def getmaskingstatus(mycpv, settings=None, portdb=None): msg = license_split[:] msg.append("license(s)") rValue.append(" ".join(msg)) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: rValue.append("LICENSE: "+str(e)) try: @@ -8337,7 +8337,7 @@ def getmaskingstatus(mycpv, settings=None, portdb=None): msg = properties_split[:] msg.append("properties") rValue.append(" ".join(msg)) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: rValue.append("PROPERTIES: "+str(e)) # Only show KEYWORDS masks for installed packages @@ -8442,7 +8442,7 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, uid=portage_uid, gid=portage_gid, mode=070, mask=0) try: shutil.rmtree(builddir) - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno != errno.ENOENT: raise del e @@ -8501,7 +8501,7 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, try: if success: shutil.rmtree(builddir) - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno != errno.ENOENT: raise del e @@ -8559,7 +8559,7 @@ def commit_mtimedb(mydict=None, filename=None): f.close() portage.util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0644) - except (IOError, OSError), e: + except (IOError, OSError) as e: pass def portageexit(): @@ -8728,7 +8728,7 @@ class MtimeDB(dict): d = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError), e: + except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e: if isinstance(e, pickle.UnpicklingError): writemsg(_("!!! Error loading '%s': %s\n") % \ (filename, str(e)), noiselevel=-1) diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py index 226c6d7d0..5b771adad 100644 --- a/pym/portage/cache/anydbm.py +++ b/pym/portage/cache/anydbm.py @@ -38,7 +38,7 @@ class database(fs_template.FsBased): try: self._ensure_dirs() self._ensure_dirs(self._db_path) - except (OSError, IOError), e: + except (OSError, IOError) as e: raise cache_errors.InitializationError(self.__class__, e) # try again if failed @@ -46,7 +46,7 @@ class database(fs_template.FsBased): if self.__db == None: self.__db = anydbm_module.open( _unicode_encode(self._db_path), 'c', self._perms) - except anydbm_module.error, e: + 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/ebuild_xattr.py b/pym/portage/cache/ebuild_xattr.py index fa3937e2f..4bcc6c846 100644 --- a/pym/portage/cache/ebuild_xattr.py +++ b/pym/portage/cache/ebuild_xattr.py @@ -35,7 +35,7 @@ class database(fs_template.FsBased): path = os.path.join(self.portdir,'profiles/repo_name') try: return int(self.__get(path,'value_max_len')) - except NoValueException,e: + except NoValueException as e: max = self.__calc_max(path) self.__set(path,'value_max_len',str(max)) return max @@ -54,7 +54,7 @@ class database(fs_template.FsBased): while True: self.__set(path,'test_max',s) s+=hundred - except IOError,e: + except IOError as e: # ext based give wrong errno # http://bugzilla.kernel.org/show_bug.cgi?id=12793 if e.errno in (E2BIG,ENOSPC): @@ -64,7 +64,7 @@ class database(fs_template.FsBased): try: self.__remove(path,'test_max') - except IOError,e: + except IOError as e: if e.errno is not ENODATA: raise e @@ -77,7 +77,7 @@ class database(fs_template.FsBased): def __has_cache(self,path): try: self.__get(path,'_mtime_') - except NoValueException,e: + except NoValueException as e: return False return True @@ -85,7 +85,7 @@ class database(fs_template.FsBased): def __get(self,path,key,default=None): try: return xattr.get(path,key,namespace=self.ns) - except IOError,e: + except IOError as e: if not default is None and ENODATA == e.errno: return default else: diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py index 259be4108..3f46df8b9 100644 --- a/pym/portage/cache/flat_hash.py +++ b/pym/portage/cache/flat_hash.py @@ -43,7 +43,7 @@ class database(fs_template.FsBased): return d finally: myf.close() - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno != errno.ENOENT: raise cache_errors.CacheCorruption(cpv, e) raise KeyError(cpv) @@ -51,7 +51,7 @@ class database(fs_template.FsBased): def _parse_data(self, data, cpv): try: d = dict(map(lambda x:x.rstrip("\n").split("=", 1), data)) - except ValueError, e: + except ValueError as e: # If a line is missing an "=", the split length is 1 instead of 2. raise cache_errors.CacheCorruption(cpv, e) return d @@ -65,7 +65,7 @@ class database(fs_template.FsBased): encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], errors='backslashreplace') - except (IOError, OSError), e: + except (IOError, OSError) as e: if errno.ENOENT == e.errno: try: self._ensure_dirs(cpv) @@ -73,7 +73,7 @@ class database(fs_template.FsBased): encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], errors='backslashreplace') - except (OSError, IOError),e: + except (OSError, IOError) as e: raise cache_errors.CacheCorruption(cpv, e) else: raise cache_errors.CacheCorruption(cpv, e) @@ -93,7 +93,7 @@ class database(fs_template.FsBased): new_fp = os.path.join(self.location,cpv) try: os.rename(fp, new_fp) - except (OSError, IOError), e: + except (OSError, IOError) as e: os.remove(fp) raise cache_errors.CacheCorruption(cpv, e) @@ -102,7 +102,7 @@ class database(fs_template.FsBased): # import pdb;pdb.set_trace() try: os.remove(os.path.join(self.location,cpv)) - except OSError, e: + except OSError as e: if errno.ENOENT == e.errno: raise KeyError(cpv) else: @@ -120,7 +120,7 @@ class database(fs_template.FsBased): while len(dirs): try: dir_list = os.listdir(dirs[0]) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e diff --git a/pym/portage/cache/flat_list.py b/pym/portage/cache/flat_list.py index 1d4dbd28f..cfa3340cd 100644 --- a/pym/portage/cache/flat_list.py +++ b/pym/portage/cache/flat_list.py @@ -38,14 +38,14 @@ class database(fs_template.FsBased): errors='replace') for k,v in zip(self.auxdbkey_order, myf): d[k] = v.rstrip("\n") - except (OSError, IOError),e: + except (OSError, IOError) as e: if errno.ENOENT == e.errno: raise KeyError(cpv) raise cache_errors.CacheCorruption(cpv, e) try: d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime) - except OSError, e: + except OSError as e: myf.close() raise cache_errors.CacheCorruption(cpv, e) myf.close() @@ -60,7 +60,7 @@ class database(fs_template.FsBased): encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], errors='backslashreplace') - except (OSError, IOError), e: + except (OSError, IOError) as e: if errno.ENOENT == e.errno: try: self._ensure_dirs(cpv) @@ -68,7 +68,7 @@ class database(fs_template.FsBased): encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], errors='backslashreplace') - except (OSError, IOError),e: + except (OSError, IOError) as e: raise cache_errors.CacheCorruption(cpv, e) else: raise cache_errors.CacheCorruption(cpv, e) @@ -83,7 +83,7 @@ class database(fs_template.FsBased): new_fp = os.path.join(self._base,cpv) try: os.rename(fp, new_fp) - except (OSError, IOError), e: + except (OSError, IOError) as e: os.remove(fp) raise cache_errors.CacheCorruption(cpv, e) @@ -91,7 +91,7 @@ class database(fs_template.FsBased): def _delitem(self, cpv): try: os.remove(os.path.join(self._base,cpv)) - except OSError, e: + except OSError as e: if errno.ENOENT == e.errno: raise KeyError(cpv) else: diff --git a/pym/portage/cache/metadata.py b/pym/portage/cache/metadata.py index ff1227bdb..8b35593c2 100644 --- a/pym/portage/cache/metadata.py +++ b/pym/portage/cache/metadata.py @@ -61,7 +61,7 @@ class database(flat_hash.database): try: d["_eclasses_"] = self.ec.get_eclass_data( d["INHERITED"].split()) - except KeyError, e: + except KeyError as e: # INHERITED contains a non-existent eclass. raise cache_errors.CacheCorruption(cpv, e) del d["INHERITED"] @@ -122,13 +122,13 @@ class database(flat_hash.database): try: myf = open(_unicode_encode(fp, encoding=_encodings['fs'], errors='strict'), 'wb') - except EnvironmentError, e: + except EnvironmentError as e: if errno.ENOENT == e.errno: try: self._ensure_dirs(cpv) myf = open(_unicode_encode(fp, encoding=_encodings['fs'], errors='strict'), 'wb') - except EnvironmentError, e: + except EnvironmentError as e: raise cache_errors.CacheCorruption(cpv, e) else: raise cache_errors.CacheCorruption(cpv, e) @@ -141,7 +141,7 @@ class database(flat_hash.database): try: os.rename(fp, new_fp) - except EnvironmentError, e: + except EnvironmentError as e: try: os.unlink(fp) except EnvironmentError: diff --git a/pym/portage/cache/sql_template.py b/pym/portage/cache/sql_template.py index a002d6c06..a4580bdc7 100644 --- a/pym/portage/cache/sql_template.py +++ b/pym/portage/cache/sql_template.py @@ -74,7 +74,7 @@ class SQLDatabase(template.database): self.SCHEMA_PACKAGE_NAME) try: self.con.execute(self.SCHEMA_PACKAGE_CREATE) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.InitializationError(self.__class__, e) if not self._table_exists(self.SCHEMA_VALUES_NAME): @@ -83,7 +83,7 @@ class SQLDatabase(template.database): self.SCHEMA_VALUES_NAME) try: self.con.execute(self.SCHEMA_VALUES_CREATE) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.InitializationError(self.__class__, e) @@ -103,7 +103,7 @@ class SQLDatabase(template.database): self.con.execute("SELECT key, value FROM %s NATURAL JOIN %s " "WHERE label=%s AND cpv=%s" % (self.SCHEMA_PACKAGE_NAME, self.SCHEMA_VALUES_NAME, self.label, self._sfilter(cpv))) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.CacheCorruption(self, cpv, e) rows = self.con.fetchall() @@ -126,7 +126,7 @@ class SQLDatabase(template.database): (self.SCHEMA_PACKAGE_NAME, self.label, self._sfilter(cpv))) if self.autocommits: self.commit() - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.CacheCorruption(self, cpv, e) if self.con.rowcount <= 0: raise KeyError(cpv) @@ -148,7 +148,7 @@ class SQLDatabase(template.database): # insert. try: pkgid = self._insert_cpv(cpv) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.CacheCorruption(cpv, e) # __getitem__ fills out missing values, @@ -162,7 +162,7 @@ class SQLDatabase(template.database): try: self.con.executemany("INSERT INTO %s (pkgid, key, value) VALUES(\"%s\", %%(key)s, %%(value)s)" % \ (self.SCHEMA_VALUES_NAME, str(pkgid)), db_values) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.CacheCorruption(cpv, e) if self.autocommits: self.commit() @@ -210,13 +210,13 @@ class SQLDatabase(template.database): if not self.autocommits: try: self.commit() - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.GeneralCacheCorruption(e) try: self.con.execute("SELECT cpv FROM %s WHERE label=%s AND cpv=%s" % \ (self.SCHEMA_PACKAGE_NAME, self.label, self._sfilter(cpv))) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.GeneralCacheCorruption(e) return self.con.rowcount > 0 @@ -225,13 +225,13 @@ class SQLDatabase(template.database): if not self.autocommits: try: self.commit() - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.GeneralCacheCorruption(e) try: self.con.execute("SELECT cpv FROM %s WHERE label=%s" % (self.SCHEMA_PACKAGE_NAME, self.label)) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.GeneralCacheCorruption(e) # return [ row[0] for row in self.con.fetchall() ] for x in self.con.fetchall(): @@ -242,7 +242,7 @@ class SQLDatabase(template.database): self.con.execute("SELECT cpv, key, value FROM %s NATURAL JOIN %s " "WHERE label=%s" % (self.SCHEMA_PACKAGE_NAME, self.SCHEMA_VALUES_NAME, self.label)) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.CacheCorruption(self, cpv, e) oldcpv = None @@ -288,7 +288,7 @@ class SQLDatabase(template.database): try: self.con.execute("SELECT cpv from package_cache natural join values_cache WHERE label=%s %s" % \ (self.label, query)) - except self._BaseError, e: + except self._BaseError as e: raise cache_errors.GeneralCacheCorruption(e) return [ row[0] for row in self.con.fetchall() ] diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index d5f765459..073ca2cd8 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -70,7 +70,7 @@ class database(fs_template.FsBased): raise cache_errors.InitializationError(self.__class__, "can't ensure perms on %s" % self._dbpath) self._db_init_cache_size(config["cache_bytes"]) self._db_init_synchronous(config["synchronous"]) - except self._db_error, e: + except self._db_error as e: raise cache_errors.InitializationError(self.__class__, e) def _db_init_structures(self): @@ -189,7 +189,7 @@ class database(fs_template.FsBased): try: s = " ".join(update_statement) cursor.execute(s) - except self._db_error, e: + except self._db_error as e: writemsg("%s: %s\n" % (cpv, str(e))) raise diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index 97adb1058..d4573c760 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -173,7 +173,7 @@ class database(object): restricts[key] = re.compile(match).match else: restricts[key] = re.compile(match[0],match[1]).match - except re.error, e: + except re.error as e: raise InvalidRestriction(key, match, e) if key not in self.__known_keys: raise InvalidRestriction(key, match, "Key isn't valid") diff --git a/pym/portage/cache/util.py b/pym/portage/cache/util.py index 57d328ced..7b2f1026a 100644 --- a/pym/portage/cache/util.py +++ b/pym/portage/cache/util.py @@ -33,11 +33,11 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, dead_nodes.discard(x) try: entry = src_cache[x] - except KeyError, e: + except KeyError as e: noise.missing_entry(x) del e continue - except cache_errors.CacheError, ce: + except cache_errors.CacheError as ce: noise.exception(x, ce) del ce continue @@ -82,7 +82,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, try: inherited = entry.get("INHERITED", "") eclasses = entry.get("_eclasses_") - except cache_errors.CacheError, ce: + except cache_errors.CacheError as ce: noise.exception(x, ce) del ce continue @@ -123,7 +123,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, # been updated/translated (if needs be, for metadata/cache mainly) try: trg_cache[x] = entry - except cache_errors.CacheError, ce: + except cache_errors.CacheError as ce: noise.exception(x, ce) del ce continue @@ -141,7 +141,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, del trg_cache[key] except KeyError: pass - except cache_errors.CacheError, ce: + except cache_errors.CacheError as ce: noise.exception(ce) del ce noise.finish() diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 0a67d2dc0..7b1340dad 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -67,7 +67,7 @@ try: from Crypto.Hash import SHA256, RIPEMD sha256hash = _generate_hash_function("SHA256", SHA256.new, origin="pycrypto") rmd160hash = _generate_hash_function("RMD160", RIPEMD.new, origin="pycrypto") -except ImportError, e: +except ImportError as e: pass # Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks. @@ -86,7 +86,7 @@ try: def rmd160(): return hashlib.new('ripemd160') rmd160hash = _generate_hash_function("RMD160", rmd160, origin="hashlib") -except ImportError, e: +except ImportError as e: pass @@ -163,7 +163,7 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0): mysize = os.stat(filename)[stat.ST_SIZE] if mydict["size"] != mysize: return False,(_("Filesize does not match recorded size"), mysize, mydict["size"]) - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: raise portage.exception.FileNotFound(filename) return False, (str(e), None, None) @@ -244,7 +244,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0): raise portage.exception.DigestException(hashname + \ " hash function not available (needs dev-python/pycrypto)") myhash, mysize = hashfunc_map[hashname](myfilename) - except (OSError, IOError), e: + except (OSError, IOError) as e: if e.errno == errno.ENOENT: raise portage.exception.FileNotFound(myfilename) raise @@ -253,7 +253,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0): if prelink_tmpfile: try: os.unlink(prelink_tmpfile) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e diff --git a/pym/portage/cvstree.py b/pym/portage/cvstree.py index 0fd2a54c5..c3f5d3045 100644 --- a/pym/portage/cvstree.py +++ b/pym/portage/cvstree.py @@ -206,7 +206,7 @@ def getentries(mydir,recursive=0): mode='r', encoding=_encodings['content'], errors='strict') mylines=myfile.readlines() myfile.close() - except SystemExit, e: + except SystemExit as e: raise except: mylines=[] @@ -296,9 +296,9 @@ def getentries(mydir,recursive=0): print "stat done" del mystat - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: print "failed to stat",file print e return diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index d15953735..3c96a375a 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -309,7 +309,7 @@ class binarytree(object): os.unlink(mylink) try: os.rmdir(os.path.join(self.pkgdir, mycat)) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST): raise @@ -324,7 +324,7 @@ class binarytree(object): self._ensure_dir(os.path.dirname(full_path)) try: os.unlink(full_path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -408,7 +408,7 @@ class binarytree(object): src_path = os.path.join(self.pkgdir, mycat, myfile) try: mystat = os.lstat(src_path) - except OSError, e: + except OSError as e: mystat = None if mystat and stat.S_ISREG(mystat.st_mode): self._ensure_dir(os.path.join(self.pkgdir, "All")) @@ -674,7 +674,7 @@ class binarytree(object): pkgindex.read(f) finally: f.close() - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise local_timestamp = pkgindex.header.get("TIMESTAMP", None) @@ -702,7 +702,7 @@ class binarytree(object): pkgindex = rmt_idx finally: f.close() - except EnvironmentError, e: + except EnvironmentError as e: writemsg(_("\n\n!!! Error fetching binhost package" \ " info from '%s'\n") % base_url) writemsg("!!! %s\n\n" % str(e)) @@ -807,7 +807,7 @@ class binarytree(object): remote_metadata[k] = v.strip() self._remotepkgs[fullpkg] = remote_metadata #print " -- Injected" - except SystemExit, e: + except SystemExit as e: raise except: writemsg(_("!!! Failed to inject remote binary package: %s\n") % fullpkg, @@ -835,7 +835,7 @@ class binarytree(object): full_path = filename try: s = os.stat(full_path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -1001,7 +1001,7 @@ class binarytree(object): deps = use_reduce(deps, uselist=raw_use) deps = paren_normalize(deps) deps = paren_enclose(deps) - except portage.exception.InvalidDependString, e: + except portage.exception.InvalidDependString as e: writemsg("%s: %s\n" % (k, str(e)), noiselevel=-1) raise @@ -1181,8 +1181,8 @@ class binarytree(object): myslot = "" try: myslot = self.dbapi.aux_get(mycatpkg,["SLOT"])[0] - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: pass return myslot diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 4cc07362a..7d37f365f 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -388,7 +388,7 @@ class portdbapi(dbapi): try: ensure_dirs(self.depcachedir, gid=portage_gid, mode=dirmode, mask=modemask) - except PortageException, e: + except PortageException as e: pass def close_caches(self): @@ -789,7 +789,7 @@ class portdbapi(dbapi): mystat = None try: mystat = os.stat(file_path) - except OSError, e: + except OSError as e: pass if mystat is None: existing_size = 0 @@ -825,7 +825,7 @@ class portdbapi(dbapi): try: ok, reason = portage.checksum.verify_all( os.path.join(self.mysettings["DISTDIR"], x), mysums[x]) - except FileNotFound, e: + except FileNotFound as e: ok = False reason = _("File Not Found: '%s'") % (e,) if not ok: @@ -1098,7 +1098,7 @@ class portdbapi(dbapi): metadata.update(izip(aux_keys, self.aux_get(mycpv, aux_keys))) except KeyError: continue - except PortageException, e: + except PortageException as e: writemsg("!!! Error: aux_get('%s', %s)\n" % (mycpv, aux_keys), noiselevel=-1) writemsg("!!! %s\n" % (e,), noiselevel=-1) @@ -1213,8 +1213,8 @@ class portagetree(object): myslot = "" try: myslot = self.dbapi.aux_get(mycatpkg, ["SLOT"])[0] - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: pass return myslot diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 284d5ff1f..45686ee00 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -80,10 +80,10 @@ class PreservedLibsRegistry(object): self._data = pickle.load( open(_unicode_encode(self._filename, encoding=_encodings['fs'], errors='strict'), 'rb')) - except (ValueError, pickle.UnpicklingError), e: + except (ValueError, pickle.UnpicklingError) as e: writemsg_level(_("!!! Error loading '%s': %s\n") % \ (self._filename, e), level=logging.ERROR, noiselevel=-1) - except (EOFError, IOError), e: + except (EOFError, IOError) as e: if isinstance(e, EOFError) or e.errno == errno.ENOENT: pass elif e.errno == PermissionDenied.errno: @@ -104,7 +104,7 @@ class PreservedLibsRegistry(object): f = atomic_ofstream(self._filename, 'wb') pickle.dump(self._data, f, protocol=2) f.close() - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != PermissionDenied.errno: writemsg("!!! %s %s\n" % (e, self._filename), noiselevel=-1) else: @@ -335,7 +335,7 @@ class LinkageMap(object): for x in items) try: proc = subprocess.Popen(args, stdout=subprocess.PIPE) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise raise CommandNotFound(args[0]) @@ -907,7 +907,7 @@ class vardbapi(dbapi): try: os.rename(os.path.join(newpath, old_pf + ".ebuild"), os.path.join(newpath, new_pf + ".ebuild")) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -931,7 +931,7 @@ class vardbapi(dbapi): cat_dir = self.getpath(mysplit[0]) try: dir_list = os.listdir(cat_dir) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno == PermissionDenied.errno: raise PermissionDenied(cat_dir) del e @@ -972,7 +972,7 @@ class vardbapi(dbapi): try: return [x for x in os.listdir(p) \ if os.path.isdir(os.path.join(p, x))] - except EnvironmentError, e: + except EnvironmentError as e: if e.errno == PermissionDenied.errno: raise PermissionDenied(p) del e @@ -1097,7 +1097,7 @@ class vardbapi(dbapi): f.close() apply_secpass_permissions( self._aux_cache_filename, gid=portage_gid, mode=0644) - except (IOError, OSError), e: + except (IOError, OSError) as e: pass self._aux_cache["modified"] = set() @@ -1129,7 +1129,7 @@ class vardbapi(dbapi): aux_cache = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError), e: + except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e: if isinstance(e, pickle.UnpicklingError): writemsg(_("!!! Error loading '%s': %s\n") % \ (self._aux_cache_filename, str(e)), noiselevel=-1) @@ -1193,7 +1193,7 @@ class vardbapi(dbapi): mydir_stat = None try: mydir_stat = os.stat(mydir) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise raise KeyError(mycpv) @@ -1251,7 +1251,7 @@ class vardbapi(dbapi): if st is None: try: st = os.stat(mydir) - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError(mycpv) elif e.errno == PermissionDenied.errno: @@ -1343,7 +1343,7 @@ class vardbapi(dbapi): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace') - except EnvironmentError, e: + except EnvironmentError as e: new_vdb = not bool(self.cpv_all()) if not new_vdb: writemsg(_("!!! Unable to read COUNTER file: '%s'\n") % \ @@ -1356,7 +1356,7 @@ class vardbapi(dbapi): counter = long(cfile.readline().strip()) finally: cfile.close() - except (OverflowError, ValueError), e: + except (OverflowError, ValueError) as e: writemsg(_("!!! COUNTER file is corrupt: '%s'\n") % \ self._counter_path, noiselevel=-1) writemsg("!!! %s\n" % str(e), noiselevel=-1) @@ -1674,9 +1674,9 @@ class vartree(object): mys = myprovide.split("/") myprovides += [mys[0] + "/" + mys[1]] return myprovides - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: mydir = os.path.join(self.root, VDB_PATH, mycpv) writemsg(_("\nParse Error reading PROVIDE and USE in '%s'\n") % mydir, noiselevel=-1) @@ -1931,7 +1931,7 @@ class dblink(object): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace') - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -2089,7 +2089,7 @@ class dblink(object): try: doebuild_environment(myebuildpath, "prerm", self.myroot, self.settings, 0, 0, self.vartree.dbapi) - except UnsupportedAPIException, e: + except UnsupportedAPIException as e: # Sometimes this happens due to corruption of the EAPI file. writemsg(_("!!! FAILED prerm: %s\n") % \ os.path.join(self.dbdir, "EAPI"), noiselevel=-1) @@ -2249,7 +2249,7 @@ class dblink(object): if catdir_lock: try: os.rmdir(catdir) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST): raise @@ -2468,7 +2468,7 @@ class dblink(object): not self.isprotected(obj): try: unlink(obj, lstatobj) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno not in ignored_unlink_errnos: raise del e @@ -2499,7 +2499,7 @@ class dblink(object): try: unlink(obj, lstatobj) show_unmerge("<<<", "", file_type, obj) - except (OSError, IOError),e: + except (OSError, IOError) as e: if e.errno not in ignored_unlink_errnos: raise del e @@ -2511,7 +2511,7 @@ class dblink(object): mymd5 = None try: mymd5 = perf_md5(obj, calc_prelink=1) - except FileNotFound, e: + except FileNotFound as e: # the file has disappeared between now and our stat call show_unmerge("---", unmerge_desc["!obj"], file_type, obj) continue @@ -2523,7 +2523,7 @@ class dblink(object): continue try: unlink(obj, lstatobj) - except (OSError, IOError), e: + except (OSError, IOError) as e: if e.errno not in ignored_unlink_errnos: raise del e @@ -2558,7 +2558,7 @@ class dblink(object): # Restore the parent flags we saved before unlinking bsd_chflags.chflags(parent_name, pflags) show_unmerge("<<<", "", "dir", obj) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno not in ignored_rmdir_errnos: raise if e.errno != errno.ENOENT: @@ -2678,7 +2678,7 @@ class dblink(object): parent_path = os_filename_arg.path.dirname(destfile) try: parent_stat = os_filename_arg.stat(parent_path) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -2742,7 +2742,7 @@ class dblink(object): return try: self.vartree.dbapi.linkmap.rebuild(**kwargs) - except CommandNotFound, e: + except CommandNotFound as e: self._linkmap_broken = True self._display_merge(_("!!! Disabling preserve-libs " \ "due to error: Command Not Found: %s\n") % (e,), @@ -3038,7 +3038,7 @@ class dblink(object): obj_type = _("obj") try: os.unlink(obj) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -3101,7 +3101,7 @@ class dblink(object): os.path.join(destroot, f.lstrip(os.path.sep))) try: dest_lstat = os.lstat(dest_path) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno == errno.ENOENT: del e continue @@ -3116,7 +3116,7 @@ class dblink(object): try: dest_lstat = os.lstat(parent_path) break - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOTDIR: raise del e @@ -3185,7 +3185,7 @@ class dblink(object): path = os.path.join(root, f.lstrip(os.sep)) try: st = os.lstat(path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ENOTDIR): raise del e @@ -3236,7 +3236,7 @@ class dblink(object): try: s = os.lstat(path) - except OSError, e: + except OSError as e: if e.errno not in (errno.ENOENT, errno.ENOTDIR): raise del e @@ -3360,7 +3360,7 @@ class dblink(object): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace').readline().strip() - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -3669,7 +3669,7 @@ class dblink(object): try: os.unlink(os.path.join( os.path.dirname(normalize_path(srcroot)), ".installed")) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -4006,7 +4006,7 @@ class dblink(object): try: mydstat = os.lstat(mydest) mydmode = mydstat.st_mode - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e @@ -4420,7 +4420,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): curval += 1 try: lst = os.lstat(path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py index 49e53c2ee..e9b220a39 100644 --- a/pym/portage/dispatch_conf.py +++ b/pym/portage/dispatch_conf.py @@ -64,7 +64,7 @@ def rcs_archive(archive, curconf, newconf, mrgconf): try: shutil.copy2(curconf, archive) - except(IOError, os.error), why: + except(IOError, os.error) as why: print >> sys.stderr, _('dispatch-conf: Error copying %(curconf)s to %(archive)s: %(reason)s; fatal') % \ {"curconf": curconf, "archive": archive, "reason": str(why)} if os.path.exists(archive + ',v'): @@ -80,7 +80,7 @@ def rcs_archive(archive, curconf, newconf, mrgconf): try: shutil.copy2(newconf, archive) - except(IOError, os.error), why: + except(IOError, os.error) as why: print >> sys.stderr, _('dispatch-conf: Error copying %(newconf)s to %(archive)s: %(reason)s; fatal') % \ {"newconf": newconf, "archive": archive, "reason": str(why)} @@ -123,7 +123,7 @@ def file_archive(archive, curconf, newconf, mrgconf): try: shutil.copy2(curconf, archive) - except(IOError, os.error), why: + except(IOError, os.error) as why: print >> sys.stderr, _('dispatch-conf: Error copying %(curconf)s to %(archive)s: %(reason)s; fatal') % \ {"curconf": curconf, "archive": archive, "reason": str(why)} @@ -131,7 +131,7 @@ def file_archive(archive, curconf, newconf, mrgconf): # Save off new config file in the archive dir with .dist.new suffix try: shutil.copy2(newconf, archive + '.dist.new') - except(IOError, os.error), why: + except(IOError, os.error) as why: print >> sys.stderr, _('dispatch-conf: Error copying %(newconf)s to %(archive)s: %(reason)s; fatal') % \ {"newconf": newconf, "archive": archive + '.dist.new', "reason": str(why)} diff --git a/pym/portage/eclass_cache.py b/pym/portage/eclass_cache.py index 3f86a6d69..e0b9383c5 100644 --- a/pym/portage/eclass_cache.py +++ b/pym/portage/eclass_cache.py @@ -80,7 +80,7 @@ class cache(object): for x in [normalize_path(os.path.join(y,"eclass")) for y in self.porttrees]: try: eclass_filenames = os.listdir(x) - except OSError, e: + except OSError as e: if e.errno in ignored_listdir_errnos: del e continue diff --git a/pym/portage/elog/__init__.py b/pym/portage/elog/__init__.py index 7bd567cee..c689d821d 100644 --- a/pym/portage/elog/__init__.py +++ b/pym/portage/elog/__init__.py @@ -168,10 +168,10 @@ def elog_process(cpv, mysettings, phasefilter=None): if hasattr(m, "finalize") and not m.finalize in _elog_atexit_handlers: _elog_atexit_handlers.append(m.finalize) atexit_register(m.finalize) - except (ImportError, AttributeError), e: + except (ImportError, AttributeError) as e: writemsg(_("!!! Error while importing logging modules " "while loading \"mod_%s\":\n") % str(s)) writemsg("%s\n" % str(e), noiselevel=-1) - except PortageException, e: + except PortageException as e: writemsg("%s\n" % str(e), noiselevel=-1) diff --git a/pym/portage/elog/mod_mail.py b/pym/portage/elog/mod_mail.py index 841986b96..ac96f3b20 100644 --- a/pym/portage/elog/mod_mail.py +++ b/pym/portage/elog/mod_mail.py @@ -38,7 +38,7 @@ def process(mysettings, key, logentries, fulltext): mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, fulltext) try: portage.mail.send_mail(mysettings, mymessage) - except PortageException, e: + except PortageException as e: writemsg("%s\n" % str(e), noiselevel=-1) return diff --git a/pym/portage/elog/mod_mail_summary.py b/pym/portage/elog/mod_mail_summary.py index e642dc044..4380146d2 100644 --- a/pym/portage/elog/mod_mail_summary.py +++ b/pym/portage/elog/mod_mail_summary.py @@ -73,7 +73,7 @@ def _finalize(mysettings, items): portage.mail.send_mail(mysettings, mymessage) finally: signal.alarm(0) - except PortageException, e: + except PortageException as e: writemsg("%s\n" % str(e), noiselevel=-1) return diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py index 5ec3a066f..60e0e1b11 100644 --- a/pym/portage/env/loaders.py +++ b/pym/portage/env/loaders.py @@ -153,7 +153,7 @@ class FileLoader(DataLoader): f = codecs.open(_unicode_encode(fn, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace') - except EnvironmentError, e: + except EnvironmentError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise del e diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index dfe2fad59..adab28fab 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -26,12 +26,12 @@ except ImportError: try: import ftplib -except ImportError, e: +except ImportError as e: sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT FTPLIB: ")+str(e)+"\n") try: import httplib -except ImportError, e: +except ImportError as e: sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT HTTPLIB: ")+str(e)+"\n") def make_metadata_dict(data): @@ -207,7 +207,7 @@ def make_ftp_request(conn, address, rest=None, dest=None): return mydata,not (fsize==data_size),"" - except ValueError, e: + except ValueError as e: return None,int(str(e)[:4]),str(e) @@ -223,9 +223,9 @@ def make_http_request(conn, address, params={}, headers={}, dest=None): if (rc != 0): conn,ignore,ignore,ignore,ignore = create_conn(address) conn.request("GET", address, params, headers) - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: return None,None,"Server request failed: "+str(e) response = conn.getresponse() rc = response.status @@ -481,7 +481,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= try: conn, protocol, address, params, headers = create_conn(baseurl, conn) - except socket.error, e: + except socket.error as e: # ftplib.FTP(host) can raise errors like this: # socket.error: (111, 'Connection refused') sys.stderr.write("!!! %s\n" % (e,)) @@ -522,7 +522,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= import portage.exception try: filelist = dir_get_list(baseurl, conn) - except portage.exception.PortageException, e: + except portage.exception.PortageException as e: sys.stderr.write(_("!!! Error connecting to '%s'.\n") % baseurl) sys.stderr.write("!!! %s\n" % str(e)) del e @@ -547,7 +547,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= if mytempfile.tell() > len(data): mytempfile.seek(0) data = mytempfile.read() - except ValueError, e: + except ValueError as e: sys.stderr.write("--- "+str(e)+"\n") if trynum < 3: sys.stderr.write(_("Retrying...\n")) @@ -562,9 +562,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= mytempfile.seek(0) gzindex = gzip.GzipFile(mfile[:-3],'rb',9,mytempfile) data = gzindex.read() - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: mytempfile.close() sys.stderr.write(_("!!! Failed to use gzip: ")+str(e)+"\n") sys.stderr.flush() @@ -578,9 +578,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= out.write(_("Pickle loaded.\n")) out.flush() break - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: sys.stderr.write(_("!!! Failed to read data from index: ")+str(mfile)+"\n") sys.stderr.write("!!! "+str(e)+"\n") sys.stderr.flush() @@ -589,9 +589,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= encoding=_encodings['fs'], errors='strict'), 'wb') pickle.dump(metadata, metadatafile, protocol=2) metadatafile.close() - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: sys.stderr.write(_("!!! Failed to write binary metadata to disk!\n")) sys.stderr.write("!!! "+str(e)+"\n") sys.stderr.flush() @@ -687,9 +687,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= encoding=_encodings['fs'], errors='strict'), 'wb') pickle.dump(metadata[baseurl]["data"], metadatafile, protocol=2) metadatafile.close() - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: sys.stderr.write(_("!!! Failed to write binary metadata to disk!\n")) sys.stderr.write("!!! "+str(e)+"\n") sys.stderr.flush() diff --git a/pym/portage/locks.py b/pym/portage/locks.py index adf82af81..f2147c5e1 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -65,7 +65,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, try: try: myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR, 0660) - except OSError, e: + except OSError as e: func_call = "open('%s')" % lockfilename if e.errno == OperationNotPermitted.errno: raise OperationNotPermitted(func_call) @@ -78,7 +78,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, try: if os.stat(lockfilename).st_gid != portage_gid: os.chown(lockfilename, -1, portage_gid) - except OSError, e: + except OSError as e: if e.errno in (errno.ENOENT, errno.ESTALE): return lockfile(mypath, wantnewlockfile=wantnewlockfile, @@ -103,7 +103,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, locking_method = fcntl.lockf try: fcntl.lockf(myfd,fcntl.LOCK_EX|fcntl.LOCK_NB) - except IOError, e: + except IOError as e: if "errno" not in dir(e): raise if e.errno in (errno.EACCES, errno.EAGAIN): @@ -123,7 +123,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, # try for the exclusive lock now. try: fcntl.lockf(myfd, fcntl.LOCK_EX) - except EnvironmentError, e: + except EnvironmentError as e: out.eend(1, str(e)) raise out.eend(os.EX_OK) @@ -168,7 +168,7 @@ def _fstat_nlink(fd): """ try: return os.fstat(fd).st_nlink - except EnvironmentError, e: + except EnvironmentError as e: if e.errno in (errno.ENOENT, errno.ESTALE): # Some filesystems such as CIFS return # ENOENT which means st_nlink == 0. @@ -229,7 +229,7 @@ def unlockfile(mytuple): writemsg(_("lockfile does not exist '%s'\n") % lockfilename, 1) os.close(myfd) return False - except Exception, e: + except Exception as e: writemsg(_("Failed to get lock... someone took it.\n"), 1) writemsg(str(e)+"\n",1) diff --git a/pym/portage/mail.py b/pym/portage/mail.py index 260455739..a8b384969 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -126,9 +126,9 @@ def send_mail(mysettings, message): myconn.login(mymailuser, mymailpasswd) myconn.sendmail(myfrom, myrecipient, message.as_string()) myconn.quit() - except smtplib.SMTPException, e: + except smtplib.SMTPException as e: raise portage.exception.PortageException(_("!!! An error occured while trying to send logmail:\n")+str(e)) - except socket.error, e: + except socket.error as e: raise portage.exception.PortageException(_("!!! A network error occured while trying to send logmail:\n%s\nSure you configured PORTAGE_ELOG_MAILURI correctly?") % str(e)) return diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 25893d759..e60850e5f 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -151,7 +151,7 @@ class Manifest(object): self._parseDigests(fd, myhashdict=myhashdict, **kwargs) fd.close() return myhashdict - except (OSError, IOError), e: + except (OSError, IOError) as e: if e.errno == errno.ENOENT: raise FileNotFound(file_path) else: @@ -243,7 +243,7 @@ class Manifest(object): if oldentries[i] != myentries[i]: update_manifest = True break - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno == errno.ENOENT: pass else: @@ -253,7 +253,7 @@ class Manifest(object): "".join("%s\n" % str(myentry) for myentry in myentries)) if sign: self.sign() - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno == errno.EACCES: raise PermissionDenied(str(e)) raise @@ -435,7 +435,7 @@ class Manifest(object): if not ok: raise DigestException(tuple([self._getAbsname(ftype, fname)]+list(reason))) return ok, reason - except FileNotFound, e: + except FileNotFound as e: if not ignoreMissing: raise return False, _("File Not Found: '%s'") % str(e) diff --git a/pym/portage/output.py b/pym/portage/output.py index baf818f58..06073df71 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -218,7 +218,7 @@ def _parse_color_map(config_root='/', onerror=None): _styles[k] = tuple(code_list) elif k in codes: codes[k] = "".join(code_list) - except (IOError, OSError), e: + except (IOError, OSError) as e: if e.errno == errno.ENOENT: raise FileNotFound(myfile) elif e.errno == errno.EACCES: @@ -745,10 +745,10 @@ def _init(config_root='/'): onerror=lambda e: writemsg("%s\n" % str(e), noiselevel=-1)) except FileNotFound: pass - except PermissionDenied, e: + except PermissionDenied as e: writemsg(_("Permission denied: '%s'\n") % str(e), noiselevel=-1) del e - except PortageException, e: + except PortageException as e: writemsg("%s\n" % str(e), noiselevel=-1) del e diff --git a/pym/portage/process.py b/pym/portage/process.py index 1822a3082..9698743f8 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -239,7 +239,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, try: _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, pre_exec) - except Exception, e: + except Exception as e: # We need to catch _any_ exception so that it doesn't # propogate out of this function and cause exiting # with anything other than os._exit() diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py index f52c7fa1a..3b8084ab3 100644 --- a/pym/portage/sets/__init__.py +++ b/pym/portage/sets/__init__.py @@ -97,7 +97,7 @@ class SetConfig(object): newsets = {} try: newsets = setclass.multiBuilder(optdict, self.settings, self.trees) - except SetConfigError, e: + except SetConfigError as e: self.errors.append(_("Configuration error in section '%s': %s") % (sname, str(e))) continue for x in newsets: @@ -126,7 +126,7 @@ class SetConfig(object): if parser.has_option(sname, "world-candidate") and \ not parser.getboolean(sname, "world-candidate"): self.psets[setname].world_candidate = False - except SetConfigError, e: + except SetConfigError as e: self.errors.append(_("Configuration error in section '%s': %s") % (sname, str(e))) continue else: diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 5cd6c6ba1..06ebcadfd 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -299,7 +299,7 @@ class AgeSet(EverythingSet): raise SetConfigError(_("invalid 'mode' value %s (use either 'newer' or 'older')") % mode) try: age = int(options.get("age", "7")) - except ValueError, e: + except ValueError as e: raise SetConfigError(_("value of option 'age' is not an integer")) return AgeSet(vardb=trees["vartree"].dbapi, mode=mode, age=age) diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index 13c8508e0..b052a444d 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -77,7 +77,7 @@ class StaticFileSet(EditablePackageSet): for fname in errors: for e in errors[fname]: self.errors.append(fname+": "+e) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -249,7 +249,7 @@ class WorldSet(EditablePackageSet): for fname in errors: for e in errors[fname]: self.errors.append(fname+": "+e) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e @@ -269,7 +269,7 @@ class WorldSet(EditablePackageSet): for fname in errors: for e in errors[fname]: self.errors.append(fname+": "+e) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e diff --git a/pym/portage/tests/ebuild/test_spawn.py b/pym/portage/tests/ebuild/test_spawn.py index 97a5f42d0..8dfbddd78 100644 --- a/pym/portage/tests/ebuild/test_spawn.py +++ b/pym/portage/tests/ebuild/test_spawn.py @@ -46,7 +46,7 @@ class SpawnTestCase(TestCase): if logfile: try: os.unlink(logfile) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.ENOENT: raise del e diff --git a/pym/portage/update.py b/pym/portage/update.py index 251da88a4..0941ba06b 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -94,7 +94,7 @@ def grab_updates(updpath, prev_mtimes=None): given then only updates with differing mtimes are considered.""" try: mylist = os.listdir(updpath) - except OSError, oe: + except OSError as oe: if oe.errno == errno.ENOENT: raise DirectoryNotFound(updpath) raise @@ -256,7 +256,7 @@ def update_config_files(config_root, protect, protect_mask, update_iter): updating_file = new_protect_filename(updating_file) try: write_atomic(updating_file, "".join(file_contents[x])) - except PortageException, e: + except PortageException as e: writemsg("\n!!! %s\n" % str(e), noiselevel=-1) writemsg(_("!!! An error occured while updating a config file:") + \ " '%s'\n" % updating_file, noiselevel=-1) diff --git a/pym/portage/util.py b/pym/portage/util.py index 04a799466..5cc3c5e57 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -347,7 +347,7 @@ def grablines(myfilename,recursive=0): mode='r', encoding=_encodings['content'], errors='replace') mylines = myfile.readlines() myfile.close() - except IOError, e: + except IOError as e: if e.errno == PermissionDenied.errno: raise PermissionDenied(myfilename) pass @@ -389,7 +389,7 @@ class _tolerant_shlex(shlex.shlex): def sourcehook(self, newfile): try: return shlex.shlex.sourcehook(self, newfile) - except EnvironmentError, e: + except EnvironmentError as e: writemsg(_("!!! Parse error in '%s': source command failed: %s\n") % \ (self.infile, str(e)), noiselevel=-1) return (newfile, StringIO()) @@ -420,7 +420,7 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): encoding=_encodings['content'], errors='replace').read() if content and content[-1] != '\n': content += '\n' - except IOError, e: + except IOError as e: if e.errno == PermissionDenied.errno: raise PermissionDenied(mycfg) if e.errno != errno.ENOENT: @@ -494,9 +494,9 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): expand_map[key] = mykeys[key] else: mykeys[key] = val - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: raise portage.exception.ParseError(str(e)+" in "+mycfg) return mykeys @@ -626,9 +626,9 @@ def pickle_read(filename,default=None,debug=0): myf.close() del mypickle,myf writemsg(_("pickle_read(): Loaded pickle. '")+filename+"'\n",1) - except SystemExit, e: + except SystemExit as e: raise - except Exception, e: + except Exception as e: writemsg(_("!!! Failed to load pickle: ")+str(e)+"\n",1) data = default return data @@ -736,7 +736,7 @@ def apply_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1, stat_cached = os.stat(filename) else: stat_cached = os.lstat(filename) - except OSError, oe: + except OSError as oe: func_call = "stat('%s')" % filename if oe.errno == errno.EPERM: raise OperationNotPermitted(func_call) @@ -756,7 +756,7 @@ def apply_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1, import portage.data portage.data.lchown(filename, uid, gid) modified = True - except OSError, oe: + except OSError as oe: func_call = "chown('%s', %i, %i)" % (filename, uid, gid) if oe.errno == errno.EPERM: raise OperationNotPermitted(func_call) @@ -809,7 +809,7 @@ def apply_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1, try: os.chmod(filename, new_mode) modified = True - except OSError, oe: + except OSError as oe: func_call = "chmod('%s', %s)" % (filename, oct(new_mode)) if oe.errno == errno.EPERM: raise OperationNotPermitted(func_call) @@ -855,7 +855,7 @@ def apply_recursive_permissions(top, uid=-1, gid=-1, uid=uid, gid=gid, mode=dirmode, mask=dirmask) if not applied: all_applied = False - except PortageException, e: + except PortageException as e: all_applied = False onerror(e) @@ -865,7 +865,7 @@ def apply_recursive_permissions(top, uid=-1, gid=-1, uid=uid, gid=gid, mode=filemode, mask=filemask) if not applied: all_applied = False - except PortageException, e: + except PortageException as e: # Ignore InvalidLocation exceptions such as FileNotFound # and DirectoryNotFound since sometimes things disappear, # like when adjusting permissions on DISTCC_DIR. @@ -890,7 +890,7 @@ def apply_secpass_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1, stat_cached = os.stat(filename) else: stat_cached = os.lstat(filename) - except OSError, oe: + except OSError as oe: func_call = "stat('%s')" % filename if oe.errno == errno.EPERM: raise OperationNotPermitted(func_call) @@ -948,7 +948,7 @@ class atomic_ofstream(ObjectProxy): encoding=_encodings['fs'], errors='strict'), mode=mode, **kargs)) return - except IOError, e: + except IOError as e: if canonical_path == filename: raise writemsg(_("!!! Failed to open file: '%s'\n") % tmp_name, @@ -986,7 +986,7 @@ class atomic_ofstream(ObjectProxy): pass except FileNotFound: pass - except OSError, oe: # from the above os.stat call + except OSError as oe: # from the above os.stat call if oe.errno in (errno.ENOENT, errno.EPERM): pass else: @@ -997,7 +997,7 @@ class atomic_ofstream(ObjectProxy): # even if an exception is raised. try: os.unlink(f.name) - except OSError, oe: + except OSError as oe: pass def abort(self): @@ -1025,7 +1025,7 @@ def write_atomic(file_path, content, **kwargs): f = atomic_ofstream(file_path, **kwargs) f.write(content) f.close() - except (IOError, OSError), e: + except (IOError, OSError) as e: if f: f.abort() func_call = "write_atomic('%s')" % file_path @@ -1050,7 +1050,7 @@ def ensure_dirs(dir_path, *args, **kwargs): try: os.makedirs(dir_path) created_dir = True - except OSError, oe: + except OSError as oe: func_call = "makedirs('%s')" % dir_path if oe.errno in (errno.EEXIST, errno.EISDIR): pass diff --git a/pym/portage/xpak.py b/pym/portage/xpak.py index 15a432f51..54d2eb880 100644 --- a/pym/portage/xpak.py +++ b/pym/portage/xpak.py @@ -232,7 +232,7 @@ def xpand(myid,mydest): mydata=myid[1] try: origdir=os.getcwd() - except SystemExit, e: + except SystemExit as e: raise except: os.chdir("/") @@ -313,7 +313,7 @@ class tbz2(object): # thus the above sanity check. try: shutil.rmtree(datadir) - except OSError, oe: + except OSError as oe: if oe.errno == errno.ENOENT: pass else: @@ -359,7 +359,7 @@ class tbz2(object): self.datapos=a.tell() a.close() return 2 - except SystemExit, e: + except SystemExit as e: raise except: return 0 @@ -397,7 +397,7 @@ class tbz2(object): return 0 try: origdir=os.getcwd() - except SystemExit, e: + except SystemExit as e: raise except: os.chdir("/") diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index c3665d9d8..18480294c 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -117,7 +117,7 @@ def parse_metadata_use(mylines, uselist=None): uselist = [] try: metadatadom = minidom.parse(mylines) - except ExpatError, e: + except ExpatError as e: raise exception.ParseError("metadata.xml: %s" % (e,)) try: @@ -289,7 +289,7 @@ def get_commit_message_with_editor(editor, message=None): encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace' ).readlines() - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise del e -- 2.26.2