diff options
| author | Martin Pihlak | 2009-02-17 15:16:54 +0000 |
|---|---|---|
| committer | Martin Pihlak | 2009-02-17 15:16:54 +0000 |
| commit | 86bcfce26f1f13b18bf92142d8bcad4410ae08e7 (patch) | |
| tree | df89d3c6f1a023ca7cf3a116067b8bb9c576bcef /python/skytools | |
| parent | 94c0a70775f18c109c38f95ba4e34bac29fa5faf (diff) | |
| parent | 12ce61de6b7dac644cc3474bc9b83382031117ab (diff) | |
Merge branch 'master' of git://github.com/markokr/skytools-dev
Diffstat (limited to 'python/skytools')
| -rw-r--r-- | python/skytools/scripting.py | 29 | ||||
| -rw-r--r-- | python/skytools/sqltools.py | 10 |
2 files changed, 31 insertions, 8 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. diff --git a/python/skytools/sqltools.py b/python/skytools/sqltools.py index fd4fb855..2dee2cc1 100644 --- a/python/skytools/sqltools.py +++ b/python/skytools/sqltools.py @@ -9,7 +9,7 @@ import skytools.installer_config __all__ = [ "fq_name_parts", "fq_name", "get_table_oid", "get_table_pkeys", "get_table_columns", "exists_schema", "exists_table", "exists_type", - "exists_sequence", + "exists_sequence", "exists_temp_table", "exists_function", "exists_language", "Snapshot", "magic_insert", "CopyPipe", "full_copy", "DBObject", "DBSchema", "DBTable", "DBFunction", "DBLanguage", "db_install", "installer_find_file", "installer_apply_file", @@ -149,6 +149,14 @@ def exists_language(curs, lang_name): res = curs.fetchone() return res[0] +def exists_temp_table(curs, tbl): + """Does temp table exists?""" + # correct way, works only on 8.2 + q = "select 1 from pg_class where relname = %s and relnamespace = pg_my_temp_schema()" + curs.execute(q, [tbl]) + tmp = curs.fetchall() + return len(tmp) > 0 + # # Support for PostgreSQL snapshot # |
