mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-25 01:16:14 +01:00
PEP8-ified parts of the code.
Exchange individual return statements with a finally statement in the big try/except statement in babysitter.py. If you return a different value in the 'except' clause, it takes precedency over the 'finally' clause (finally is executed before returning, naturally).
This commit is contained in:
parent
6676d530bc
commit
438569f821
@ -3,7 +3,11 @@
|
|||||||
# this wrapper exists so it can be put into /usr/bin, but still allows the
|
# this wrapper exists so it can be put into /usr/bin, but still allows the
|
||||||
# python module to be called within the source directory during development
|
# python module to be called within the source directory during development
|
||||||
|
|
||||||
import sys, locale
|
import locale
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from osc import commandline, babysitter
|
||||||
|
|
||||||
# this is a hack to make osc work as expected with utf-8 characters,
|
# this is a hack to make osc work as expected with utf-8 characters,
|
||||||
# no matter how site.py is set...
|
# no matter how site.py is set...
|
||||||
reload(sys)
|
reload(sys)
|
||||||
@ -13,9 +17,6 @@ if not loc:
|
|||||||
sys.setdefaultencoding(loc)
|
sys.setdefaultencoding(loc)
|
||||||
del sys.setdefaultencoding
|
del sys.setdefaultencoding
|
||||||
|
|
||||||
from osc import commandline
|
|
||||||
from osc import babysitter
|
|
||||||
|
|
||||||
osccli = commandline.Osc()
|
osccli = commandline.Osc()
|
||||||
|
|
||||||
r = babysitter.run(osccli)
|
r = babysitter.run(osccli)
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
# and distributed under the terms of the GNU General Public Licence,
|
# and distributed under the terms of the GNU General Public Licence,
|
||||||
# either version 2, or (at your option) any later version.
|
# either version 2, or (at your option) any later version.
|
||||||
|
|
||||||
|
import errno
|
||||||
import os.path
|
import os.path
|
||||||
|
import pdb
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import errno
|
import traceback
|
||||||
|
|
||||||
from osc import oscerr
|
from osc import oscerr
|
||||||
from urllib2 import URLError, HTTPError
|
|
||||||
from httplib import HTTPException, BadStatusLine
|
|
||||||
from oscsslexcp import NoSecureSSLError
|
from oscsslexcp import NoSecureSSLError
|
||||||
from osc.util.cpio import CpioError
|
from osc.util.cpio import CpioError
|
||||||
from osc.util.packagequery import PackageError
|
from osc.util.packagequery import PackageError
|
||||||
@ -28,79 +29,65 @@ except:
|
|||||||
# if rpm-python isn't installed (we might be on a debian system):
|
# if rpm-python isn't installed (we might be on a debian system):
|
||||||
RPMError = None
|
RPMError = None
|
||||||
|
|
||||||
|
from httplib import HTTPException, BadStatusLine
|
||||||
|
from urllib2 import URLError, HTTPError
|
||||||
|
|
||||||
# the good things are stolen from Matt Mackall's mercurial
|
# the good things are stolen from Matt Mackall's mercurial
|
||||||
|
|
||||||
|
|
||||||
def catchterm(*args):
|
def catchterm(*args):
|
||||||
raise oscerr.SignalInterrupt
|
raise oscerr.SignalInterrupt
|
||||||
|
|
||||||
for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
|
for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
|
||||||
num = getattr(signal, name, None)
|
num = getattr(signal, name, None)
|
||||||
if num: signal.signal(num, catchterm)
|
if num:
|
||||||
|
signal.signal(num, catchterm)
|
||||||
|
|
||||||
|
|
||||||
def run(prg):
|
def run(prg):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if '--debugger' in sys.argv:
|
if '--debugger' in sys.argv:
|
||||||
import pdb
|
|
||||||
pdb.set_trace()
|
pdb.set_trace()
|
||||||
|
|
||||||
# here we actually run the program:
|
# here we actually run the program:
|
||||||
return prg.main()
|
return prg.main()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# look for an option in the prg.options object and in the config dict
|
# look for an option in the prg.options object and in the config
|
||||||
# print stack trace, if desired
|
# dict print stack trace, if desired
|
||||||
if getattr(prg.options, 'traceback', None) or getattr(prg.conf, 'config', {}).get('traceback', None) or \
|
if getattr(prg.options, 'traceback', None) or getattr(prg.conf, 'config', {}).get('traceback', None) or \
|
||||||
getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
|
getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
|
||||||
import traceback
|
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
# we could use http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215
|
# we could use http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215
|
||||||
|
|
||||||
# enter the debugger, if desired
|
# enter the debugger, if desired
|
||||||
if getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
|
if getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
|
||||||
if sys.stdout.isatty() and not hasattr(sys, 'ps1'):
|
if sys.stdout.isatty() and not hasattr(sys, 'ps1'):
|
||||||
import pdb
|
|
||||||
pdb.post_mortem(sys.exc_info()[2])
|
pdb.post_mortem(sys.exc_info()[2])
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'sys.stdout is not a tty. Not jumping into pdb.'
|
print >>sys.stderr, 'sys.stdout is not a tty. Not jumping into pdb.'
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except oscerr.SignalInterrupt:
|
except oscerr.SignalInterrupt:
|
||||||
print >>sys.stderr, 'killed!'
|
print >>sys.stderr, 'killed!'
|
||||||
return 1
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print >>sys.stderr, 'interrupted!'
|
print >>sys.stderr, 'interrupted!'
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.UserAbort:
|
except oscerr.UserAbort:
|
||||||
print >>sys.stderr, 'aborted.'
|
print >>sys.stderr, 'aborted.'
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.APIError, e:
|
except oscerr.APIError, e:
|
||||||
print >>sys.stderr, 'BuildService API error:', e.msg
|
print >>sys.stderr, 'BuildService API error:', e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.LinkExpandError, e:
|
except oscerr.LinkExpandError, e:
|
||||||
print >>sys.stderr, 'Link "%s/%s" cannot be expanded:\n' % (e.prj, e.pac), e.msg
|
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'
|
print >>sys.stderr, 'Use "osc repairlink" to fix merge conflicts.\n'
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.WorkingCopyWrongVersion, e:
|
except oscerr.WorkingCopyWrongVersion, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
|
|
||||||
except oscerr.NoWorkingCopy, e:
|
except oscerr.NoWorkingCopy, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
if os.path.isdir('.git'): print >>sys.stderr, "Current directory looks like git."
|
if os.path.isdir('.git'):
|
||||||
if os.path.isdir('.hg'): print >>sys.stderr, "Current directory looks like mercurial."
|
print >>sys.stderr, "Current directory looks like git."
|
||||||
if os.path.isdir('.svn'): print >>sys.stderr, "Current directory looks like svn."
|
if os.path.isdir('.hg'):
|
||||||
if os.path.isdir('CVS'): print >>sys.stderr, "Current directory looks like cvs."
|
print >>sys.stderr, "Current directory looks like mercurial."
|
||||||
return 1
|
if os.path.isdir('.svn'):
|
||||||
|
print >>sys.stderr, "Current directory looks like svn."
|
||||||
|
if os.path.isdir('CVS'):
|
||||||
|
print >>sys.stderr, "Current directory looks like cvs."
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
print >>sys.stderr, 'Server returned an error:', e
|
print >>sys.stderr, 'Server returned an error:', e
|
||||||
if hasattr(e, 'osc_msg'):
|
if hasattr(e, 'osc_msg'):
|
||||||
@ -116,105 +103,65 @@ def run(prg):
|
|||||||
print >>sys.stderr, e.hdrs
|
print >>sys.stderr, e.hdrs
|
||||||
print >>sys.stderr, body
|
print >>sys.stderr, body
|
||||||
|
|
||||||
if e.code in [ 400, 403, 404, 500 ]:
|
if e.code in [400, 403, 404, 500]:
|
||||||
if '<summary>' in body:
|
if '<summary>' in body:
|
||||||
msg = body.split('<summary>')[1]
|
msg = body.split('<summary>')[1]
|
||||||
msg = msg.split('</summary>')[0]
|
msg = msg.split('</summary>')[0]
|
||||||
print >>sys.stderr, msg
|
print >>sys.stderr, msg
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
except BadStatusLine, e:
|
except BadStatusLine, e:
|
||||||
print >>sys.stderr, 'Server returned an invalid response:', e
|
print >>sys.stderr, 'Server returned an invalid response:', e
|
||||||
print >>sys.stderr, e.line
|
print >>sys.stderr, e.line
|
||||||
return 1
|
|
||||||
|
|
||||||
except HTTPException, e:
|
except HTTPException, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except URLError, e:
|
except URLError, e:
|
||||||
print >>sys.stderr, 'Failed to reach a server:\n', e.reason
|
print >>sys.stderr, 'Failed to reach a server:\n', e.reason
|
||||||
return 1
|
|
||||||
|
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
# ignore broken pipe
|
# ignore broken pipe
|
||||||
if e.errno != errno.EPIPE:
|
if e.errno != errno.EPIPE:
|
||||||
raise
|
raise
|
||||||
return 1
|
|
||||||
|
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except (oscerr.ConfigError, oscerr.NoConfigfile), e:
|
except (oscerr.ConfigError, oscerr.NoConfigfile), e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.OscIOError, e:
|
except oscerr.OscIOError, e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
if getattr(prg.options, 'debug', None) or \
|
if getattr(prg.options, 'debug', None) or \
|
||||||
getattr(prg.conf, 'config', {}).get('debug', None):
|
getattr(prg.conf, 'config', {}).get('debug', None):
|
||||||
print >>sys.stderr, e.e
|
print >>sys.stderr, e.e
|
||||||
return 1
|
|
||||||
|
|
||||||
except (oscerr.WrongOptions, oscerr.WrongArgs), e:
|
except (oscerr.WrongOptions, oscerr.WrongArgs), e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
except oscerr.ExtRuntimeError, e:
|
except oscerr.ExtRuntimeError, e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.WorkingCopyOutdated, e:
|
except oscerr.WorkingCopyOutdated, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except (oscerr.PackageExists, oscerr.PackageMissing, oscerr.WorkingCopyInconsistent), e:
|
except (oscerr.PackageExists, oscerr.PackageMissing, oscerr.WorkingCopyInconsistent), e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.PackageInternalError, e:
|
except oscerr.PackageInternalError, e:
|
||||||
import traceback
|
|
||||||
print >>sys.stderr, 'a package internal error occured\n' \
|
print >>sys.stderr, 'a package internal error occured\n' \
|
||||||
'please file a bug and attach your current package working copy ' \
|
'please file a bug and attach your current package working copy ' \
|
||||||
'and the following traceback to it:'
|
'and the following traceback to it:'
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.PackageError, e:
|
except oscerr.PackageError, e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except PackageError, e:
|
except PackageError, e:
|
||||||
print >>sys.stderr, '%s:' % e.fname, e.msg
|
print >>sys.stderr, '%s:' % e.fname, e.msg
|
||||||
return 1
|
|
||||||
|
|
||||||
except RPMError, e:
|
except RPMError, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except SSLError, e:
|
except SSLError, e:
|
||||||
print >>sys.stderr, "SSL Error:", e
|
print >>sys.stderr, "SSL Error:", e
|
||||||
return 1
|
|
||||||
|
|
||||||
except SSLVerificationError, e:
|
except SSLVerificationError, e:
|
||||||
print >>sys.stderr, "Certificate Verification Error:", e
|
print >>sys.stderr, "Certificate Verification Error:", e
|
||||||
return 1
|
|
||||||
|
|
||||||
except NoSecureSSLError, e:
|
except NoSecureSSLError, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except CpioError, e:
|
except CpioError, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
|
||||||
|
|
||||||
except oscerr.OscBaseError, e:
|
except oscerr.OscBaseError, e:
|
||||||
print >>sys.stderr, '*** Error:', e
|
print >>sys.stderr, '*** Error:', e
|
||||||
|
finally:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# vim: sw=4 et
|
# vim: sw=4 et
|
||||||
|
@ -4,14 +4,17 @@
|
|||||||
# either version 2, or version 3 (at your option).
|
# either version 2, or version 3 (at your option).
|
||||||
|
|
||||||
|
|
||||||
from core import *
|
|
||||||
import cmdln
|
import cmdln
|
||||||
import conf
|
import conf
|
||||||
import oscerr
|
import oscerr
|
||||||
import sys
|
import sys
|
||||||
from util import safewriter
|
import time
|
||||||
|
|
||||||
from optparse import SUPPRESS_HELP
|
from optparse import SUPPRESS_HELP
|
||||||
|
|
||||||
|
from core import *
|
||||||
|
from util import safewriter
|
||||||
|
|
||||||
MAN_HEADER = r""".TH %(ucname)s "1" "%(date)s" "%(name)s %(version)s" "User Commands"
|
MAN_HEADER = r""".TH %(ucname)s "1" "%(date)s" "%(name)s %(version)s" "User Commands"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
%(name)s \- openSUSE build service command-line tool.
|
%(name)s \- openSUSE build service command-line tool.
|
||||||
@ -1964,7 +1967,6 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
return
|
return
|
||||||
|
|
||||||
results.sort(reverse=True)
|
results.sort(reverse=True)
|
||||||
import time
|
|
||||||
days = opts.days or conf.config['request_list_days']
|
days = opts.days or conf.config['request_list_days']
|
||||||
since = ''
|
since = ''
|
||||||
try:
|
try:
|
||||||
|
13
setup.py
13
setup.py
@ -15,6 +15,7 @@ try:
|
|||||||
except:
|
except:
|
||||||
HAVE_PY2EXE = False
|
HAVE_PY2EXE = False
|
||||||
|
|
||||||
|
|
||||||
class build_osc(distutils.command.build.build, object):
|
class build_osc(distutils.command.build.build, object):
|
||||||
"""
|
"""
|
||||||
Custom build command which generates man page.
|
Custom build command which generates man page.
|
||||||
@ -27,9 +28,9 @@ class build_osc(distutils.command.build.build, object):
|
|||||||
man_path = os.path.join('build', 'osc.1.gz')
|
man_path = os.path.join('build', 'osc.1.gz')
|
||||||
distutils.log.info('generating %s' % man_path)
|
distutils.log.info('generating %s' % man_path)
|
||||||
outfile = gzip.open(man_path, 'w')
|
outfile = gzip.open(man_path, 'w')
|
||||||
osccli = commandline.Osc(stdout = outfile)
|
osccli = commandline.Osc(stdout=outfile)
|
||||||
# FIXME: we cannot call the main method because osc expects an ~/.oscrc file
|
# FIXME: we cannot call the main method because osc expects an ~/.oscrc
|
||||||
# (this would break builds in environments like the obs)
|
# file (this would break builds in environments like the obs)
|
||||||
#osccli.main(argv = ['osc','man'])
|
#osccli.main(argv = ['osc','man'])
|
||||||
osccli.optparser = osccli.get_optparser()
|
osccli.optparser = osccli.get_optparser()
|
||||||
osccli.do_man(None)
|
osccli.do_man(None)
|
||||||
@ -43,11 +44,11 @@ addparams = {}
|
|||||||
if HAVE_PY2EXE:
|
if HAVE_PY2EXE:
|
||||||
addparams['console'] = [{'script': 'osc-wrapper.py', 'dest_base': 'osc', 'icon_resources': [(1, 'osc.ico')]}]
|
addparams['console'] = [{'script': 'osc-wrapper.py', 'dest_base': 'osc', 'icon_resources': [(1, 'osc.ico')]}]
|
||||||
addparams['zipfile'] = 'shared.lib'
|
addparams['zipfile'] = 'shared.lib'
|
||||||
addparams['options'] = {'py2exe': { 'optimize': 0, 'compressed': True, 'packages': ['xml.etree', 'StringIO', 'gzip'] }}
|
addparams['options'] = {'py2exe': {'optimize': 0, 'compressed': True, 'packages': ['xml.etree', 'StringIO', 'gzip']}}
|
||||||
|
|
||||||
data_files = []
|
data_files = []
|
||||||
if sys.platform[:3] != 'win':
|
if sys.platform[:3] != 'win':
|
||||||
data_files.append((os.path.join('share','man','man1'), [os.path.join('build', 'osc.1.gz')]))
|
data_files.append((os.path.join('share', 'man', 'man1'), [os.path.join('build', 'osc.1.gz')]))
|
||||||
|
|
||||||
setup(name='osc',
|
setup(name='osc',
|
||||||
version = osc.core.__version__,
|
version = osc.core.__version__,
|
||||||
@ -56,7 +57,7 @@ setup(name='osc',
|
|||||||
author = 'openSUSE project',
|
author = 'openSUSE project',
|
||||||
author_email = 'opensuse-buildservice@opensuse.org',
|
author_email = 'opensuse-buildservice@opensuse.org',
|
||||||
license = 'GPL',
|
license = 'GPL',
|
||||||
platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME'],
|
platforms = ['Linux', 'Mac OSX', 'Windows XP/2000/NT', 'Windows 95/98/ME'],
|
||||||
keywords = ['openSUSE', 'SUSE', 'RPM', 'build', 'buildservice'],
|
keywords = ['openSUSE', 'SUSE', 'RPM', 'build', 'buildservice'],
|
||||||
url = 'http://en.opensuse.org/openSUSE:OSC',
|
url = 'http://en.opensuse.org/openSUSE:OSC',
|
||||||
download_url = 'http://gitorious.org/opensuse/osc',
|
download_url = 'http://gitorious.org/opensuse/osc',
|
||||||
|
Loading…
Reference in New Issue
Block a user