Exemplo n.º 1
0
    def extract_actions(self, action_names, event):
        """
        This method is used to extract all actions that trigger a given event.
        If an Action has already been stored in the database it is retrieved 
        otherwise a new Action object is created.

        @param action_names: A list containing all actions associtated to a specific event.
        @type action_names: list of strings
        @param event: event triggered by the actions
        @type event: Event object
        @return: A list of Event objects associated to the considered script.
        @rtype: list of Event
        """
        action_list = []
        # extract the list of action identifiers
        for action in action_names:
            action = action.replace(' ', '')
            if(len(action) == 0):
                continue

	    

            if(Event.objects.get(pk = event.id).action_set.filter(path_abs = action).count() == 0):
                if(Action.objects.filter(path_abs = action).count() == 0):
                    # save the action if it doesn't exist                    
                    a = Action(path_abs=action)
                    a.save()
                    a.events.add(event)
                else:
                    a = Action.objects.get(path_abs=action)
                    a.events.add(event)                    
            # check if the action had been associated to multiple events
            else:               
                continue

        # retrieve the saved action
        action_list.append(Action.objects.get(path_abs = action))
        return action_list
Exemplo n.º 2
0
Arquivo: tests.py Projeto: crs4/ACTIVE
def create_action(event_id=1):
    action = Action()
    action.path_abs = 'org.my.module.test'
    action.event = Event.objects.get(pk=event_id)
    action.save()
    return action