Skip to content

Commit

Permalink
Make exception raising/handling Python3-compatible
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Egorov <egorov@linux.com>
  • Loading branch information
JIghtuse authored and jjardon committed Feb 10, 2016
1 parent 7cfda57 commit 2a8de2d
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 65 deletions.
14 changes: 7 additions & 7 deletions jhbuild/commands/base.py
Expand Up @@ -100,7 +100,7 @@ def run(self, config, options, args, help=None):
module_set = jhbuild.moduleset.load(config)
try:
module_list = [module_set.get_module(modname, ignore_case = True) for modname in args]
except KeyError, e:
except KeyError as e:
raise FatalError(_("A module called '%s' could not be found.") % e)

if not module_list:
Expand Down Expand Up @@ -138,7 +138,7 @@ def run(self, config, options, args, help=None):
module_set = jhbuild.moduleset.load(config)
try:
module_list = [module_set.get_module(modname, ignore_case = True) for modname in args]
except KeyError, e:
except KeyError as e:
raise FatalError(_("A module called '%s' could not be found.") % e)

if not module_list:
Expand Down Expand Up @@ -325,7 +325,7 @@ def run(self, config, options, args, help=None):
modname = modname.rstrip(os.sep)
try:
module = module_set.get_module(modname, ignore_case=True)
except KeyError, e:
except KeyError as e:
default_repo = jhbuild.moduleset.get_default_repo()
if not default_repo:
continue
Expand Down Expand Up @@ -369,7 +369,7 @@ def execute(self, config, args, help=None):
return self.run(config, options, args)
try:
return os.execlp(args[0], *args)
except OSError, exc:
except OSError as exc:
raise FatalError(_("Unable to execute the command '%(command)s': %(err)s") % {
'command':args[0], 'err':str(exc)})

Expand All @@ -379,7 +379,7 @@ def run(self, config, options, args, help=None):
module_set = jhbuild.moduleset.load(config)
try:
module = module_set.get_module(module_name, ignore_case = True)
except KeyError, e:
except KeyError as e:
raise FatalError(_("A module called '%s' could not be found.") % e)

build = jhbuild.frontends.get_buildscript(config, [module], module_set=module_set)
Expand All @@ -389,7 +389,7 @@ def run(self, config, options, args, help=None):
workingdir = module.get_srcdir(build)
try:
build.execute(args, cwd=workingdir)
except CommandError, exc:
except CommandError as exc:
if args:
raise FatalError(_("Unable to execute the command '%s'") % args[0])
else:
Expand All @@ -399,7 +399,7 @@ def run(self, config, options, args, help=None):
os.execlp(args[0], *args)
except IndexError:
raise FatalError(_('No command given'))
except OSError, exc:
except OSError as exc:
raise FatalError(_("Unable to execute the command '%(command)s': %(err)s") % {
'command':args[0], 'err':str(exc)})

Expand Down
2 changes: 1 addition & 1 deletion jhbuild/commands/bot.py
Expand Up @@ -514,7 +514,7 @@ def loadConfig(self, f):
if changeHorizon is not None and not isinstance(changeHorizon, int):
raise ValueError("changeHorizon needs to be an int")

except KeyError, e:
except KeyError as e:
log.msg("config dictionary is missing a required parameter")
log.msg("leaving old configuration in place")
raise
Expand Down
4 changes: 2 additions & 2 deletions jhbuild/commands/goalreport.py
Expand Up @@ -676,7 +676,7 @@ def load_bugs(self, filename):
filename += '?action=raw'
try:
filename = httpcache.load(filename, age=0)
except Exception, e:
except Exception as e:
logging.warning('could not download %s: %s' % (filename, e))
return
for line in file(filename):
Expand Down Expand Up @@ -723,7 +723,7 @@ def load_false_positives(self, filename):
filename += '?action=raw'
try:
filename = httpcache.load(filename, age=0)
except Exception, e:
except Exception as e:
logging.warning('could not download %s: %s' % (filename, e))
return
for line in file(filename):
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/commands/make.py
Expand Up @@ -84,7 +84,7 @@ def run(self, config, options, args, help=None):

try:
module = module_set.get_module(modname, ignore_case=True)
except KeyError, e:
except KeyError as e:
default_repo = jhbuild.moduleset.get_default_repo()
if not default_repo:
logging.error(_('No module matching current directory %r in the moduleset') % (modname, ))
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/commands/sanitycheck.py
Expand Up @@ -166,7 +166,7 @@ def check_m4(self):
uprint(_("Please copy the lacking macros (%(macros)s) in one of the following paths: %(path)s") % \
{'macros': ', '.join(not_in_path), 'path': ', '.join(path)})

except CommandError, exc:
except CommandError as exc:
uprint(str(exc))

register_command(cmd_sanitycheck)
2 changes: 1 addition & 1 deletion jhbuild/config.py
Expand Up @@ -195,7 +195,7 @@ def load(self, filename=None):
if filename:
try:
execfile(filename, config)
except Exception, e:
except Exception as e:
if isinstance(e, FatalError):
# raise FatalErrors back, as it means an error in include()
# and it will print a traceback, and provide a meaningful
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/defaults.jhbuildrc
Expand Up @@ -68,7 +68,7 @@ builddir_pattern = '%s'
try:
import multiprocessing
jobs = multiprocessing.cpu_count() + 1
except ImportError, _e:
except ImportError as _e:
try:
jobs = os.sysconf('SC_NPROCESSORS_ONLN') + 1
except (OSError, AttributeError, ValueError):
Expand Down
8 changes: 4 additions & 4 deletions jhbuild/frontends/autobuild.py
Expand Up @@ -62,10 +62,10 @@ def __request(self, methodname, params):
for i in range(ITERS):
try:
return xmlrpclib.ServerProxy.__request(self, methodname, params)
except xmlrpclib.ProtocolError, e:
except xmlrpclib.ProtocolError as e:
if e.errcode != 500:
raise
except socket.error, e:
except socket.error as e:
pass
if i < ITERS-1:
if self.verbose_timeout:
Expand Down Expand Up @@ -176,7 +176,7 @@ def format_line(line, error_output, fp=self.phasefp):

try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
self.phasefp.write('<span class="error">' + _('Error: %s') % escape(str(e)) + '</span>\n')
raise CommandError(str(e))

Expand Down Expand Up @@ -207,7 +207,7 @@ def start_build(self):

try:
self.build_id = self.server.start_build(info)
except xmlrpclib.ProtocolError, e:
except xmlrpclib.ProtocolError as e:
if e.errcode == 403:
print >> sys.stderr, _('ERROR: Wrong credentials, please check username/password')
sys.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions jhbuild/frontends/buildscript.py
Expand Up @@ -161,7 +161,7 @@ def build(self, phases=None):
try:
try:
error, altphases = module.run_phase(self, phase)
except SkipToPhase, e:
except SkipToPhase as e:
try:
num_phase = build_phases.index(e.phase)
except ValueError:
Expand Down Expand Up @@ -261,7 +261,7 @@ def run_triggers(self, modules):
logging.info(_('Running post-installation trigger script: %r') % (trig.name, ))
try:
self.execute(trig.command())
except CommandError, err:
except CommandError as err:
if isinstance(trig.command(), (str, unicode)):
displayed_command = trig.command()
else:
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/frontends/gtkui.py
Expand Up @@ -482,7 +482,7 @@ def execute(self, command, hint=None, cwd=None, extra_env=None):

try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
self.child_pid = p.pid

Expand Down
6 changes: 3 additions & 3 deletions jhbuild/frontends/terminal.py
Expand Up @@ -175,9 +175,9 @@ def execute(self, command, hint=None, cwd=None, extra_env=None):
if self.config.print_command_pattern:
try:
print self.config.print_command_pattern % print_args
except TypeError, e:
except TypeError as e:
raise FatalError('\'print_command_pattern\' %s' % e)
except KeyError, e:
except KeyError as e:
raise FatalError(_('%(configuration_variable)s invalid key'
' %(key)s' % \
{'configuration_variable' :
Expand Down Expand Up @@ -207,7 +207,7 @@ def execute(self, command, hint=None, cwd=None, extra_env=None):

try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
raise CommandError(str(e))

output = []
Expand Down
14 changes: 7 additions & 7 deletions jhbuild/frontends/tinderbox.py
Expand Up @@ -213,9 +213,9 @@ def execute(self, command, hint=None, cwd=None, extra_env=None):
commandstr = self.config.print_command_pattern % print_args
self.modulefp.write('<span class="command">%s</span>\n'
% escape(commandstr))
except TypeError, e:
except TypeError as e:
raise FatalError('\'print_command_pattern\' %s' % e)
except KeyError, e:
except KeyError as e:
raise FatalError(_('%(configuration_variable)s invalid key'
' %(key)s' % \
{'configuration_variable' :
Expand Down Expand Up @@ -254,7 +254,7 @@ def format_line(line, error_output, fp=self.modulefp):

try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
self.modulefp.write('<span class="error">Error: %s</span>\n'
% escape(str(e)))
raise CommandError(str(e))
Expand Down Expand Up @@ -342,9 +342,9 @@ def end_module(self, module, failed):
try:
help_url = self.config.help_website[1] % {'module' : module}
help_html = ' <a href="%s">(help)</a>' % help_url
except TypeError, e:
except TypeError as e:
raise FatalError('"help_website" %s' % e)
except KeyError, e:
except KeyError as e:
raise FatalError(_('%(configuration_variable)s invalid key'
' %(key)s' % \
{'configuration_variable' :
Expand Down Expand Up @@ -397,9 +397,9 @@ def handle_error(self, module, phase, nextphase, error, altphases):
' for more information.</div>'
% {'name' : self.config.help_website[0],
'url' : help_url})
except TypeError, e:
except TypeError as e:
raise FatalError('"help_website" %s' % e)
except KeyError, e:
except KeyError as e:
raise FatalError(_('%(configuration_variable)s invalid key'
' %(key)s' % \
{'configuration_variable' :
Expand Down
8 changes: 4 additions & 4 deletions jhbuild/main.py
Expand Up @@ -135,7 +135,7 @@ def main(args):

try:
config = jhbuild.config.Config(options.configfile, options.conditions)
except FatalError, exc:
except FatalError as exc:
sys.stderr.write('jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace'))
sys.exit(1)

Expand All @@ -153,11 +153,11 @@ def main(args):

try:
rc = jhbuild.commands.run(command, config, args, help=lambda: print_help(parser))
except UsageError, exc:
except UsageError as exc:
sys.stderr.write('jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
parser.print_usage()
sys.exit(1)
except FatalError, exc:
except FatalError as exc:
sys.stderr.write('jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
sys.exit(1)
except KeyboardInterrupt:
Expand All @@ -166,7 +166,7 @@ def main(args):
except EOFError:
uprint(_('EOF'))
sys.exit(1)
except IOError, e:
except IOError as e:
if e.errno != errno.EPIPE:
raise
sys.exit(0)
Expand Down
8 changes: 4 additions & 4 deletions jhbuild/modtypes/__init__.py
Expand Up @@ -294,9 +294,9 @@ def _process_install_files(self, installroot, curdir, prefix, errors):
try:
fileutils.rename(src_path, dest_path)
num_copied += 1
except OSError, e:
except OSError as e:
errors.append("%s: '%s'" % (str(e), dest_path))
except OSError, e:
except OSError as e:
errors.append(str(e))
return num_copied

Expand Down Expand Up @@ -334,7 +334,7 @@ def process_install(self, buildscript, revision):
assert target.startswith(buildscript.config.prefix)
try:
os.rmdir(target)
except OSError, e:
except OSError as e:
pass

remaining_files = os.listdir(destdir)
Expand Down Expand Up @@ -418,7 +418,7 @@ def run_phase(self, buildscript, phase):
method = getattr(self, 'do_' + phase)
try:
method(buildscript)
except (CommandError, BuildStateError), e:
except (CommandError, BuildStateError) as e:
error_phases = []
if hasattr(method, 'error_phases'):
error_phases = method.error_phases
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/modtypes/autotools.py
Expand Up @@ -91,7 +91,7 @@ def _file_exists_and_is_newer_than(self, potential, other):
try:
other_stbuf = os.stat(other)
potential_stbuf = os.stat(potential)
except OSError, e:
except OSError as e:
return False
return potential_stbuf.st_mtime > other_stbuf.st_mtime

Expand Down
4 changes: 2 additions & 2 deletions jhbuild/modtypes/linux.py
Expand Up @@ -114,8 +114,8 @@ def do_configure(self, buildscript):

try:
os.makedirs(os.path.join(self.branch.srcdir, 'build-' + kconfig.version))
except OSError, (e, msg):
if e != errno.EEXIST:
except OSError as e:
if e.errno != errno.EEXIST:
raise

if kconfig.branch:
Expand Down
4 changes: 2 additions & 2 deletions jhbuild/modtypes/testmodule.py
Expand Up @@ -277,7 +277,7 @@ def do_ldtp_test(self, buildscript):
else:
buildscript.execute('ldtprunner run.xml', cwd=src_dir,
extra_env={'DISPLAY': ':%s' % self.screennum})
except CommandError, e:
except CommandError as e:
os.kill(ldtp_pid, signal.SIGINT)
if e.returncode == 32512: # ldtprunner not installed
raise BuildStateError('ldtprunner not available')
Expand Down Expand Up @@ -317,7 +317,7 @@ def do_dogtail_test(self, buildscript):
try:
buildscript.execute('python %s' % test_case,
cwd=src_dir, extra_env=extra_env)
except CommandError, e:
except CommandError as e:
if e.returncode != 0:
raise BuildStateError('%s failed' % test_case)

Expand Down
10 changes: 5 additions & 5 deletions jhbuild/moduleset.py
Expand Up @@ -176,7 +176,7 @@ def dep_resolve(node, resolved, seen, after):
# remove skip modules from module_name list
modules = [self.get_module(module, ignore_case = True) \
for module in module_names if module not in skip]
except KeyError, e:
except KeyError as e:
raise UsageError(_("A module called '%s' could not be found.") % e)

resolved = []
Expand Down Expand Up @@ -438,14 +438,14 @@ def _handle_conditions(config, element):
def _parse_module_set(config, uri):
try:
filename = httpcache.load(uri, nonetwork=config.nonetwork, age=0)
except Exception, e:
except Exception as e:
raise FatalError(_('could not download %s: %s') % (uri, e))
filename = os.path.normpath(filename)
try:
document = xml.dom.minidom.parse(filename)
except IOError, e:
except IOError as e:
raise FatalError(_('failed to parse %s: %s') % (filename, e))
except xml.parsers.expat.ExpatError, e:
except xml.parsers.expat.ExpatError as e:
raise FatalError(_('failed to parse %s: %s') % (uri, e))

assert document.documentElement.nodeName == 'moduleset'
Expand Down Expand Up @@ -523,7 +523,7 @@ def _parse_module_set(config, uri):
inc_moduleset = _parse_module_set(config, inc_uri)
except UndefinedRepositoryError:
raise
except FatalError, e:
except FatalError as e:
if inc_uri[0] == '/':
raise e
# look up in local modulesets
Expand Down
2 changes: 1 addition & 1 deletion jhbuild/utils/cmds.py
Expand Up @@ -59,7 +59,7 @@ def get_output(cmd, cwd=None, extra_env=None, get_stderr = True):
stdout=subprocess.PIPE,
stderr=stderr_output,
**kws)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
stdout, stderr = p.communicate()
if p.returncode != 0:
Expand Down

0 comments on commit 2a8de2d

Please sign in to comment.