mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
python3 compatibility: except
changes 'except FooError, fe' to 'except FooError as fe' available in python 2.6
This commit is contained in:
parent
d3648be24b
commit
3a93ac6d10
@ -74,17 +74,17 @@ def run(prg):
|
||||
except oscerr.UserAbort:
|
||||
print >>sys.stderr, 'aborted.'
|
||||
return 1
|
||||
except oscerr.APIError, e:
|
||||
except oscerr.APIError as e:
|
||||
print >>sys.stderr, 'BuildService API error:', e.msg
|
||||
return 1
|
||||
except oscerr.LinkExpandError, e:
|
||||
except oscerr.LinkExpandError as e:
|
||||
print >>sys.stderr, 'Link "%s/%s" cannot be expanded:\n' % (e.prj, e.pac), e.msg
|
||||
print >>sys.stderr, 'Use "osc repairlink" to fix merge conflicts.\n'
|
||||
return 1
|
||||
except oscerr.WorkingCopyWrongVersion, e:
|
||||
except oscerr.WorkingCopyWrongVersion as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except oscerr.NoWorkingCopy, e:
|
||||
except oscerr.NoWorkingCopy as e:
|
||||
print >>sys.stderr, e
|
||||
if os.path.isdir('.git'):
|
||||
print >>sys.stderr, "Current directory looks like git."
|
||||
@ -95,7 +95,7 @@ def run(prg):
|
||||
if os.path.isdir('CVS'):
|
||||
print >>sys.stderr, "Current directory looks like cvs."
|
||||
return 1
|
||||
except HTTPError, e:
|
||||
except HTTPError as e:
|
||||
print >>sys.stderr, 'Server returned an error:', e
|
||||
if hasattr(e, 'osc_msg'):
|
||||
print >>sys.stderr, e.osc_msg
|
||||
@ -116,76 +116,76 @@ def run(prg):
|
||||
msg = msg.split('</summary>')[0]
|
||||
print >>sys.stderr, msg
|
||||
return 1
|
||||
except BadStatusLine, e:
|
||||
except BadStatusLine as e:
|
||||
print >>sys.stderr, 'Server returned an invalid response:', e
|
||||
print >>sys.stderr, e.line
|
||||
return 1
|
||||
except HTTPException, e:
|
||||
except HTTPException as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except URLError, e:
|
||||
except URLError as e:
|
||||
print >>sys.stderr, 'Failed to reach a server:\n', e.reason
|
||||
return 1
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
# ignore broken pipe
|
||||
if e.errno != errno.EPIPE:
|
||||
raise
|
||||
return 1
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except (oscerr.ConfigError, oscerr.NoConfigfile), e:
|
||||
except (oscerr.ConfigError, oscerr.NoConfigfile) as e:
|
||||
print >>sys.stderr, e.msg
|
||||
return 1
|
||||
except oscerr.OscIOError, e:
|
||||
except oscerr.OscIOError as e:
|
||||
print >>sys.stderr, e.msg
|
||||
if getattr(prg.options, 'debug', None) or \
|
||||
getattr(prg.conf, 'config', {}).get('debug', None):
|
||||
print >>sys.stderr, e.e
|
||||
return 1
|
||||
except (oscerr.WrongOptions, oscerr.WrongArgs), e:
|
||||
except (oscerr.WrongOptions, oscerr.WrongArgs) as e:
|
||||
print >>sys.stderr, e
|
||||
return 2
|
||||
except oscerr.ExtRuntimeError, e:
|
||||
except oscerr.ExtRuntimeError as e:
|
||||
print >>sys.stderr, e.file + ':', e.msg
|
||||
return 1
|
||||
except oscerr.WorkingCopyOutdated, e:
|
||||
except oscerr.WorkingCopyOutdated as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except (oscerr.PackageExists, oscerr.PackageMissing, oscerr.WorkingCopyInconsistent), e:
|
||||
except (oscerr.PackageExists, oscerr.PackageMissing, oscerr.WorkingCopyInconsistent) as e:
|
||||
print >>sys.stderr, e.msg
|
||||
return 1
|
||||
except oscerr.PackageInternalError, e:
|
||||
except oscerr.PackageInternalError as e:
|
||||
print >>sys.stderr, 'a package internal error occured\n' \
|
||||
'please file a bug and attach your current package working copy ' \
|
||||
'and the following traceback to it:'
|
||||
print >>sys.stderr, e.msg
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
return 1
|
||||
except oscerr.PackageError, e:
|
||||
except oscerr.PackageError as e:
|
||||
print >>sys.stderr, e.msg
|
||||
return 1
|
||||
except PackageError, e:
|
||||
except PackageError as e:
|
||||
print >>sys.stderr, '%s:' % e.fname, e.msg
|
||||
return 1
|
||||
except RPMError, e:
|
||||
except RPMError as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except SSLError, e:
|
||||
except SSLError as e:
|
||||
print >>sys.stderr, "SSL Error:", e
|
||||
return 1
|
||||
except SSLVerificationError, e:
|
||||
except SSLVerificationError as e:
|
||||
print >>sys.stderr, "Certificate Verification Error:", e
|
||||
return 1
|
||||
except NoSecureSSLError, e:
|
||||
except NoSecureSSLError as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except CpioError, e:
|
||||
except CpioError as e:
|
||||
print >>sys.stderr, e
|
||||
return 1
|
||||
except oscerr.OscBaseError, e:
|
||||
except oscerr.OscBaseError as e:
|
||||
print >>sys.stderr, '*** Error:', e
|
||||
return 1
|
||||
|
||||
|
@ -605,7 +605,7 @@ def main(apiurl, opts, argv):
|
||||
bc_file = open(bc_filename, 'w')
|
||||
bc_file.write(bc)
|
||||
bc_file.flush()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404:
|
||||
# check what caused the 404
|
||||
if meta_exists(metatype='prj', path_args=(quote_plus(prj), ),
|
||||
@ -728,7 +728,7 @@ def main(apiurl, opts, argv):
|
||||
try:
|
||||
print "Downloading previous build from %s ..." % '/'.join(data)
|
||||
binaries = get_binarylist(apiurl, data[0], data[2], data[3], package=data[1], verbose=True)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print "Error: failed to get binaries: %s" % str(e)
|
||||
binaries = []
|
||||
|
||||
@ -914,7 +914,7 @@ def main(apiurl, opts, argv):
|
||||
print
|
||||
print 'The buildroot was:', build_root
|
||||
sys.exit(rc)
|
||||
except KeyboardInterrupt, i:
|
||||
except KeyboardInterrupt as i:
|
||||
print "keyboard interrupt, killing build ..."
|
||||
cmd.append('--kill')
|
||||
run_external(cmd[0], *cmd[1:])
|
||||
|
@ -28,7 +28,7 @@ class Checker:
|
||||
for key in keys:
|
||||
try:
|
||||
self.readkey(key)
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
print e
|
||||
|
||||
if not len(self.imported):
|
||||
@ -108,7 +108,7 @@ if __name__ == "__main__":
|
||||
checker.readkeys(keyfiles)
|
||||
for pkg in pkgs:
|
||||
checker.check(pkg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
checker.cleanup()
|
||||
raise e
|
||||
|
||||
|
@ -289,13 +289,13 @@ class RawCmdln(cmd.Cmd):
|
||||
if self.optparser: # i.e. optparser=None means don't process for opts
|
||||
try:
|
||||
self.options, args = self.optparser.parse_args(argv[1:])
|
||||
except CmdlnUserError, ex:
|
||||
except CmdlnUserError as ex:
|
||||
msg = "%s: %s\nTry '%s help' for info.\n"\
|
||||
% (self.name, ex, self.name)
|
||||
self.stderr.write(self._str(msg))
|
||||
self.stderr.flush()
|
||||
return 1
|
||||
except StopOptionProcessing, ex:
|
||||
except StopOptionProcessing as ex:
|
||||
return 0
|
||||
else:
|
||||
self.options, args = None, argv[1:]
|
||||
@ -1174,7 +1174,7 @@ class Cmdln(RawCmdln):
|
||||
|
||||
try:
|
||||
return handler(argv[0], opts, *args)
|
||||
except TypeError, ex:
|
||||
except TypeError as ex:
|
||||
# Some TypeError's are user errors:
|
||||
# do_foo() takes at least 4 arguments (3 given)
|
||||
# do_foo() takes at most 5 arguments (6 given)
|
||||
|
@ -120,7 +120,7 @@ class Osc(cmdln.Cmdln):
|
||||
override_no_keyring = self.options.no_keyring,
|
||||
override_no_gnome_keyring = self.options.no_gnome_keyring,
|
||||
override_verbose = self.options.verbose)
|
||||
except oscerr.NoConfigfile, e:
|
||||
except oscerr.NoConfigfile as e:
|
||||
print >>sys.stderr, e.msg
|
||||
print >>sys.stderr, 'Creating osc configuration file %s ...' % e.file
|
||||
import getpass
|
||||
@ -137,7 +137,7 @@ class Osc(cmdln.Cmdln):
|
||||
conf.write_initial_config(e.file, config)
|
||||
print >>sys.stderr, 'done'
|
||||
if try_again: self.postoptparse(try_again = False)
|
||||
except oscerr.ConfigMissingApiurl, e:
|
||||
except oscerr.ConfigMissingApiurl as e:
|
||||
print >>sys.stderr, e.msg
|
||||
import getpass
|
||||
user = raw_input('Username: ')
|
||||
@ -162,10 +162,10 @@ class Osc(cmdln.Cmdln):
|
||||
def get_api_url(self):
|
||||
try:
|
||||
localdir = os.getcwd()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
## check for Stale NFS file handle: '.'
|
||||
try: os.stat('.')
|
||||
except Exception, ee: e = ee
|
||||
except Exception as ee: e = ee
|
||||
print >>sys.stderr, "os.getcwd() failed: ", e
|
||||
sys.exit(1)
|
||||
|
||||
@ -2091,7 +2091,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
try:
|
||||
# works since OBS 2.1
|
||||
diff = request_diff(apiurl, reqid)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
# for OBS 2.0 and before
|
||||
sr_actions = r.get_actions('submit')
|
||||
if not sr_actions:
|
||||
@ -2132,7 +2132,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
r = change_review_state(apiurl, reqid, state_map[cmd], review.by_user, review.by_group,
|
||||
review.by_project, review.by_package, opts.message or '', supersed=supersedid)
|
||||
print r
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if review.by_user:
|
||||
print 'No permission on review by user %s' % review.by_user
|
||||
if review.by_group:
|
||||
@ -2189,10 +2189,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
if link_node != None:
|
||||
links_to_project = link_node.get('project') or project
|
||||
links_to_package = link_node.get('package') or package
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 404:
|
||||
print >>sys.stderr, 'Cannot get list of files for %s/%s: %s' % (project, package, e)
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
print >>sys.stderr, 'Cannot parse list of files for %s/%s: %s' % (project, package, e)
|
||||
if links_to_project==action.tgt_project and links_to_package==action.tgt_package:
|
||||
# links to my request target anyway, no need to forward submit
|
||||
@ -2359,7 +2359,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
|
||||
try:
|
||||
copy_pac(apiurl, project, package, apiurl, project, package, expand=True, comment=opts.message)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
root = ET.fromstring(show_files_meta(apiurl, project, package, 'latest', expand=False))
|
||||
li = Linkinfo()
|
||||
li.read(root.find('linkinfo'))
|
||||
@ -2955,7 +2955,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
uproject = root.find('attribute').find('value').text
|
||||
print '\nNote: The branch has been created from the configured update project: %s' \
|
||||
% uproject
|
||||
except (AttributeError, urllib2.HTTPError), e:
|
||||
except (AttributeError, urllib2.HTTPError) as e:
|
||||
devloc = srcprj
|
||||
print '\nNote: The branch has been created of a different project,\n' \
|
||||
' %s,\n' \
|
||||
@ -3373,7 +3373,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
try:
|
||||
show_package_meta(apiurl, project, package)
|
||||
return True
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 404:
|
||||
print >>sys.stderr, 'Cannot check that %s/%s exists: %s' % (project, package, e)
|
||||
return False
|
||||
@ -3401,9 +3401,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
try:
|
||||
file = http_GET(link_url)
|
||||
root = ET.parse(file).getroot()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
return (None, None)
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
print >>sys.stderr, 'Cannot parse %s/%s/_link: %s' % (project, package, e)
|
||||
return (None, None)
|
||||
|
||||
@ -3420,11 +3420,11 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
try:
|
||||
file = http_GET(link_url)
|
||||
root = ET.parse(file).getroot()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 404:
|
||||
print >>sys.stderr, 'Cannot get list of files for %s/%s: %s' % (project, package, e)
|
||||
return (None, None, None)
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
print >>sys.stderr, 'Cannot parse list of files for %s/%s: %s' % (project, package, e)
|
||||
return (None, None, None)
|
||||
|
||||
@ -3864,7 +3864,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
try:
|
||||
checkout_package(apiurl, project, package, expand_link = expand_link, \
|
||||
prj_dir = prj_dir, service_files = opts.source_service_files, server_service_files = opts.server_side_source_service_files, progress_obj=self.download_progress, size_limit=opts.limit_size, meta=opts.meta)
|
||||
except oscerr.LinkExpandError, e:
|
||||
except oscerr.LinkExpandError as e:
|
||||
print >>sys.stderr, 'Link cannot be expanded:\n', e
|
||||
print >>sys.stderr, 'Use "osc repairlink" for fixing merge conflicts:\n'
|
||||
# check out in unexpanded form at least
|
||||
@ -4108,7 +4108,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
if not msg:
|
||||
msg = edit_message()
|
||||
prj.commit(msg=msg, skip_local_service_run=skip_local_service_run, verbose=opts.verbose)
|
||||
except oscerr.ExtRuntimeError, e:
|
||||
except oscerr.ExtRuntimeError as e:
|
||||
print >>sys.stderr, "ERROR: service run failed", e
|
||||
return 1
|
||||
args.remove(arg)
|
||||
@ -4441,7 +4441,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
continue
|
||||
try:
|
||||
delete_files(apiurl, project, package, (filename, ))
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if opts.force:
|
||||
print >>sys.stderr, e
|
||||
body = e.read()
|
||||
@ -6283,7 +6283,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
print r.list_view(), '\n'
|
||||
print ""
|
||||
return
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 400:
|
||||
# skip it ... try again with old style below
|
||||
pass
|
||||
@ -6478,7 +6478,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
what = {'published/binary/id': xpath}
|
||||
try:
|
||||
res = search(apiurl, **what)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 400 or not role_filter:
|
||||
raise e
|
||||
# backward compatibility: local role filtering
|
||||
@ -6881,7 +6881,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
for role in roles:
|
||||
try:
|
||||
setBugowner(apiurl, result.get('project'), result.get('package'), bugowner)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 403:
|
||||
print "No write permission in", result.get('project'),
|
||||
if result.get('package'):
|
||||
@ -6904,7 +6904,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
for role in roles:
|
||||
try:
|
||||
setBugowner(apiurl, prj, pac, opts.delete, role)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 403:
|
||||
print "No write permission in", result.get('project'),
|
||||
if result.get('package'):
|
||||
@ -7108,7 +7108,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
else:
|
||||
for data in streamfile(u):
|
||||
sys.stdout.write(data)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404 and not opts.expand and not opts.unexpand:
|
||||
print >>sys.stderr, 'expanding link...'
|
||||
query['rev'] = show_upstream_srcmd5(apiurl, args[0], args[1], expand=True, revision=opts.revision)
|
||||
@ -7527,7 +7527,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
url = makeurl(apiurl, ['source', prj, '_pubkey'])
|
||||
f = http_GET(url)
|
||||
break
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
l = prj.rsplit(':', 1)
|
||||
# try key from parent project
|
||||
if not opts.notraverse and len(l) > 1 and l[0] and l[1] and e.code == 404:
|
||||
@ -7797,7 +7797,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
if is_project_dir(i):
|
||||
try:
|
||||
prj = Project(i, getPackageList=False)
|
||||
except oscerr.WorkingCopyInconsistent, e:
|
||||
except oscerr.WorkingCopyInconsistent as e:
|
||||
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
|
||||
apiurl = get_apiurl(apiurls)
|
||||
prj = Project(i, getPackageList=False, wc_check=False)
|
||||
@ -7817,7 +7817,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
for pdir in pacs:
|
||||
try:
|
||||
p = Package(pdir)
|
||||
except oscerr.WorkingCopyInconsistent, e:
|
||||
except oscerr.WorkingCopyInconsistent as e:
|
||||
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
|
||||
apiurl = get_apiurl(apiurls)
|
||||
p = Package(pdir, wc_check=False)
|
||||
@ -7841,7 +7841,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
continue
|
||||
try:
|
||||
exec open(os.path.join(plugin_dir, extfile))
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
if (os.environ.get('OSC_PLUGIN_FAIL_IGNORE')):
|
||||
print >>sys.stderr, "%s: %s\n" % (plugin_dir, e)
|
||||
else:
|
||||
|
@ -77,7 +77,7 @@ def _get_processors():
|
||||
"""
|
||||
try:
|
||||
return os.sysconf('SC_NPROCESSORS_ONLN')
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
return 1
|
||||
|
||||
DEFAULTS = {'apiurl': 'https://api.opensuse.org',
|
||||
@ -482,7 +482,7 @@ def _build_opener(url):
|
||||
try:
|
||||
import oscssl
|
||||
from M2Crypto import m2urllib2
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
print e
|
||||
raise NoSecureSSLError('M2Crypto is needed to access %s in a secure way.\nPlease install python-m2crypto.' % apiurl)
|
||||
|
||||
@ -766,7 +766,7 @@ def get_config(override_conffile=None,
|
||||
for i in boolean_opts:
|
||||
try:
|
||||
config[i] = cp.getboolean('general', i)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise oscerr.ConfigError('cannot parse \'%s\' setting: ' % i + str(e), conffile)
|
||||
|
||||
config['packagecachedir'] = os.path.expanduser(config['packagecachedir'])
|
||||
@ -949,7 +949,7 @@ def get_config(override_conffile=None,
|
||||
# provided that there _are_ credentials for the chosen apiurl:
|
||||
try:
|
||||
config['user'] = get_apiurl_usr(config['apiurl'])
|
||||
except oscerr.ConfigMissingApiurl, e:
|
||||
except oscerr.ConfigMissingApiurl as e:
|
||||
e.msg = config_missing_apiurl_text % config['apiurl']
|
||||
e.file = conffile
|
||||
raise e
|
||||
|
60
osc/core.py
60
osc/core.py
@ -276,7 +276,7 @@ class Serviceinfo:
|
||||
self.read(root, True)
|
||||
self.project = project
|
||||
self.package = package
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 403 and e.code != 400:
|
||||
raise e
|
||||
|
||||
@ -1104,7 +1104,7 @@ class Package:
|
||||
state = '?'
|
||||
try:
|
||||
state = self.status(n)
|
||||
except IOError, ioe:
|
||||
except IOError as ioe:
|
||||
if not force:
|
||||
raise ioe
|
||||
if state in ['?', 'A', 'M', 'R', 'C'] and not force:
|
||||
@ -2763,7 +2763,7 @@ def read_filemeta(dir):
|
||||
|
||||
try:
|
||||
r = ET.parse(filesmeta)
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
raise oscerr.NoWorkingCopy('%s\nWhen parsing .osc/_files, the following error was encountered:\n%s' % (msg, e))
|
||||
return r
|
||||
|
||||
@ -2888,7 +2888,7 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100):
|
||||
else:
|
||||
data = mmap.mmap(filefd.fileno(), os.path.getsize(file))
|
||||
data = memoryview(data)
|
||||
except EnvironmentError, e:
|
||||
except EnvironmentError as e:
|
||||
if e.errno == 19:
|
||||
sys.exit('\n\n%s\nThe file \'%s\' could not be memory mapped. It is ' \
|
||||
'\non a filesystem which does not support this.' % (e, file))
|
||||
@ -3026,7 +3026,7 @@ def show_package_trigger_reason(apiurl, prj, pac, repo, arch):
|
||||
try:
|
||||
f = http_GET(url)
|
||||
return f.read()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'Error getting trigger reason for project \'%s\' package \'%s\'' % (prj, pac)
|
||||
raise
|
||||
|
||||
@ -3044,7 +3044,7 @@ def show_package_meta(apiurl, prj, pac, meta=False):
|
||||
try:
|
||||
f = http_GET(url)
|
||||
return f.readlines()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'Error getting meta for project \'%s\' package \'%s\'' % (prj, pac)
|
||||
raise
|
||||
|
||||
@ -3069,7 +3069,7 @@ def show_attribute_meta(apiurl, prj, pac, subpac, attribute, with_defaults, with
|
||||
try:
|
||||
f = http_GET(url)
|
||||
return f.readlines()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'Error getting meta for project \'%s\' package \'%s\'' % (prj, pac)
|
||||
raise
|
||||
|
||||
@ -3101,7 +3101,7 @@ def show_pattern_metalist(apiurl, prj):
|
||||
try:
|
||||
f = http_GET(url)
|
||||
tree = ET.parse(f)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'show_pattern_metalist: Error getting pattern list for project \'%s\'' % prj
|
||||
raise
|
||||
r = [ node.get('name') for node in tree.getroot() ]
|
||||
@ -3114,7 +3114,7 @@ def show_pattern_meta(apiurl, prj, pattern):
|
||||
try:
|
||||
f = http_GET(url)
|
||||
return f.readlines()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'show_pattern_meta: Error getting pattern \'%s\' for project \'%s\'' % (pattern, prj)
|
||||
raise
|
||||
|
||||
@ -3152,7 +3152,7 @@ class metafile:
|
||||
try:
|
||||
self.sync()
|
||||
break
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
error_help = "%d" % e.code
|
||||
if e.headers.get('X-Opensuse-Errorcode'):
|
||||
error_help = "%s (%d)" % (e.headers.get('X-Opensuse-Errorcode'), e.code)
|
||||
@ -3215,7 +3215,7 @@ def meta_exists(metatype,
|
||||
url = make_meta_url(metatype, path_args, apiurl)
|
||||
try:
|
||||
data = http_GET(url).readlines()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404 and create_new:
|
||||
data = metatypes[metatype]['template']
|
||||
if template_args:
|
||||
@ -3597,7 +3597,7 @@ def create_submit_request(apiurl,
|
||||
f = http_POST(u, data=xml)
|
||||
root = ET.parse(f).getroot()
|
||||
r = root.get('id')
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.headers.get('X-Opensuse-Errorcode') == "submit_request_rejected":
|
||||
print "WARNING:"
|
||||
print "WARNING: Project does not accept submit request, request to open a NEW maintenance incident instead"
|
||||
@ -3675,7 +3675,7 @@ def change_request_state_template(req, newstate):
|
||||
'tgt_project': action.tgt_project, 'tgt_package': action.tgt_package})
|
||||
try:
|
||||
return tmpl % data
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
print >>sys.stderr, 'error: cannot interpolate \'%s\' in \'%s\'' % (e.args[0], tmpl_name)
|
||||
return ''
|
||||
|
||||
@ -4114,7 +4114,7 @@ def server_diff_noex(apiurl,
|
||||
old_project, old_package, old_revision,
|
||||
new_project, new_package, new_revision,
|
||||
unified, missingok, meta, expand)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
msg = None
|
||||
body = None
|
||||
try:
|
||||
@ -4152,12 +4152,12 @@ def submit_action_diff(apiurl, action):
|
||||
try:
|
||||
return server_diff(apiurl, action.tgt_project, action.tgt_package, None,
|
||||
action.src_project, action.src_package, action.src_rev, True, True)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 400:
|
||||
try:
|
||||
return server_diff(apiurl, action.tgt_project, action.tgt_package, None,
|
||||
action.src_project, action.src_package, action.src_rev, True, False)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise e
|
||||
root = ET.fromstring(e.read())
|
||||
@ -4532,7 +4532,7 @@ def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute,
|
||||
f = None
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
msg = ''.join(e.readlines())
|
||||
msg = msg.split('<summary>')[1]
|
||||
msg = msg.split('</summary>')[0]
|
||||
@ -4584,7 +4584,7 @@ def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None,
|
||||
u = makeurl(apiurl, ['source', src_project, src_package], query=query)
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if not return_existing:
|
||||
raise
|
||||
root = ET.fromstring(e.read())
|
||||
@ -4635,7 +4635,7 @@ def copy_pac(src_apiurl, src_project, src_package,
|
||||
found = None
|
||||
try:
|
||||
found = http_GET(url).readlines()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
pass
|
||||
if force_meta_update or not found:
|
||||
print 'Sending meta data...'
|
||||
@ -4919,7 +4919,7 @@ def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], ve
|
||||
results = r = []
|
||||
try:
|
||||
results = get_package_results(apiurl, prj, package, lastbuild, repository, arch, oldstate)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
# check for simple timeout error and fetch again
|
||||
if e.code != 502:
|
||||
raise
|
||||
@ -5424,7 +5424,7 @@ def runservice(apiurl, prj, package):
|
||||
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'could not trigger service run for project \'%s\' package \'%s\'' % (prj, package)
|
||||
raise
|
||||
|
||||
@ -5446,7 +5446,7 @@ def rebuild(apiurl, prj, package, repo, arch, code=None):
|
||||
u = makeurl(apiurl, ['build', prj], query=query)
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'could not trigger rebuild for project \'%s\' package \'%s\'' % (prj, package)
|
||||
raise
|
||||
|
||||
@ -5568,7 +5568,7 @@ def abortbuild(apiurl, project, package=None, arch=None, repo=None):
|
||||
u = makeurl(apiurl, ['build', project], query)
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'abortion failed for project %s' % project
|
||||
if package:
|
||||
e.osc_msg += ' package %s' % package
|
||||
@ -5596,7 +5596,7 @@ def wipebinaries(apiurl, project, package=None, arch=None, repo=None, code=None)
|
||||
u = makeurl(apiurl, ['build', project], query)
|
||||
try:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'wipe binary rpms failed for project %s' % project
|
||||
if package:
|
||||
e.osc_msg += ' package %s' % package
|
||||
@ -5782,7 +5782,7 @@ def owner(apiurl, binary, mode="binary", attribute=None, project=None, usefilter
|
||||
try:
|
||||
f = http_GET(u)
|
||||
res = ET.parse(f).getroot()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
# old server not supporting this search
|
||||
pass
|
||||
return res
|
||||
@ -5797,7 +5797,7 @@ def set_link_rev(apiurl, project, package, revision='', expand=False, baserev=Fa
|
||||
try:
|
||||
f = http_GET(url)
|
||||
root = ET.parse(f).getroot()
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project)
|
||||
raise
|
||||
|
||||
@ -6295,7 +6295,7 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None, igno
|
||||
try:
|
||||
change_request_state(*args, **kwargs)
|
||||
return True
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
print >>sys.stderr, 'Server returned an error:', e
|
||||
print >>sys.stderr, 'Try -f to force the state change'
|
||||
return False
|
||||
@ -6331,7 +6331,7 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None, igno
|
||||
try:
|
||||
diff = request_diff(apiurl, request.reqid)
|
||||
tmpfile.write(diff)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 400:
|
||||
raise
|
||||
# backward compatible diff for old apis
|
||||
@ -6534,7 +6534,7 @@ def get_user_projpkgs(apiurl, user, role=None, exclude_projects=[], proj=True, p
|
||||
what['project_id'] = xpath_prj
|
||||
try:
|
||||
res = search(apiurl, **what)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code != 400 or not role_filter_xpath:
|
||||
raise e
|
||||
# backward compatibility: local role filtering
|
||||
@ -6575,7 +6575,7 @@ def run_external(filename, *args, **kwargs):
|
||||
cmd = filename
|
||||
try:
|
||||
return subprocess.call(cmd, **kwargs)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
raise oscerr.ExtRuntimeError(e.strerror, filename)
|
||||
|
14
osc/fetch.py
14
osc/fetch.py
@ -43,13 +43,13 @@ class OscFileGrabber:
|
||||
try:
|
||||
for i in streamfile(url, progress_obj=self.progress_obj, text=text):
|
||||
f.write(i)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
exc = URLGrabError(14, str(e))
|
||||
exc.url = url
|
||||
exc.exception = e
|
||||
exc.code = e.code
|
||||
raise exc
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
raise URLGrabError(4, str(e))
|
||||
finally:
|
||||
f.close()
|
||||
@ -126,7 +126,7 @@ class Fetcher:
|
||||
if not os.path.isfile(pac.fullfilename):
|
||||
raise oscerr.APIError('failed to fetch file \'%s\': ' \
|
||||
'does not exist in CPIO archive' % pac.repofilename)
|
||||
except URLGrabError, e:
|
||||
except URLGrabError as e:
|
||||
if e.errno != 14 or e.code != 414:
|
||||
raise
|
||||
# query str was too large
|
||||
@ -168,7 +168,7 @@ class Fetcher:
|
||||
filename = tmpfile,
|
||||
text = '%s(%s) %s' %(prefix, pac.project, pac.filename))
|
||||
self.move_package(tmpfile, pac.localdir, pac)
|
||||
except URLGrabError, e:
|
||||
except URLGrabError as e:
|
||||
if self.enable_cpio and e.errno == 256:
|
||||
self.__add_cpio(pac)
|
||||
return
|
||||
@ -205,7 +205,7 @@ class Fetcher:
|
||||
if not os.path.exists(dir):
|
||||
try:
|
||||
os.makedirs(dir, mode=0755)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
print >>sys.stderr, 'packagecachedir is not writable for you?'
|
||||
print >>sys.stderr, e
|
||||
sys.exit(1)
|
||||
@ -269,7 +269,7 @@ class Fetcher:
|
||||
if os.path.exists(dest):
|
||||
os.unlink(dest)
|
||||
sys.exit(0)
|
||||
except URLGrabError, e:
|
||||
except URLGrabError as e:
|
||||
# Not found is okay, let's go to the next project
|
||||
if e.code != 404:
|
||||
print >>sys.stderr, "Invalid answer from server", e
|
||||
@ -380,7 +380,7 @@ def verify_pacs(bi):
|
||||
for pkg in pac_list:
|
||||
try:
|
||||
checker.check(pkg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
failed = True
|
||||
print pkg, ':', e
|
||||
except:
|
||||
|
@ -75,7 +75,7 @@ def verify_cb(ctx, ok, store):
|
||||
ctx.verrs.record(store.get_current_cert(), store.get_error(), store.get_error_depth())
|
||||
return 1
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print e
|
||||
return 0
|
||||
|
||||
@ -211,7 +211,7 @@ class myHTTPSHandler(M2Crypto.m2urllib2.HTTPSHandler):
|
||||
if s:
|
||||
self.saved_session = s
|
||||
r = h.getresponse()
|
||||
except socket.error, err: # XXX what error?
|
||||
except socket.error as err: # XXX what error?
|
||||
err.filename = full_url
|
||||
raise M2Crypto.m2urllib2.URLError(err)
|
||||
|
||||
|
@ -163,7 +163,7 @@ class Ar:
|
||||
self.__file = mmap.mmap(self.__file.fileno(), os.path.getsize(self.__file.name), prot=mmap.PROT_READ)
|
||||
else:
|
||||
self.__file = mmap.mmap(self.__file.fileno(), os.path.getsize(self.__file.name))
|
||||
except EnvironmentError, e:
|
||||
except EnvironmentError as e:
|
||||
if e.errno == 19 or ( hasattr(e, 'winerror') and e.winerror == 5 ):
|
||||
print >>sys.stderr, 'cannot use mmap to read the file, falling back to the default io'
|
||||
else:
|
||||
|
@ -152,7 +152,7 @@ if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
archq = ArchQuery.query(sys.argv[1])
|
||||
except ArchError, e:
|
||||
except ArchError as e:
|
||||
print e.msg
|
||||
sys.exit(2)
|
||||
print archq.name(), archq.version(), archq.release(), archq.arch()
|
||||
|
@ -150,7 +150,7 @@ class CpioRead:
|
||||
self.__file = mmap.mmap(self.__file.fileno(), os.path.getsize(self.__file.name), prot = mmap.PROT_READ)
|
||||
else:
|
||||
self.__file = mmap.mmap(self.__file.fileno(), os.path.getsize(self.__file.name))
|
||||
except EnvironmentError, e:
|
||||
except EnvironmentError as e:
|
||||
if e.errno == 19 or ( hasattr(e, 'winerror') and e.winerror == 5 ):
|
||||
print >>sys.stderr, 'cannot use mmap to read the file, failing back to default'
|
||||
else:
|
||||
|
@ -167,7 +167,7 @@ if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
debq = DebQuery.query(sys.argv[1])
|
||||
except DebError, e:
|
||||
except DebError as e:
|
||||
print e.msg
|
||||
sys.exit(2)
|
||||
print debq.name(), debq.version(), debq.release(), debq.arch()
|
||||
|
@ -114,7 +114,7 @@ if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
pkgq = PackageQuery.query(sys.argv[1])
|
||||
except PackageError, e:
|
||||
except PackageError as e:
|
||||
print e.msg
|
||||
sys.exit(2)
|
||||
print pkgq.name()
|
||||
|
@ -312,7 +312,7 @@ if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
rpmq = RpmQuery.query(sys.argv[1])
|
||||
except RpmError, e:
|
||||
except RpmError as e:
|
||||
print e.msg
|
||||
sys.exit(2)
|
||||
print rpmq.name(), rpmq.version(), rpmq.release(), rpmq.arch(), rpmq.url()
|
||||
|
@ -19,7 +19,7 @@ class SafeWriter:
|
||||
def write(self, s):
|
||||
try:
|
||||
self.__get_writer().write(s)
|
||||
except UnicodeEncodeError, e:
|
||||
except UnicodeEncodeError as e:
|
||||
self.__get_writer().write(s.encode(self.__get_encoding()))
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
Loading…
Reference in New Issue
Block a user