2 # -*- coding: utf-8 -*- vim: set ts=4 et sw=4 fdm=indent :
8 sys.stderr.write('Unable to load simplejson python module.')
11 class MCollectiveActionNoEnv(Exception):
13 class MCollectiveActionFileError(Exception):
16 class MCollectiveAction(object):
17 def __init__(self, *args, **kwargs):
19 self.infile = os.environ['MCOLLECTIVE_REQUEST_FILE']
21 raise MCollectiveActionNoEnv("No MCOLLECTIVE_REQUEST_FILE environment variable")
23 self.outfile = os.environ['MCOLLECTIVE_REPLY_FILE']
25 raise MCollectiveActionNoEnv("No MCOLLECTIVE_REPLY_FILE environment variable")
36 infile = open(self.infile, 'r')
37 self.request = simplejson.load(infile)
40 raise MCollectiveActionFileError("Could not read request file `%s`: %s" % (self.infile, e))
41 except simplejson.JSONDecodeError, e:
43 raise MCollectiveActionFileError("Could not parse JSON data in file `%s`: %s", (self.infile, e))
46 if not getattr(self, 'outfile', None): # if exception was raised during or before setting self.outfile
49 outfile = open(self.outfile, 'w')
50 simplejson.dump(self.reply, outfile)
53 raise MCollectiveActionFileError("Could not write reply file `%s`: %s" % (self.outfile, e))
56 """Prints line to STDERR that will be logged at error level in the mcollectived log file"""
57 sys.stderr.write("%s\n" % msg)
60 """Logs error message and exitst with RPCAborted"""
65 """Prints line to STDOUT that will be logged at info level in the mcollectived log file"""
66 sys.stdout.write("%s\n" % msg)