python-modernize -f lib2to3.fixes.fix_except

This commit is contained in:
Tomas Kopecek 2017-05-03 11:33:22 +02:00
parent b1da150c01
commit 1220008f8f
14 changed files with 66 additions and 66 deletions

View file

@ -1976,7 +1976,7 @@ class ChainMavenTask(MultiPlatformTask):
del todo[package] del todo[package]
try: try:
results = self.wait(running.keys()) results = self.wait(running.keys())
except (six.moves.xmlrpc_client.Fault, koji.GenericError), e: except (six.moves.xmlrpc_client.Fault, koji.GenericError) as e:
# One task has failed, wait for the rest to complete before the # One task has failed, wait for the rest to complete before the
# chainmaven task fails. self.wait(all=True) should thrown an exception. # chainmaven task fails. self.wait(all=True) should thrown an exception.
self.wait(all=True) self.wait(all=True)
@ -2113,7 +2113,7 @@ class TagBuildTask(BaseTaskHandler):
#XXX - add more post tests #XXX - add more post tests
self.session.host.tagBuild(self.id,tag_id,build_id,force=force,fromtag=fromtag) self.session.host.tagBuild(self.id,tag_id,build_id,force=force,fromtag=fromtag)
self.session.host.tagNotification(True, tag_id, fromtag, build_id, user_id, ignore_success) self.session.host.tagNotification(True, tag_id, fromtag, build_id, user_id, ignore_success)
except Exception, e: except Exception as e:
exctype, value = sys.exc_info()[:2] exctype, value = sys.exc_info()[:2]
self.session.host.tagNotification(False, tag_id, fromtag, build_id, user_id, ignore_success, "%s: %s" % (exctype, value)) self.session.host.tagNotification(False, tag_id, fromtag, build_id, user_id, ignore_success, "%s: %s" % (exctype, value))
raise e raise e
@ -2676,10 +2676,10 @@ class ImageTask(BaseTaskHandler):
self.ks = ksparser.KickstartParser(version) self.ks = ksparser.KickstartParser(version)
try: try:
self.ks.readKickstart(kspath) self.ks.readKickstart(kspath)
except IOError, e: except IOError as e:
raise koji.LiveCDError("Failed to read kickstart file " raise koji.LiveCDError("Failed to read kickstart file "
"'%s' : %s" % (kspath, e)) "'%s' : %s" % (kspath, e))
except kserrors.KickstartError, e: except kserrors.KickstartError as e:
raise koji.LiveCDError("Failed to parse kickstart file " raise koji.LiveCDError("Failed to parse kickstart file "
"'%s' : %s" % (kspath, e)) "'%s' : %s" % (kspath, e))
@ -3291,10 +3291,10 @@ class OzImageTask(BaseTaskHandler):
self.logger.debug('attempting to read kickstart: %s' % kspath) self.logger.debug('attempting to read kickstart: %s' % kspath)
try: try:
ks.readKickstart(kspath) ks.readKickstart(kspath)
except IOError, e: except IOError as e:
raise koji.BuildError("Failed to read kickstart file " raise koji.BuildError("Failed to read kickstart file "
"'%s' : %s" % (kspath, e)) "'%s' : %s" % (kspath, e))
except kserrors.KickstartError, e: except kserrors.KickstartError as e:
raise koji.BuildError("Failed to parse kickstart file " raise koji.BuildError("Failed to parse kickstart file "
"'%s' : %s" % (kspath, e)) "'%s' : %s" % (kspath, e))
return ks return ks
@ -4228,7 +4228,7 @@ class BuildIndirectionImageTask(OzImageTask):
base_factory_image = _nvr_to_image(opts['base_image_build'], opts['arch']) base_factory_image = _nvr_to_image(opts['base_image_build'], opts['arch'])
else: else:
base_factory_image = _task_to_image(int(opts['base_image_task'])) base_factory_image = _task_to_image(int(opts['base_image_task']))
except Exception, e: except Exception as e:
self.logger.exception(e) self.logger.exception(e)
raise raise
@ -4290,7 +4290,7 @@ class BuildIndirectionImageTask(OzImageTask):
image_id=base_factory_image.identifier, image_id=base_factory_image.identifier,
parameters=params) parameters=params)
target.target_thread.join() target.target_thread.join()
except Exception, e: except Exception as e:
self.logger.debug("Exception encountered during target build") self.logger.debug("Exception encountered during target build")
self.logger.exception(e) self.logger.exception(e)
finally: finally:
@ -5633,7 +5633,7 @@ if __name__ == "__main__":
# authenticate using SSL client certificates # authenticate using SSL client certificates
session.ssl_login(options.cert, None, session.ssl_login(options.cert, None,
options.serverca) options.serverca)
except koji.AuthError, e: except koji.AuthError as e:
quit("Error: Unable to log in: %s" % e) quit("Error: Unable to log in: %s" % e)
except six.moves.xmlrpc_client.ProtocolError: except six.moves.xmlrpc_client.ProtocolError:
quit("Error: Unable to connect to server %s" % (options.server)) quit("Error: Unable to connect to server %s" % (options.server))
@ -5653,9 +5653,9 @@ if __name__ == "__main__":
session.krb_login(principal=krb_principal, session.krb_login(principal=krb_principal,
keytab=options.keytab, keytab=options.keytab,
ccache=options.ccache) ccache=options.ccache)
except krbV.Krb5Error, e: except krbV.Krb5Error as e:
quit("Kerberos authentication failed: '%s' (%s)" % (e.args[1], e.args[0])) quit("Kerberos authentication failed: '%s' (%s)" % (e.args[1], e.args[0]))
except socket.error, e: except socket.error as e:
quit("Could not connect to Kerberos authentication service: '%s'" % e.args[1]) quit("Could not connect to Kerberos authentication service: '%s'" % e.args[1])
else: else:
quit("No username/password supplied and Kerberos missing or not configured") quit("No username/password supplied and Kerberos missing or not configured")

View file

@ -240,7 +240,7 @@ def get_options():
# load local config # load local config
try: try:
result = koji.read_config(options.profile, user_config=options.configFile) result = koji.read_config(options.profile, user_config=options.configFile)
except koji.ConfigurationError, e: except koji.ConfigurationError as e:
parser.error(e.args[0]) parser.error(e.args[0])
assert False # pragma: no cover assert False # pragma: no cover
@ -342,7 +342,7 @@ class TaskWatcher(object):
error = None error = None
try: try:
result = self.session.getTaskResult(self.id) result = self.session.getTaskResult(self.id)
except (six.moves.xmlrpc_client.Fault,koji.GenericError),e: except (six.moves.xmlrpc_client.Fault,koji.GenericError) as e:
error = e error = e
if error is None: if error is None:
# print("%s: complete" % self.str()) # print("%s: complete" % self.str())
@ -550,7 +550,7 @@ def list_task_output_all_volumes(session, task_id):
"""List task output with all volumes, or fake it""" """List task output with all volumes, or fake it"""
try: try:
return session.listTaskOutput(task_id, all_volumes=True) return session.listTaskOutput(task_id, all_volumes=True)
except koji.GenericError, e: except koji.GenericError as e:
if 'got an unexpected keyword argument' not in str(e): if 'got an unexpected keyword argument' not in str(e):
raise raise
# otherwise leave off the option and fake it # otherwise leave off the option and fake it
@ -944,7 +944,7 @@ def _progress_callback(uploaded, total, piece, time, total_time):
def _running_in_bg(): def _running_in_bg():
try: try:
return (not os.isatty(0)) or (os.getpgrp() != os.tcgetpgrp(0)) return (not os.isatty(0)) or (os.getpgrp() != os.tcgetpgrp(0))
except OSError, e: except OSError as e:
return True return True
def handle_build(options, session, args): def handle_build(options, session, args):
@ -1167,7 +1167,7 @@ def handle_maven_build(options, session, args):
try: try:
params = koji.util.parse_maven_param(build_opts.inis, scratch=build_opts.scratch, params = koji.util.parse_maven_param(build_opts.inis, scratch=build_opts.scratch,
section=build_opts.section) section=build_opts.section)
except ValueError, e: except ValueError as e:
parser.error(e.args[0]) parser.error(e.args[0])
opts = params.values()[0] opts = params.values()[0]
if opts.pop('type', 'maven') != 'maven': if opts.pop('type', 'maven') != 'maven':
@ -1226,7 +1226,7 @@ def handle_wrapper_rpm(options, session, args):
try: try:
params = koji.util.parse_maven_param(build_opts.inis, scratch=build_opts.scratch, params = koji.util.parse_maven_param(build_opts.inis, scratch=build_opts.scratch,
section=build_opts.section) section=build_opts.section)
except ValueError, e: except ValueError as e:
parser.error(e.args[0]) parser.error(e.args[0])
opts = params.values()[0] opts = params.values()[0]
if opts.get('type') != 'wrapper': if opts.get('type') != 'wrapper':
@ -1300,7 +1300,7 @@ def handle_maven_chain(options, session, args):
opts[key] = val opts[key] = val
try: try:
builds = koji.util.parse_maven_chain(args[1:], scratch=opts.get('scratch')) builds = koji.util.parse_maven_chain(args[1:], scratch=opts.get('scratch'))
except ValueError, e: except ValueError as e:
parser.error(e.args[0]) parser.error(e.args[0])
priority = None priority = None
if build_opts.background: if build_opts.background:
@ -1675,7 +1675,7 @@ def handle_import(options, session, args):
sys.stdout.flush() sys.stdout.flush()
try: try:
session.importRPM(serverdir, os.path.basename(path)) session.importRPM(serverdir, os.path.basename(path))
except koji.GenericError, e: except koji.GenericError as e:
print(_("\nError importing: %s" % str(e).splitlines()[-1])) print(_("\nError importing: %s" % str(e).splitlines()[-1]))
sys.stdout.flush() sys.stdout.flush()
else: else:
@ -2284,7 +2284,7 @@ def handle_prune_signed_copies(options, session, args):
print("Unlinking: %s" % signedpath) print("Unlinking: %s" % signedpath)
try: try:
os.unlink(signedpath) os.unlink(signedpath)
except OSError, e: except OSError as e:
print("Error removing %s: %s" % (signedpath, e)) print("Error removing %s: %s" % (signedpath, e))
print("This script needs write access to %s" % koji.BASEDIR) print("This script needs write access to %s" % koji.BASEDIR)
continue continue
@ -2304,7 +2304,7 @@ def handle_prune_signed_copies(options, session, args):
print("Removing dir: %s" % dir) print("Removing dir: %s" % dir)
try: try:
os.rmdir(dir) os.rmdir(dir)
except OSError, e: except OSError as e:
print("Error removing %s: %s" % (signedpath, e)) print("Error removing %s: %s" % (signedpath, e))
if len(sigdirs) == 1: if len(sigdirs) == 1:
dir = sigdirs.keys()[0] dir = sigdirs.keys()[0]
@ -2315,7 +2315,7 @@ def handle_prune_signed_copies(options, session, args):
print("Removing dir: %s" % dir) print("Removing dir: %s" % dir)
try: try:
os.rmdir(dir) os.rmdir(dir)
except OSError, e: except OSError as e:
print("Error removing %s: %s" % (signedpath, e)) print("Error removing %s: %s" % (signedpath, e))
elif len(sigdirs) > 1: elif len(sigdirs) > 1:
print("Warning: more than one signature dir for %s: %r" % (sigkey, sigdirs)) print("Warning: more than one signature dir for %s: %r" % (sigkey, sigdirs))
@ -2549,7 +2549,7 @@ def handle_import_in_place(options, session, args):
sys.stdout.write(_("importing %s... ") % nvr) sys.stdout.write(_("importing %s... ") % nvr)
try: try:
session.importBuildInPlace(data) session.importBuildInPlace(data)
except koji.GenericError, e: except koji.GenericError as e:
print(_("\nError importing: %s" % str(e).splitlines()[-1])) print(_("\nError importing: %s" % str(e).splitlines()[-1]))
sys.stdout.flush() sys.stdout.flush()
else: else:
@ -6735,7 +6735,7 @@ def anon_handle_download_build(options, session, args):
# We want the latest build, not a specific build # We want the latest build, not a specific build
try: try:
builds = session.listTagged(suboptions.latestfrom, latest=True, package=build, type=suboptions.type) builds = session.listTagged(suboptions.latestfrom, latest=True, package=build, type=suboptions.type)
except koji.GenericError, data: except koji.GenericError as data:
print("Error finding latest build: %s" % data) print("Error finding latest build: %s" % data)
return 1 return 1
if not builds: if not builds:
@ -7382,7 +7382,7 @@ def handle_runroot(options, session, args):
kwargs['new_chroot'] = True kwargs['new_chroot'] = True
task_id = session.runroot(tag, arch, command, **kwargs) task_id = session.runroot(tag, arch, command, **kwargs)
except koji.GenericError, e: except koji.GenericError as e:
if 'Invalid method' in str(e): if 'Invalid method' in str(e):
print("* The runroot plugin appears to not be installed on the" print("* The runroot plugin appears to not be installed on the"
" koji hub. Please contact the administrator.") " koji hub. Please contact the administrator.")
@ -7458,7 +7458,7 @@ def handle_save_failed_tree(options, session, args):
try: try:
task_id = session.saveFailedTree(br_id, opts.full) task_id = session.saveFailedTree(br_id, opts.full)
except koji.GenericError, e: except koji.GenericError as e:
m = str(e) m = str(e)
if 'Invalid method' in m: if 'Invalid method' in m:
print(_("* The save_failed_tree plugin appears to not be " print(_("* The save_failed_tree plugin appears to not be "
@ -7573,9 +7573,9 @@ def activate_session(session):
session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas) session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas)
else: else:
session.krb_login(proxyuser=options.runas) session.krb_login(proxyuser=options.runas)
except socket.error, e: except socket.error as e:
warn(_("Could not connect to Kerberos authentication service: %s") % e.args[1]) warn(_("Could not connect to Kerberos authentication service: %s") % e.args[1])
except Exception, e: except Exception as e:
if krbV is not None and isinstance(e, krbV.Krb5Error): if krbV is not None and isinstance(e, krbV.Krb5Error):
error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0])) error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0]))
else: else:

View file

@ -421,7 +421,7 @@ class Task(object):
# If the result is a Fault, then loads will raise it # If the result is a Fault, then loads will raise it
# This is normally what we want to happen # This is normally what we want to happen
result, method = six.moves.xmlrpc_client.loads(xml_result) result, method = six.moves.xmlrpc_client.loads(xml_result)
except six.moves.xmlrpc_client.Fault, fault: except six.moves.xmlrpc_client.Fault as fault:
if raise_fault: if raise_fault:
raise raise
# Note that you can't really return a fault over xmlrpc, except by # Note that you can't really return a fault over xmlrpc, except by
@ -8800,7 +8800,7 @@ class RootExports(object):
fn = get_upload_path(path, name, create=True, volume=volume) fn = get_upload_path(path, name, create=True, volume=volume)
try: try:
st = os.lstat(fn) st = os.lstat(fn)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass pass
else: else:
@ -8869,7 +8869,7 @@ class RootExports(object):
data = {} data = {}
try: try:
fd = os.open(fn, os.O_RDONLY) fd = os.open(fn, os.O_RDONLY)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return None return None
else: else:
@ -8877,7 +8877,7 @@ class RootExports(object):
try: try:
try: try:
fcntl.lockf(fd, fcntl.LOCK_SH|fcntl.LOCK_NB) fcntl.lockf(fd, fcntl.LOCK_SH|fcntl.LOCK_NB)
except IOError, e: except IOError as e:
raise koji.LockError(e) raise koji.LockError(e)
st = os.fstat(fd) st = os.fstat(fd)
if not stat.S_ISREG(st.st_mode): if not stat.S_ISREG(st.st_mode):
@ -10387,7 +10387,7 @@ class RootExports(object):
#handle older base64 encoded data #handle older base64 encoded data
val = base64.decodestring(val) val = base64.decodestring(val)
data, method = six.moves.xmlrpc_client.loads(val) data, method = six.moves.xmlrpc_client.loads(val)
except six.moves.xmlrpc_client.Fault, fault: except six.moves.xmlrpc_client.Fault as fault:
data = fault data = fault
task[f] = data task[f] = data
yield task yield task
@ -12430,7 +12430,7 @@ class HostExports(object):
logger.debug("os.link(%r, %r)", rpmpath, l_dst) logger.debug("os.link(%r, %r)", rpmpath, l_dst)
try: try:
os.link(rpmpath, l_dst) os.link(rpmpath, l_dst)
except OSError, ose: except OSError as ose:
if ose.errno == 18: if ose.errno == 18:
shutil.copy2( shutil.copy2(
rpmpath, os.path.join(archdir, bnplet, bnp)) rpmpath, os.path.join(archdir, bnplet, bnp))
@ -12527,7 +12527,7 @@ def handle_upload(environ):
try: try:
try: try:
fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB) fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError, e: except IOError as e:
raise koji.LockError(e) raise koji.LockError(e)
if offset == -1: if offset == -1:
offset = os.lseek(fd, 0, 2) offset = os.lseek(fd, 0, 2)

View file

@ -244,7 +244,7 @@ class ModXMLRPCRequestHandler(object):
# wrap response in a singleton tuple # wrap response in a singleton tuple
response = (response,) response = (response,)
response = dumps(response, methodresponse=1, allow_none=1) response = dumps(response, methodresponse=1, allow_none=1)
except Fault, fault: except Fault as fault:
self.traceback = True self.traceback = True
response = dumps(fault) response = dumps(fault)
except: except:
@ -338,7 +338,7 @@ class ModXMLRPCRequestHandler(object):
for call in calls: for call in calls:
try: try:
result = self._dispatch(call['methodName'], call['params']) result = self._dispatch(call['methodName'], call['params'])
except Fault, fault: except Fault as fault:
results.append({'faultCode': fault.faultCode, 'faultString': fault.faultString}) results.append({'faultCode': fault.faultCode, 'faultString': fault.faultString})
except: except:
# transform unknown exceptions into XML-RPC Faults # transform unknown exceptions into XML-RPC Faults

View file

@ -227,7 +227,7 @@ def main():
ignore_tags = [] ignore_tags = []
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hi:", ["help", "ignore="]) opts, args = getopt.getopt(sys.argv[1:], "hi:", ["help", "ignore="])
except getopt.GetoptError, e: except getopt.GetoptError as e:
print("Error: %s" % e) print("Error: %s" % e)
_usage() _usage()

View file

@ -475,7 +475,7 @@ def safe_xmlrpc_loads(s):
"""Load xmlrpc data from a string, but catch faults""" """Load xmlrpc data from a string, but catch faults"""
try: try:
return loads(s) return loads(s)
except Fault, f: except Fault as f:
return f return f
## BEGIN kojikamid dup ## BEGIN kojikamid dup
@ -1582,7 +1582,7 @@ def config_directory_contents(dir_name):
configs = [] configs = []
try: try:
conf_dir_contents = os.listdir(dir_name) conf_dir_contents = os.listdir(dir_name)
except OSError, exception: except OSError as exception:
if exception.errno != errno.ENOENT: if exception.errno != errno.ENOENT:
raise raise
else: else:
@ -2312,7 +2312,7 @@ class ClientSession(object):
for i in (0, 1): for i in (0, 1):
try: try:
return self._sendOneCall(handler, headers, request) return self._sendOneCall(handler, headers, request)
except Exception, e: except Exception as e:
if i or not is_conn_error(e): if i or not is_conn_error(e):
raise raise
self.logger.debug("Connection Error: %s", e) self.logger.debug("Connection Error: %s", e)
@ -2405,7 +2405,7 @@ class ClientSession(object):
# note that, for logged-in sessions the server should tell us (via a RetryError fault) # note that, for logged-in sessions the server should tell us (via a RetryError fault)
# if the call cannot be retried. For non-logged-in sessions, all calls should be read-only # if the call cannot be retried. For non-logged-in sessions, all calls should be read-only
# and hence retryable. # and hence retryable.
except Fault, fault: except Fault as fault:
#try to convert the fault to a known exception #try to convert the fault to a known exception
err = convertFault(fault) err = convertFault(fault)
if isinstance(err, ServerOffline): if isinstance(err, ServerOffline):
@ -2421,7 +2421,7 @@ class ClientSession(object):
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
#(depending on the python version, these may or may not be subclasses of Exception) #(depending on the python version, these may or may not be subclasses of Exception)
raise raise
except Exception, e: except Exception as e:
tb_str = ''.join(traceback.format_exception(*sys.exc_info())) tb_str = ''.join(traceback.format_exception(*sys.exc_info()))
self.new_session() self.new_session()

View file

@ -79,7 +79,7 @@ class Session(object):
try: try:
id = long(args['session-id'][0]) id = long(args['session-id'][0])
key = args['session-key'][0] key = args['session-key'][0]
except KeyError, field: except KeyError as field:
raise koji.AuthError('%s not specified in session args' % field) raise koji.AuthError('%s not specified in session args' % field)
try: try:
callnum = args['callnum'][0] callnum = args['callnum'][0]

View file

@ -609,7 +609,7 @@ class TaskManager(object):
rootdir = "%s/root" % topdir rootdir = "%s/root" % topdir
try: try:
st = os.lstat(rootdir) st = os.lstat(rootdir)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
rootdir = None rootdir = None
else: else:
@ -630,13 +630,13 @@ class TaskManager(object):
#also remove the config #also remove the config
try: try:
os.unlink(data['cfg']) os.unlink(data['cfg'])
except OSError, e: except OSError as e:
self.logger.warn("%s: can't remove config: %s" % (desc, e)) self.logger.warn("%s: can't remove config: %s" % (desc, e))
elif age > 120: elif age > 120:
if rootdir: if rootdir:
try: try:
flist = os.listdir(rootdir) flist = os.listdir(rootdir)
except OSError, e: except OSError as e:
self.logger.warn("%s: can't list rootdir: %s" % (desc, e)) self.logger.warn("%s: can't list rootdir: %s" % (desc, e))
continue continue
if flist: if flist:
@ -864,7 +864,7 @@ class TaskManager(object):
prefix = "Task %i (pid %i)" % (task_id, pid) prefix = "Task %i (pid %i)" % (task_id, pid)
try: try:
(childpid, status) = os.waitpid(pid, os.WNOHANG) (childpid, status) = os.waitpid(pid, os.WNOHANG)
except OSError, e: except OSError as e:
#check errno #check errno
if e.errno != errno.ECHILD: if e.errno != errno.ECHILD:
#should not happen #should not happen
@ -905,7 +905,7 @@ class TaskManager(object):
try: try:
os.kill(pid, sig) os.kill(pid, sig)
except OSError, e: except OSError as e:
# process probably went away, we'll find out on the next iteration # process probably went away, we'll find out on the next iteration
self.logger.info('Error sending signal %i to %s (pid %i, taskID %i): %s' % self.logger.info('Error sending signal %i to %s (pid %i, taskID %i): %s' %
(sig, execname, pid, task_id, e)) (sig, execname, pid, task_id, e))
@ -1194,7 +1194,7 @@ class TaskManager(object):
self.logger.info("RESPONSE: %r" % response) self.logger.info("RESPONSE: %r" % response)
self.session.host.closeTask(handler.id, response) self.session.host.closeTask(handler.id, response)
return return
except six.moves.xmlrpc_client.Fault, fault: except six.moves.xmlrpc_client.Fault as fault:
response = six.moves.xmlrpc_client.dumps(fault) response = six.moves.xmlrpc_client.dumps(fault)
tb = ''.join(traceback.format_exception(*sys.exc_info())).replace(r"\n", "\n") tb = ''.join(traceback.format_exception(*sys.exc_info())).replace(r"\n", "\n")
self.logger.warn("FAULT:\n%s" % tb) self.logger.warn("FAULT:\n%s" % tb)

View file

@ -106,7 +106,7 @@ class SSLConnection:
try: try:
sent = con.send(data, flags) sent = con.send(data, flags)
except SSL.SysCallError, e: except SSL.SysCallError as e:
if e[0] == 32: # Broken Pipe if e[0] == 32: # Broken Pipe
self.close() self.close()
sent = 0 sent = 0
@ -142,7 +142,7 @@ class SSLConnection:
return None return None
except SSL.WantReadError: except SSL.WantReadError:
time.sleep(0.2) time.sleep(0.2)
except SSL.SysCallError, e: except SSL.SysCallError as e:
if e.args == (-1, 'Unexpected EOF'): if e.args == (-1, 'Unexpected EOF'):
break break
raise raise

View file

@ -240,7 +240,7 @@ class BaseTaskHandler(object):
continue continue
try: try:
self.session.getTaskResult(task) self.session.getTaskResult(task)
except (koji.GenericError, six.moves.xmlrpc_client.Fault), task_error: except (koji.GenericError, six.moves.xmlrpc_client.Fault) as task_error:
self.logger.info("task %s failed or was canceled" % task) self.logger.info("task %s failed or was canceled" % task)
failed = True failed = True
break break

View file

@ -156,7 +156,7 @@ def call_with_argcheck(func, args, kwargs=None):
kwargs = {} kwargs = {}
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except TypeError, e: except TypeError as e:
if sys.exc_info()[2].tb_next is None: if sys.exc_info()[2].tb_next is None:
# The stack is only one high, so the error occurred in this function. # The stack is only one high, so the error occurred in this function.
# Therefore, we assume the TypeError is due to a parameter mismatch # Therefore, we assume the TypeError is due to a parameter mismatch
@ -459,7 +459,7 @@ def setup_rlimits(opts, logger=None):
logger.warn('Setting resource limit: %s = %r', key, limits) logger.warn('Setting resource limit: %s = %r', key, limits)
try: try:
resource.setrlimit(rcode, tuple(limits)) resource.setrlimit(rcode, tuple(limits))
except ValueError, e: except ValueError as e:
logger.error("Unable to set %s: %s", key, e) logger.error("Unable to set %s: %s", key, e)
class adler32_constructor(object): class adler32_constructor(object):

View file

@ -198,7 +198,7 @@ def get_options():
if len(parts) < 2: if len(parts) < 2:
continue continue
options.key_aliases[parts[0].upper()] = parts[1] options.key_aliases[parts[0].upper()] = parts[1]
except ValueError, e: except ValueError as e:
print(e) print(e)
parser.error(_("Invalid key alias data in config: %s") % config.get('main','key_aliases')) parser.error(_("Invalid key alias data in config: %s") % config.get('main','key_aliases'))
@ -373,9 +373,9 @@ def activate_session(session):
session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas) session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas)
else: else:
session.krb_login(proxyuser=options.runas) session.krb_login(proxyuser=options.runas)
except krbV.Krb5Error, e: except krbV.Krb5Error as e:
error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0])) error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0]))
except socket.error, e: except socket.error as e:
warn(_("Could not connect to Kerberos authentication service: '%s'") % e.args[1]) warn(_("Could not connect to Kerberos authentication service: '%s'") % e.args[1])
if not options.noauth and not session.logged_in: if not options.noauth and not session.logged_in:
error(_("Error: unable to log in, no authentication methods available")) error(_("Error: unable to log in, no authentication methods available"))
@ -656,7 +656,7 @@ def handle_delete(just_salvage=False):
session.untagBuildBypass(trashcan_tag, binfo['id']) session.untagBuildBypass(trashcan_tag, binfo['id'])
try: try:
session.deleteBuild(binfo['id']) session.deleteBuild(binfo['id'])
except (six.moves.xmlrpc_client.Fault, koji.GenericError), e: except (six.moves.xmlrpc_client.Fault, koji.GenericError) as e:
print("Warning: deletion failed: %s" % e) print("Warning: deletion failed: %s" % e)
#server issue #server issue
pass pass
@ -875,7 +875,7 @@ def handle_prune():
try: try:
session.untagBuildBypass(taginfo['id'], entry['build_id'], force=bypass) session.untagBuildBypass(taginfo['id'], entry['build_id'], force=bypass)
untagged.setdefault(nvr, {})[tagname] = 1 untagged.setdefault(nvr, {})[tagname] = 1
except (six.moves.xmlrpc_client.Fault, koji.GenericError), e: except (six.moves.xmlrpc_client.Fault, koji.GenericError) as e:
print("Warning: untag operation failed: %s" % e) print("Warning: untag operation failed: %s" % e)
pass pass
# if action == 'keep' do nothing # if action == 'keep' do nothing
@ -909,7 +909,7 @@ def handle_prune():
print("Deleting untagged build: %s" % nvr) print("Deleting untagged build: %s" % nvr)
try: try:
session.deleteBuild(build_id, strict=False) session.deleteBuild(build_id, strict=False)
except (six.moves.xmlrpc_client.Fault, koji.GenericError), e: except (six.moves.xmlrpc_client.Fault, koji.GenericError) as e:
print("Warning: deletion failed: %s" % e) print("Warning: deletion failed: %s" % e)
#server issue #server issue
pass pass

View file

@ -329,9 +329,9 @@ def activate_session(session):
session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas) session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas)
else: else:
session.krb_login(proxyuser=options.runas) session.krb_login(proxyuser=options.runas)
except krbV.Krb5Error, e: except krbV.Krb5Error as e:
error(_("Kerberos authentication failed: '%s' (%s)") % (e.args[1], e.args[0])) error(_("Kerberos authentication failed: '%s' (%s)") % (e.args[1], e.args[0]))
except socket.error, e: except socket.error as e:
warn(_("Could not connect to Kerberos authentication service: '%s'") % e.args[1]) warn(_("Could not connect to Kerberos authentication service: '%s'") % e.args[1])
if not options.noauth and not session.logged_in: if not options.noauth and not session.logged_in:
error(_("Error: unable to log in")) error(_("Error: unable to log in"))

View file

@ -146,7 +146,7 @@ class ManagedRepo(object):
#also check dir age. We do this because a repo can be created from an older event #also check dir age. We do this because a repo can be created from an older event
#and should not be removed based solely on that event's timestamp. #and should not be removed based solely on that event's timestamp.
mtime = os.stat(path).st_mtime mtime = os.stat(path).st_mtime
except OSError, e: except OSError as e:
if e.errno == 2: if e.errno == 2:
# No such file or directory, so the repo either never existed, # No such file or directory, so the repo either never existed,
# or has already been deleted, so allow it to be marked deleted. # or has already been deleted, so allow it to be marked deleted.
@ -226,7 +226,7 @@ class RepoManager(object):
prefix = "pid %i (%s)" % (pid, self.delete_pids.get(pid)) prefix = "pid %i (%s)" % (pid, self.delete_pids.get(pid))
try: try:
(childpid, status) = os.waitpid(pid, os.WNOHANG) (childpid, status) = os.waitpid(pid, os.WNOHANG)
except OSError, e: except OSError as e:
if e.errno != errno.ECHILD: if e.errno != errno.ECHILD:
#should not happen #should not happen
raise raise
@ -261,7 +261,7 @@ class RepoManager(object):
for pid in self.delete_pids: for pid in self.delete_pids:
try: try:
os.kill(pid, sig) os.kill(pid, sig)
except OSError, e: except OSError as e:
if e.errno != errno.ESRCH: if e.errno != errno.ESRCH:
logger.error("Unable to kill process %s", pid) logger.error("Unable to kill process %s", pid)