diff options
author | Marko Kreen | 2009-02-16 17:55:39 +0000 |
---|---|---|
committer | Marko Kreen | 2009-02-17 15:02:20 +0000 |
commit | 8aa404b2468fc075083c6a1afbf87c865b9f4f32 (patch) | |
tree | 1c5c8374ce229e7e8535ab535055dc5664b0e4da /python/skytools/scripting.py | |
parent | 869638cccf1481c1ff71c23963e830d88793ac36 (diff) |
New UsageError exception class.
When thrown, the DBScript will just print the error message,
without traceback and any additional noise
To be used to show user simple error messages.
Can be used to build own Exception classes.
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r-- | python/skytools/scripting.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py index a61154de..4d45107f 100644 --- a/python/skytools/scripting.py +++ b/python/skytools/scripting.py @@ -25,9 +25,13 @@ I_READ_COMMITTED = 1 I_SERIALIZABLE = 2 __all__ = ['DBScript', 'I_AUTOCOMMIT', 'I_READ_COMMITTED', 'I_SERIALIZABLE', - 'signal_pidfile'] + 'signal_pidfile', 'UsageError'] #__all__ += ['daemonize', 'run_single_process'] +class UsageError(Exception): + """User induced error.""" + pass + # # utils # @@ -386,6 +390,9 @@ class DBScript(object): try: run_single_process(self, self.go_daemon, self.pidfile) + except UsageError, ex: + self.log.error(str(ex)) + sys.exit(1) except KeyboardInterrupt: raise except SystemExit: @@ -499,6 +506,9 @@ class DBScript(object): # run startup, safely try: self.startup() + except UsageError, ex: + self.log.error(str(ex)) + sys.exit(1) except KeyboardInterrupt: raise except SystemExit: @@ -546,6 +556,9 @@ class DBScript(object): "Run users work function, safely." try: return self.work() + except UsageError, ex: + self.log.error(str(ex)) + # should we exit here? except SystemExit, d: self.send_stats() self.log.info("got SystemExit(%s), exiting" % str(d)) @@ -562,12 +575,14 @@ class DBScript(object): del tb self.log.exception("Job %s crashed: %s: %s" % ( self.job_name, str(exc), str(msg).rstrip())) - self.reset() - if self.looping and not self.do_single_loop: - time.sleep(20) - return 1 - else: - sys.exit(1) + + # reset and sleep + self.reset() + if self.looping and not self.do_single_loop: + time.sleep(20) + return 1 + else: + sys.exit(1) def work(self): """Here should user's processing happen. |