Exemplo n.º 1
0
    def __init__(self, global_conf=CoreConfig()):
        """
        Initializes a DataStore object
        """
        # dictionary {backend_name_string: Backend instance}
        self.backends = {}
        self.treefactory = TreeFactory()
        self._tasks = self.treefactory.get_tasks_tree()
        self.requester = requester.Requester(self, global_conf)
        self.tagfile_loaded = False
        self._tagstore = self.treefactory.get_tags_tree(self.requester)
        self.load_tag_tree()
        self._backend_signals = BackendSignals()

        # Flag when turned to true, all pending operation should be
        # completed and then GTG should quit
        self.please_quit = False

        # The default backend must be loaded first. This flag turns to True
        # when the default backend loading has finished.
        self.is_default_backend_loaded = False
        self._backend_signals.connect('default-backend-loaded',
                                      self._activate_non_default_backends)
        self.filtered_datastore = FilteredDataStore(self)
        self._backend_mutex = threading.Lock()
Exemplo n.º 2
0
    def get_saved_backends_list(self):
        config = CoreConfig()
        backends = []

        for backend in config.get_all_backends():
            settings = config.get_backend_config(backend)
            module = self.get_backend(settings.get('module'))

            # Skip this backend if it doesn't have a module
            if not module:
                log.debug(f"Could not load module for backend {module}")
                continue

            backend_data = {}
            specs = module.Backend.get_static_parameters()
            backend_data['pid'] = str(settings.get('pid'))
            backend_data["first_run"] = False

            for param_name, param_dic in specs.items():

                try:
                    # We need to convert the parameter to the right format.
                    # We fetch the format from the static_parameters
                    param_type = param_dic[GenericBackend.PARAM_TYPE]
                    param_value = GenericBackend.cast_param_type_from_string(
                        settings.get(param_name), param_type)

                    backend_data[param_name] = param_value

                except ValueError:
                    # Parameter not found in config
                    pass

            backend_data['backend'] = module.Backend(backend_data)
            backends.append(backend_data)

        # If no backend available, we create a new using localfile. Dic
        # will be filled in by the backend
        if not backends:
            dic = BackendFactory().get_new_backend_dict(
                "backend_localfile")

            dic["first_run"] = True
            backends.append(dic)

        return backends