Beispiel #1
0
def remove_model_from_workbench(model_name):
    '''
    Adds the given model to the list of models in the config file
    '''
    this_dir = os.path.abspath(os.path.dirname(__file__))
    models = load_json_object(this_dir + '/projects.json')
    this_model = { 'file': model_name }
    if this_model in models:
        models.remove(this_model)
        encoded = json.dumps(models, sort_keys=True, indent=2)
        with open(this_dir + '/projects.json', "w") as the_file:
            the_file.write(encoded)
Beispiel #2
0
def remove_model_from_workbench(model_name):
    '''
    Adds the given model to the list of models in the config file
    '''
    this_dir = os.path.abspath(os.path.dirname(__file__))
    models = load_json_object(this_dir + '/projects.json')
    this_model = {'file': model_name}
    if this_model in models:
        models.remove(this_model)
        encoded = json.dumps(models, sort_keys=True, indent=2)
        with open(this_dir + '/projects.json', "w") as the_file:
            the_file.write(encoded)
Beispiel #3
0
 def load_memory(self):
     '''
     Loads the search cache from a file, if file name is None the method
     returns silently but will log a warning
     '''
     self._results_cache = dict()
     if self._memory_file_name is None:
         LOGGER.warning("Trying to load memory when no file was specified")
         return
     if os.path.isfile(self._memory_file_name) == False:
         LOGGER.warning("Memory file %s not found" % self._memory_file_name)
         return
     
     self._results_cache = utils.load_json_object(self._memory_file_name)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
0
    def __init__(self, file_name, load_modules=True):
        self._model = utils.load_json_object(file_name)
        if not 'coverage' in self._model:
            self._model['coverage'] = 'coverage.json'
        self._file_name = file_name
        self._working_dir = os.path.dirname(file_name)
        
        self.current_view = None
        self.tags = dict()

        if 'business rules' in self._model and load_modules:
            name = "%s.%s" % (self._model['namespace'],
                              self._model['business rules'])
            full_path = os.path.abspath(file_name)
            base_dir = os.path.dirname(os.path.dirname(os.path.dirname(full_path)))
            # Normally the rules file is 2 dirs deeper than the model dir
            if not base_dir in sys.path:
                # print "Adding %s to pythonpath" % base_dir
                sys.path.append(base_dir)
            __import__(name)
            self._rules_module = sys.modules[name]
        else:
            self._rules_module = None
Beispiel #7
0
    def __init__(self, file_name, load_modules=True):
        self._model = utils.load_json_object(file_name)
        if not 'coverage' in self._model:
            self._model['coverage'] = 'coverage.json'
        self._file_name = file_name
        self._working_dir = os.path.dirname(file_name)

        self.current_view = None
        self.tags = dict()

        if 'business rules' in self._model and load_modules:
            name = "%s.%s" % (self._model['namespace'],
                              self._model['business rules'])
            full_path = os.path.abspath(file_name)
            base_dir = os.path.dirname(
                os.path.dirname(os.path.dirname(full_path)))
            # Normally the rules file is 2 dirs deeper than the model dir
            if not base_dir in sys.path:
                # print "Adding %s to pythonpath" % base_dir
                sys.path.append(base_dir)
            __import__(name)
            self._rules_module = sys.modules[name]
        else:
            self._rules_module = None