summaryrefslogtreecommitdiffstats
path: root/func/utils.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-01-29 16:19:30 -0500
committerMichael DeHaan <mdehaan@redhat.com>2008-01-29 16:19:30 -0500
commitb3c5591d70c1c354d14267e804ab64872af97b40 (patch)
treea361f4d0ea060df23ffbccf9961f38bb01a65d23 /func/utils.py
parent1d60f197dab809e9a51c3377587d46370e698c52 (diff)
downloadfunc-b3c5591d70c1c354d14267e804ab64872af97b40.tar.gz
func-b3c5591d70c1c354d14267e804ab64872af97b40.tar.xz
func-b3c5591d70c1c354d14267e804ab64872af97b40.zip
All exceptions, async or otherwise, now come back as easily detectable signatures. Use utils.is_error(result)
to determine if something is an error or isn't. Example scripts as well as func-inventory have been updated. See async_test.py for examples.
Diffstat (limited to 'func/utils.py')
-rwxr-xr-xfunc/utils.py58
1 files changed, 20 insertions, 38 deletions
diff --git a/func/utils.py b/func/utils.py
index c2fbb9f..1a4abb7 100755
--- a/func/utils.py
+++ b/func/utils.py
@@ -16,17 +16,13 @@ import sys
import traceback
import xmlrpclib
-REMOTE_CANARY = "***REMOTE_ERROR***"
+REMOTE_ERROR = "REMOTE_ERROR"
-# this is kind of handy, so keep it around for now
-# but we really need to fix out server side logging and error
-# reporting so we don't need it
def trace_me():
x = traceback.extract_stack()
bar = string.join(traceback.format_list(x))
return bar
-
def daemonize(pidfile=None):
"""
Daemonize this process with the UNIX double-fork trick.
@@ -41,41 +37,27 @@ def daemonize(pidfile=None):
os.umask(0)
pid = os.fork()
-
if pid > 0:
if pidfile is not None:
open(pidfile, "w").write(str(pid))
sys.exit(0)
-def remove_exceptions(results):
- """
- Used by forkbomb/jobthing to avoid storing exceptions in database
- because you know those don't serialize so well :)
- # FIXME: this needs cleanup
- """
-
- if results is None:
- return REMOTE_CANARY
-
- if str(results).startswith("<Fault"):
- return REMOTE_CANARY
-
- if type(results) == xmlrpclib.Fault:
- return REMOTE_CANARY
-
- if type(results) == dict:
- new_results = {}
- for x in results.keys():
- value = results[x]
- if str(value).find("<Fault") == -1:
- # there are interesting issues with the way it is imported and type()
- # so that is why this hack is here. type(x) != xmlrpclib.Fault appears to miss some things
- new_results[x] = value
- else:
- new_results[x] = REMOTE_CANARY
- return new_results
-
- return results
-
-
-
+def nice_exception(etype, evalue, etb):
+ etype = str(etype)
+ lefti = etype.index("'") + 1
+ righti = etype.rindex("'")
+ nicetype = etype[lefti:righti]
+ nicestack = string.join(traceback.format_list(traceback.extract_tb(etb)))
+ return [ REMOTE_ERROR, nicetype, str(evalue), nicestack ]
+
+def is_error(result):
+ if type(result) != list:
+ return False
+ if len(result) == 0:
+ return False
+ if result[0] == REMOTE_ERROR:
+ return True
+ return False
+
+
+