def createStep(self, id="", action="", app="", device="", input={}, next=[], errors=[]): # Creates new step object input = { input[key]["tag"]: arguments.Argument(key=input[key]["tag"], value=input[key]["value"], format=input[key]["format"]) for key in input } ancestry = list(self.ancestry) ancestry.append(id) self.steps[id] = Step(name=id, action=action, app=app, device=device, input=input, next=next, errors=errors, ancestry=ancestry, parent_name=self.name) stepXML = self.steps[id].to_xml() self.workflowXML.find(".//steps").append(stepXML)
def _update_xml(self, step_xml): self.action = step_xml.find('action').text self.app = step_xml.find('app').text device_field = step_xml.find('device') self.device = device_field.text if device_field is not None else '' risk_field = step_xml.find('risk') self.risk = int(risk_field.text) if risk_field is not None else 0 self.input = { arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get('format')) for arg in step_xml.findall('input/*') } self.conditionals = [ nextstep.NextStep(xml=next_step_element, parent_name=self.name, ancestry=self.ancestry) for next_step_element in step_xml.findall('next') ] self.errors = [ nextstep.NextStep(xml=error_step_element, parent_name=self.name, ancestry=self.ancestry) for error_step_element in step_xml.findall('error') ]
def __init__(self, xml=None, parent_name='', action='', args=None, ancestry=None): if xml: self._from_xml(xml, parent_name, ancestry) else: ExecutionElement.__init__(self, name=action, parent_name=parent_name, ancestry=ancestry) self.action = action args = args if args is not None else {} self.args = { arg_name: arguments.Argument(key=arg_name, value=arg_value, format=type(arg_value).__name__) for arg_name, arg_value in args.items() } super(Filter, self)._register_event_callbacks({ 'FilterSuccess': callbacks.add_filter_entry('Filter success'), 'FilterError': callbacks.add_filter_entry('Filter error') })
def _from_xml(self, xml_element, parent_name='', ancestry=None): self.action = xml_element.get("action") ExecutionElement.__init__(self, name=self.action, parent_name=parent_name, ancestry=ancestry) self.args = {arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get("format")) for arg in xml_element.findall("args/*")} self.filters = [Filter(xml=filter_element, parent_name=self.name, ancestry=self.ancestry) for filter_element in xml_element.findall("filters/*")]
def _from_xml(self, xml_element, parent_name=None, ancestry=None): self.action = xml_element.get('action') ExecutionElement.__init__(self, name=self.action, parent_name=parent_name, ancestry=ancestry) args = { arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get("format")) for arg in xml_element.findall("args/*") } self.args = { arg: arguments.Argument(key=arg, value=args[arg], format=type(args[arg]).__name__) for arg in args }
def _update_xml(self, step_xml): self.action = step_xml.find("action").text self.app = step_xml.find("app").text self.device = step_xml.find("device").text self.input = {arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get("format")) for arg in step_xml.findall("input/*")} self.conditionals = [nextstep.NextStep(xml=next_step_element, parent_name=self.name, ancestry=self.ancestry) for next_step_element in step_xml.findall("next")] self.errors = [nextstep.NextStep(xml=error_step_element, parent_name=self.name, ancestry=self.ancestry) for error_step_element in step_xml.findall("error")]
def _from_xml(self, step_xml, parent_name='', ancestry=None): name = step_xml.get("id") ExecutionElement.__init__(self, name=name, parent_name=parent_name, ancestry=ancestry) self.action = step_xml.find("action").text self.app = step_xml.find("app").text self.device = step_xml.find("device").text self.input = {arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get("format")) for arg in step_xml.findall("input/*")} self.conditionals = [nextstep.NextStep(xml=next_step_element, parent_name=self.name, ancestry=self.ancestry) for next_step_element in step_xml.findall("next")] self.errors = [nextstep.NextStep(xml=error_step_element, parent_name=self.name, ancestry=self.ancestry) for error_step_element in step_xml.findall("error")]
def create_step(self, name='', action='', app='', device='', arg_input=None, next_steps=None, errors=None, risk=0): arg_input = arg_input if arg_input is not None else {} next_steps = next_steps if next_steps is not None else [] errors = errors if errors is not None else [] # Creates new step object arg_input = {arg['tag']: arguments.Argument(key=arg['tag'], value=arg['value'], format=arg['format']) for key, arg in arg_input.items()} ancestry = list(self.ancestry) self.steps[name] = Step(name=name, action=action, app=app, device=device, inputs=arg_input, next_steps=next_steps, errors=errors, ancestry=ancestry, parent_name=self.name, risk=risk) self.total_risk += risk
def _from_xml(self, xml_element, parent_name=None, ancestry=None): self.action = xml_element.get('action') ExecutionElement.__init__(self, name=self.action, parent_name=parent_name, ancestry=ancestry) self.args = { arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get('format')) for arg in xml_element.findall('args/*') }
def create_step(self, name='', action='', app='', device='', arg_input=None, next_steps=None, errors=None, risk=0): """Creates a new Step object and adds it to the Workflow's list of Steps. Args: name (str, optional): The name of the Step object. Defaults to an empty string. action (str, optional): The name of the action associated with a Step. Defaults to an empty string. app (str, optional): The name of the app associated with the Step. Defaults to an empty string. device (str, optional): The name of the device associated with the app associated with the Step. Defaults to an empty string. arg_input (dict, optional): A dictionary of Argument objects that are input to the step execution. Defaults to None. next_steps (list[NextStep], optional): A list of NextStep objects for the Step object. Defaults to None. errors (list[NextStep], optional): A list of NextStep error objects for the Step object. Defaults to None. risk (int, optional): The risk associated with the Step. Defaults to 0. """ arg_input = arg_input if arg_input is not None else {} next_steps = next_steps if next_steps is not None else [] errors = errors if errors is not None else [] # Creates new step object arg_input = { arg['tag']: arguments.Argument(key=arg['tag'], value=arg['value'], format=arg['format']) for key, arg in arg_input.items() } ancestry = list(self.ancestry) self.steps[name] = Step(name=name, action=action, app=app, device=device, inputs=arg_input, next_steps=next_steps, errors=errors, ancestry=ancestry, parent_name=self.name, risk=risk) self.total_risk += risk logger.info('Step added to workflow {0}. Step: {1}'.format( self.ancestry, self.steps[name].as_json()))
def _from_xml(self, step_xml, parent_name='', ancestry=None): name = step_xml.get('id') ExecutionElement.__init__(self, name=name, parent_name=parent_name, ancestry=ancestry) self.action = step_xml.find('action').text self.app = step_xml.find('app').text device_field = step_xml.find('device') self.device = device_field.text if device_field is not None else '' risk_field = step_xml.find('risk') self.risk = int(risk_field.text) if risk_field is not None else 0 self.input = { arg.tag: arguments.Argument(key=arg.tag, value=arg.text, format=arg.get('format')) for arg in step_xml.findall('input/*') } self.conditionals = [ nextstep.NextStep(xml=next_step_element, parent_name=self.name, ancestry=self.ancestry) for next_step_element in step_xml.findall('next') ] self.errors = [ nextstep.NextStep(xml=error_step_element, parent_name=self.name, ancestry=self.ancestry) for error_step_element in step_xml.findall('error') ] self.widgets = [ _Widget(widget.get('app'), widget.text) for widget in step_xml.findall('widgets/*') ] position = step_xml.find('position') if position is None: self.position = {} else: x_position = position.find('x') y_position = position.find('y') if x_position is not None and y_position is not None: self.position = {'x': x_position.text, 'y': y_position.text} else: self.position = {}
def __init__(self, xml=None, parent_name='', action='', args=None, ancestry=None): """Initializes a new Filter object. A Filter is used to filter input into a workflow. Args: xml (cElementTree, optional): The XML element tree object. Defaults to None. parent_name (str, optional): The name of the parent for ancestry purposes. Defaults to an empty string. action (str, optional): The action name for the filter. Defaults to an empty string. args (dict[str:str], optional): Dictionary of Argument keys to Argument values. This dictionary will be converted to a dictionary of str:Argument. Defaults to None. ancestry (list[str], optional): The ancestry for the Filter object. Defaults to None. """ if xml: self._from_xml(xml, parent_name, ancestry) else: ExecutionElement.__init__(self, name=action, parent_name=parent_name, ancestry=ancestry) self.action = action args = args if args is not None else {} self.args = {arg_name: arguments.Argument(key=arg_name, value=arg_value, format=type(arg_value).__name__) for arg_name, arg_value in args.items()}
def __init__(self, xml=None, parent_name='', action='', args=None, ancestry=None): if xml: self._from_xml(xml, parent_name, ancestry) else: ExecutionElement.__init__(self, name=action, parent_name=parent_name, ancestry=ancestry) self.action = action args = args if args is not None else {} self.args = { arg_name: arguments.Argument(key=arg_name, value=arg_value, format=type(arg_value).__name__) for arg_name, arg_value in args.items() }
def test_workflowInput(self): arg = arguments.Argument(key="call", value="Hello World", format="string")
def test_workflowInput(self): arg = arguments.Argument(key='call', value='Hello World', format='string')