示例#1
0
文件: worker.py 项目: F-Secure/murphy
    def _load_modules(self, model, images_dir):
        '''
        Loads the model and create the internal objects accordingly
        '''
        module_list = model['modules']
        package = model['namespace']
        if images_dir:
            images_folder = images_dir
        else:
            images_folder = model['images dir']
        
        for i in range(len(module_list)):
            name = package + "." + module_list[i]
            mod = __import__(name)
            mod = sys.modules[name]
            if is_valid_module(mod):
                if mod.HERE['desc'] in self._views:
                    raise Exception("More than one module contains the same " +
                                    "description: " + mod.HERE['desc'])
                module_dict = dict()
                module_dict['self'] = mod
                module_dict['verbs'] = list_verbs(mod)
                self._views[mod.HERE['desc']] = module_dict
                mod.worker = self
                mod.WORKER = self

        self._navigator = Navigator(self._views)
        #WARN: executor uses navigator so it must be created before
        #this needs a bit of refactoring
        self._executor = Executor(model['global timeout'],
                                  images_folder,
                                  self)
        self._executor.navigator_executor.set_context_setter(self.In)
        self._graphs = Graphs(self._views)
示例#2
0
    def _load_modules(self, model, images_dir):
        '''
        Loads the model and create the internal objects accordingly
        '''
        module_list = model['modules']
        package = model['namespace']
        if images_dir:
            images_folder = images_dir
        else:
            images_folder = model['images dir']

        for i in range(len(module_list)):
            name = package + "." + module_list[i]
            mod = __import__(name)
            mod = sys.modules[name]
            if is_valid_module(mod):
                if mod.HERE['desc'] in self._views:
                    raise Exception("More than one module contains the same " +
                                    "description: " + mod.HERE['desc'])
                module_dict = dict()
                module_dict['self'] = mod
                module_dict['verbs'] = list_verbs(mod)
                self._views[mod.HERE['desc']] = module_dict
                mod.worker = self
                mod.WORKER = self

        self._navigator = Navigator(self._views)
        #WARN: executor uses navigator so it must be created before
        #this needs a bit of refactoring
        self._executor = Executor(model['global timeout'], images_folder, self)
        self._executor.navigator_executor.set_context_setter(self.In)
        self._graphs = Graphs(self._views)
示例#3
0
文件: worker.py 项目: F-Secure/murphy
    def load_application(self, package, file_name, img_folder=None):
        '''
        Loads a modeled application in the given package space.
        The file that describes the application is a simple json array that
        lists the modules that models each view of the application, for example
        ["view1", "view2", "view3", "view4"]
        The package parameter is the package space where it will be loaded,
        usually follows the directory structure relative from the murphy
        directory.
        Example:
        >>> worker = Worker()
        >>> worker.load_application('self_test.app5',
        ... r'murphy\\self_test\\app5\\app5.json')
        '''
        model = load_json_object(file_name)
        module_list = model
        if type(module_list) is dict:
            module_list = module_list['modules']

        for i in range(len(module_list)):
            try:
                name = package + "." + module_list[i]
                mod = __import__(name)
                mod = sys.modules[name]
                if is_valid_module(mod):
                    if mod.HERE['desc'] in self._views:
                        raise Exception("More than one module contains the "
                                        "same description: " + mod.HERE['desc'])
                    module_dict = dict()
                    module_dict['self'] = mod
                    module_dict['verbs'] = list_verbs(mod)
                    self._views[mod.HERE['desc']] = module_dict
                    mod.worker = self
                    mod.WORKER = self
            except Exception:
                print "Unexpected error while loading module %s" % name
                raise
            
        self._navigator = Navigator(self._views)
        general_timeout = GLOBAL_TIMEOUT
        if type(model) is dict:
            if 'global timeout' in model:
                general_timeout = model['global timeout']
        self._executor = Executor(general_timeout,
                                  img_folder,
                                  self)
        self._executor.navigator_executor.set_context_setter(self.In)
        self._graphs = Graphs(self._views)
示例#4
0
    def load_application(self, package, file_name, img_folder=None):
        '''
        Loads a modeled application in the given package space.
        The file that describes the application is a simple json array that
        lists the modules that models each view of the application, for example
        ["view1", "view2", "view3", "view4"]
        The package parameter is the package space where it will be loaded,
        usually follows the directory structure relative from the murphy
        directory.
        Example:
        >>> worker = Worker()
        >>> worker.load_application('self_test.app5',
        ... r'murphy\\self_test\\app5\\app5.json')
        '''
        model = load_json_object(file_name)
        module_list = model
        if type(module_list) is dict:
            module_list = module_list['modules']

        for i in range(len(module_list)):
            try:
                name = package + "." + module_list[i]
                mod = __import__(name)
                mod = sys.modules[name]
                if is_valid_module(mod):
                    if mod.HERE['desc'] in self._views:
                        raise Exception("More than one module contains the "
                                        "same description: " +
                                        mod.HERE['desc'])
                    module_dict = dict()
                    module_dict['self'] = mod
                    module_dict['verbs'] = list_verbs(mod)
                    self._views[mod.HERE['desc']] = module_dict
                    mod.worker = self
                    mod.WORKER = self
            except Exception:
                print "Unexpected error while loading module %s" % name
                raise

        self._navigator = Navigator(self._views)
        general_timeout = GLOBAL_TIMEOUT
        if type(model) is dict:
            if 'global timeout' in model:
                general_timeout = model['global timeout']
        self._executor = Executor(general_timeout, img_folder, self)
        self._executor.navigator_executor.set_context_setter(self.In)
        self._graphs = Graphs(self._views)