def process(self, event): if not isinstance(event, dict): raise ValueError( "Expected event of type dict, got one of type %s" % (type(event), )) # We want the bindings in the event to override those in the static # dict, so we make of copy of the static dict and update the copy with # the event bindings = dict(self._static_variable_dict) bindings.update(event) command_args = self._make_command_sequence(bindings) # This will throw with a useful error message if the command can't be # run or if it runs and fails. if self.notify_stream: note = '[' + timestamp.get_timestamp() + '] Starting: ' + ' '.join( command_args) + '\n' self.notify_stream.write(note) (self._last_stdout_output, self._last_stderr_output, self._last_command_line) = process.subprocess(command_args) # If we got here, the subprocess finished successfully. if self.notify_stream: note = '[' + timestamp.get_timestamp() + '] Finished: ' + ' '.join( command_args) + '\n' self.notify_stream.write(note) self.send(event)
def process(self, event): if not isinstance(event, dict): raise ValueError("Expected event of type dict, got one of type %s" % (type(event),)) # We want the bindings in the event to override those in the static # dict, so we make of copy of the static dict and update the copy with # the event bindings = dict(self._static_variable_dict) bindings.update(event) command_args = self._make_command_sequence(bindings) # This will throw with a useful error message if the command can't be # run or if it runs and fails. if self.notify_stream: note = '[' + timestamp.get_timestamp() + '] Starting: ' + ' '.join(command_args) + '\n' self.notify_stream.write(note) (self._last_stdout_output, self._last_stderr_output, self._last_command_line) = process.subprocess(command_args) # If we got here, the subprocess finished successfully. if self.notify_stream: note = '[' + timestamp.get_timestamp() + '] Finished: ' + ' '.join(command_args) + '\n' self.notify_stream.write(note) self.send(event)
def dprint(key, *things): """ Print str(key) +": " + str(thing[0]) + ' ' + str(thing[1]) + ... if key is active in DebugPrint. Output goes to the stream associated with key which is sys.stdout by default. If thing[0] is DebugPrint.NO_PREFIX, suppress both str(key) and the colon-space. If thing[0] is DebugPrint.NEWLINE_PREFIX, write a newline before the usual output; this is useful for setting off a block of debug printing. See help(DebugPrint) for documentation on how to activate keys and how to change the stream associated with a key. >>> with DebugPrint('HI'): ... dprint('HI', "Hello,", "World!") HI: Hello, World! >>> with DebugPrint('HI'): ... dprint('HI', DebugPrint.NO_PREFIX, "Hello") Hello Turning off the prefix includes turning off timestamps if they were turned on: >>> with DebugPrint(DebugPrint.TIMESTAMP_ON, 'HI'): ... dprint('HI', DebugPrint.NO_PREFIX, "Hello") Hello >>> with DebugPrint('HI'): ... dprint('HI', DebugPrint.NEWLINE_PREFIX, "World!") <BLANKLINE> HI: World! A newline is printed before the prefix, including the timestamp if there is one: >>> with DebugPrint(DebugPrint.TIMESTAMP_ON, 'HI'): #doctest: +ELLIPSIS ... dprint('HI', DebugPrint.NEWLINE_PREFIX, "World!") <BLANKLINE> [20...] HI: World! """ if len(things) == 0: return if DebugPrint.active(key): outs = list() (stream, use_timestamp) = DebugPrint.get_stream(key) thingiter = iter(things) thing0 = things[0] if thing0 is DebugPrint.NO_PREFIX: thingiter.next() else: if thing0 is DebugPrint.NEWLINE_PREFIX: thingiter.next() outs.append('\n') if use_timestamp: outs.append('[' + timestamp.get_timestamp() + '] ') prefix = str(key), ': ' outs.extend(prefix) outs.append(' '.join(str(thing) for thing in thingiter)) outs.append('\n') stream.write(''.join(outs)) # may want to give a control for this flush stream.flush()