From 7cb8fb941f09d1ac646be334745f90e16ebd46eb Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sun, 20 Sep 2009 10:57:44 +0000 Subject: 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 +++++++++++++++--------------- 14 files changed, 46 insertions(+), 46 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3-1-g7c22