Commit 2a8de2df authored by Boris Egorov's avatar Boris Egorov Committed by Javier Jardón

Make exception raising/handling Python3-compatible

Signed-off-by: 's avatarBoris Egorov <egorov@linux.com>
parent 7cfda575
......@@ -100,7 +100,7 @@ class cmd_updateone(Command):
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:
......@@ -138,7 +138,7 @@ class cmd_cleanone(Command):
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:
......@@ -325,7 +325,7 @@ class cmd_buildone(BuildCommand):
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
......@@ -369,7 +369,7 @@ class cmd_run(Command):
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)})
......@@ -379,7 +379,7 @@ class cmd_run(Command):
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)
......@@ -389,7 +389,7 @@ class cmd_run(Command):
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:
......@@ -399,7 +399,7 @@ class cmd_run(Command):
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)})
......
......@@ -514,7 +514,7 @@ class cmd_bot(Command):
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
......
......@@ -676,7 +676,7 @@ class cmd_goalreport(Command):
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):
......@@ -723,7 +723,7 @@ class cmd_goalreport(Command):
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):
......
......@@ -84,7 +84,7 @@ class cmd_make(Command):
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, ))
......
......@@ -166,7 +166,7 @@ class cmd_sanitycheck(Command):
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)
......@@ -195,7 +195,7 @@ class Config:
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
......
......@@ -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):
......
......@@ -62,10 +62,10 @@ class ServerProxy(xmlrpclib.ServerProxy):
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:
......@@ -176,7 +176,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
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))
......@@ -207,7 +207,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
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)
......
......@@ -161,7 +161,7 @@ class BuildScript:
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:
......@@ -261,7 +261,7 @@ class BuildScript:
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:
......
......@@ -482,7 +482,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
self.child_pid = p.pid
......
......@@ -175,9 +175,9 @@ class TerminalBuildScript(buildscript.BuildScript):
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' :
......@@ -207,7 +207,7 @@ class TerminalBuildScript(buildscript.BuildScript):
try:
p = subprocess.Popen(command, **kws)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
output = []
......
......@@ -213,9 +213,9 @@ class TinderboxBuildScript(buildscript.BuildScript):
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' :
......@@ -254,7 +254,7 @@ class TinderboxBuildScript(buildscript.BuildScript):
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))
......@@ -342,9 +342,9 @@ class TinderboxBuildScript(buildscript.BuildScript):
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' :
......@@ -397,9 +397,9 @@ class TinderboxBuildScript(buildscript.BuildScript):
' 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' :
......
......@@ -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)
......@@ -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:
......@@ -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)
......
......@@ -294,9 +294,9 @@ them into the prefix."""
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
......@@ -334,7 +334,7 @@ them into the prefix."""
assert target.startswith(buildscript.config.prefix)
try:
os.rmdir(target)
except OSError, e:
except OSError as e:
pass
remaining_files = os.listdir(destdir)
......@@ -418,7 +418,7 @@ them into the prefix."""
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
......
......@@ -91,7 +91,7 @@ class AutogenModule(MakeModule, DownloadableModule):
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
......
......@@ -114,8 +114,8 @@ class LinuxModule(MakeModule):
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:
......
......@@ -277,7 +277,7 @@ class TestModule(Package, DownloadableModule):
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')
......@@ -317,7 +317,7 @@ class TestModule(Package, DownloadableModule):
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)
......
......@@ -176,7 +176,7 @@ class ModuleSet:
# 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 = []
......@@ -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'
......@@ -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
......
......@@ -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:
......
......@@ -69,7 +69,7 @@ Returns a list, where each item is a 2-tuple:
else:
os.unlink(path)
results.append((path, True, ''))
except OSError, e:
except OSError as e:
if (isdir
and allow_nonempty_dirs
and len(os.listdir(path)) > 0):
......@@ -98,7 +98,7 @@ def _windows_rename(src, dst):
'''atomically rename file src to dst, replacing dst if it exists'''
try:
os.rename(src, dst)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
# Windows does not allow to unlink open file.
......
......@@ -43,7 +43,7 @@ except ImportError:
try:
import xml.dom.minidom
except ImportError:
raise SystemExit, _('Python XML packages are required but could not be found')
raise SystemExit(_('Python XML packages are required but could not be found'))
def _parse_isotime(string):
if string[-1] != 'Z':
......@@ -214,7 +214,7 @@ class Cache:
fp = open(filename, 'wb')
fp.write(data)
fp.close()
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if e.code == 304: # not modified; update validated
expires = e.hdrs.get('Expires')
filename = os.path.join(self.cachedir, entry.local)
......
......@@ -197,7 +197,7 @@ class SystemInstall(object):
elif cmds.has_command('sudo'):
self._root_command_prefix_args = ['sudo']
else:
raise SystemExit, _('No suitable root privilege command found; you should install "pkexec"')
raise SystemExit(_('No suitable root privilege command found; you should install "pkexec"'))
def install(self, uninstalled):
"""Takes a list of pkg-config identifiers and uses a system-specific method to install them."""
......
......@@ -95,7 +95,7 @@ class TrayIcon:
try:
self.proc.stdin.write(cmd)
self.proc.stdin.flush()
except (IOError, OSError), err:
except (IOError, OSError) as err:
self.close()
def set_icon(self, icon):
self._send_cmd('icon: %s\n' % icon)
......
......@@ -101,7 +101,7 @@ class DarcsBranch(Branch):
path = os.path.join(self.srcdir, filename)
try:
stat = os.stat(path)
except OSError, e:
except OSError as e:
continue
os.chmod(path, stat.st_mode | 0111)
......
......@@ -112,7 +112,7 @@ class FossilBranch(Branch):
try:
infos = Popen(['fossil', 'info'], stdout=PIPE, cwd=self.srcdir)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
infos = infos.stdout.read().strip()
return re.search(r"checkout: +(\w+)", infos).group(1)
......
......@@ -111,7 +111,7 @@ class HgBranch(Branch):
try:
hg = Popen(['hg', 'ti', '--template', '{node}'], stdout=PIPE,
cwd=self.srcdir)
except OSError, e:
except OSError as e:
raise CommandError(str(e))
return hg.stdout.read().strip()
......
......@@ -306,7 +306,7 @@ class SubversionBranch(Branch):
try:
output = subprocess.Popen(['svn', 'info', '-R'],
stdout = subprocess.PIPE, **kws).communicate()[0]
except OSError, e:
except OSError as e:
raise CommandError(str(e))
if '\nConflict' in output:
raise CommandError(_('Error checking for conflicts'))
......
......@@ -254,9 +254,9 @@ class TarballBranch(Branch):
# patch name has scheme, get patch from network
try:
patchfile = httpcache.load(patch, nonetwork=buildscript.config.nonetwork)
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
raise BuildStateError(_('could not download patch (error: %s)') % e.code)
except urllib2.URLError, e:
except urllib2.URLError as e:
raise BuildStateError(_('could not download patch'))
elif self.repository.moduleset_uri:
# get it relative to the moduleset uri, either in the same
......@@ -266,7 +266,7 @@ class TarballBranch(Branch):
os.path.join(patch_prefix, patch))
try:
patchfile = httpcache.load(uri, nonetwork=buildscript.config.nonetwork)
except Exception, e:
except Exception as e:
continue
if not os.path.isfile(patchfile):
continue
......
......@@ -74,7 +74,7 @@ if __name__ == '__main__':
ret = False
try:
ret = pull_and_update()
except OSError, e:
except OSError as e:
print '%s: %s' % (sys.argv[0], e)
if ret:
......
......@@ -104,7 +104,7 @@ def main(args):
opts, args = getopt.getopt(args, 'd:u:s:x:h',
['dependencies=', 'uri=', 'source=',
'exceptions=', 'help'])
except getopt.error, exc:
except getopt.error as exc:
sys.stderr.write('mk-tarball-moduleset: %s\n' % str(exc))
sys.stderr.write(usage + '\n')
sys.exit(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment