mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 22:56:15 +01:00
Simplify how babysitter works with options and config
This commit is contained in:
parent
8ea24b1a3c
commit
f7c84d42a3
@ -18,6 +18,7 @@ import urllib3.exceptions
|
|||||||
|
|
||||||
from . import _private
|
from . import _private
|
||||||
from . import commandline
|
from . import commandline
|
||||||
|
from . import conf as osc_conf
|
||||||
from . import oscerr
|
from . import oscerr
|
||||||
from .OscConfigParser import configparser
|
from .OscConfigParser import configparser
|
||||||
from .oscssl import CertVerificationError
|
from .oscssl import CertVerificationError
|
||||||
@ -52,19 +53,20 @@ for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
|
|||||||
def run(prg, argv=None):
|
def run(prg, argv=None):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
if '--debugger' in sys.argv:
|
# we haven't parsed options yet, that's why we rely on argv directly
|
||||||
|
if "--debugger" in (argv or sys.argv[1:]):
|
||||||
pdb.set_trace()
|
pdb.set_trace()
|
||||||
# here we actually run the program:
|
# here we actually run the program
|
||||||
return prg.main(argv)
|
return prg.main(argv)
|
||||||
except:
|
except:
|
||||||
# look for an option in the prg.options object and in the config
|
# If any of these was set via the command-line options,
|
||||||
# dict print stack trace, if desired
|
# the config values are expected to be changed accordingly.
|
||||||
if getattr(prg.options, 'traceback', None) or getattr(prg.conf, 'config', {}).get('traceback', None) or \
|
# That's why we're working only with the config.
|
||||||
getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
|
if osc_conf.config["traceback"] or osc_conf.config["post_mortem"]:
|
||||||
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 osc_conf.config["post_mortem"]:
|
||||||
if sys.stdout.isatty() and not hasattr(sys, 'ps1'):
|
if sys.stdout.isatty() and not hasattr(sys, 'ps1'):
|
||||||
pdb.post_mortem(sys.exc_info()[2])
|
pdb.post_mortem(sys.exc_info()[2])
|
||||||
else:
|
else:
|
||||||
@ -104,8 +106,7 @@ def run(prg, argv=None):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
body = ''
|
body = ''
|
||||||
|
|
||||||
if getattr(prg.options, 'debug', None) or \
|
if osc_conf.config["debug"]:
|
||||||
getattr(prg.conf, 'config', {}).get('debug', None):
|
|
||||||
print(e.hdrs, file=sys.stderr)
|
print(e.hdrs, file=sys.stderr)
|
||||||
print(body, file=sys.stderr)
|
print(body, file=sys.stderr)
|
||||||
|
|
||||||
@ -151,8 +152,7 @@ def run(prg, argv=None):
|
|||||||
print(e.message, file=sys.stderr)
|
print(e.message, file=sys.stderr)
|
||||||
except oscerr.OscIOError as e:
|
except oscerr.OscIOError as e:
|
||||||
print(e.msg, file=sys.stderr)
|
print(e.msg, file=sys.stderr)
|
||||||
if getattr(prg.options, 'debug', None) or \
|
if osc_conf.config["debug"]:
|
||||||
getattr(prg.conf, 'config', {}).get('debug', None):
|
|
||||||
print(e.e, file=sys.stderr)
|
print(e.e, file=sys.stderr)
|
||||||
except (oscerr.WrongOptions, oscerr.WrongArgs) as e:
|
except (oscerr.WrongOptions, oscerr.WrongArgs) as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user