コード例 #1
0
ファイル: test_rs_paras.py プロジェクト: cegesoma/rspub-core
    def test_load_configuration(self):
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("test_rs_paras", rsp.configuration_name())

        rsp.max_items_in_list = 5566
        rsp.save_configuration_as("realy_not_a_name_for_config")
        self.assertEquals("realy_not_a_name_for_config",
                          rsp.configuration_name())

        rsp = RsParameters(config_name="realy_not_a_name_for_config")
        self.assertEquals(5566, rsp.max_items_in_list)

        self.assertTrue("realy_not_a_name_for_config" in
                        Configurations.list_configurations())

        Configurations.remove_configuration("realy_not_a_name_for_config")

        with self.assertRaises(Exception) as context:
            RsParameters(config_name="realy_not_a_name_for_config")
        self.assertIsInstance(context.exception, ValueError)

        Configuration().reset()
        rsp = RsParameters()
        self.assertEquals("realy_not_a_name_for_config",
                          rsp.configuration_name())
コード例 #2
0
 def complete_configuration(text):
     if not text:
         completions = Configurations.list_configurations()[:]
     else:
         completions = [
             x for x in Configurations.list_configurations()
             if x.startswith(text)
         ]
     return completions
コード例 #3
0
ファイル: wmain.py プロジェクト: cegesoma/rspub-gui
 def on_menu_open_config_about_to_show(self):
     self.menu_open_config.clear()
     for child in self.config_action_group.children():
         self.config_action_group.removeAction(child)
     current_name = Configurations.current_configuration_name()
     for name in Configurations.list_configurations():
         action = QAction(name, self)
         action.setCheckable(True)
         action.setData(name)
         self.config_action_group.addAction(action)
         self.menu_open_config.addAction(action)
         if name == current_name:
             action.setChecked(True)
コード例 #4
0
    def save_configuration_as(self, name: str):
        """
        ``function`` :samp:`Save current configuration under {name}`

        Save the current configuration under the given `name`. If a configuration under the given `name` already
        exists it will be overwritten without warning.

        :param str name: the name under which the configuration will be saved

        See also: :func:`~rspub.core.config.Configurations.load_configuration`
        """
        self.save_configuration(False)
        Configurations.save_configuration_as(name)
コード例 #5
0
    def configuration_name():
        """
        ``function`` :samp:`Current configuration name`

        :return: current configuration name
        """
        return Configurations.current_configuration_name()
コード例 #6
0
    def __get_selector(self):
        if self.paras.selector_file:
            try:
                selector = Selector(location=self.paras.selector_file)
                self.last_directory = os.path.dirname(self.paras.selector_file)
                LOG.debug("Loaded selector from %s" % self.paras.selector_file)
            except Exception as err:
                self.warn(
                    "Unable to read selector file '%s'" %
                    self.paras.selector_file, err)
                selector = Selector()
        else:
            selector = Selector()

        #Difficult keeping track of a selector that is not saved:
        if selector.location is None:
            selector_dir = os.path.join(Configurations.rspub_config_dir(),
                                        "selectors")
            os.makedirs(selector_dir, exist_ok=True)
            location = os.path.join(selector_dir, "default_selector.csv")
            if os.path.exists(location):
                selector = Selector(location=location)
            else:
                selector.write(location)
            self.paras.selector_file = location
        return selector
コード例 #7
0
ファイル: wmain.py プロジェクト: cegesoma/rspub-gui
 def on_btn_delete_clicked(self):
     items = [x.data() for x in self.selection_model.selectedIndexes()]
     msg_box = QMessageBox()
     msg_box.setText(_("Delete configurations"))
     if len(items) == 1:
         i_text = _("Delete configuration '%s'" % items[0])
     else:
         i_text = _("Delete %d configurations" % len(items))
     i_text += "\n\n"
     i_text += _("Ok to proceed?")
     msg_box.setInformativeText(i_text)
     msg_box.setIcon(QMessageBox.Question)
     msg_box.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
     msg_box.setDefaultButton(QMessageBox.Yes)
     exe = msg_box.exec()
     if exe == QMessageBox.Yes:
         for item in self.selection_model.selectedIndexes():
             Configurations.remove_configuration(item.data())
         self.populate_model()
         self.on_selection_changed()
コード例 #8
0
    def test_current_configuration_name(self):
        # No name change
        current_name = Configurations.current_configuration_name()
        Configuration.reset()
        self.assertEquals(current_name, Configurations.current_configuration_name())

        cfg1 = Configuration()
        Configurations.save_configuration_as("test_current")
        self.assertEquals("test_current", Configurations.current_configuration_name())

        Configurations.remove_configuration("test_current")
コード例 #9
0
    def do_list_configurations(self, line):
        """
list_configurations::

    List saved configurations

        """
        print("====================")
        print("Saved configurations")
        print("====================")
        for config in Configurations.list_configurations():
            print(config)
        print("")
        print("====================")
コード例 #10
0
    def do_remove_configuration(self, name):
        """
remove_configuration [name]::

    Remove a saved configuration

        """
        if name:
            if self.__confirm__("Remove configuration '%s'?" % name):
                if Configurations.remove_configuration(name):
                    print("Removed configuration %s" % name)
                else:
                    print("No configuration with the name %s" % name)
        else:
            print("Remove a configuration. Specify a name:")
            self.do_list_configurations(name)
コード例 #11
0
ファイル: test_config.py プロジェクト: EHRI/rspub-core
 def test_rspub_config_dir(self):
     print(Configurations.rspub_config_dir())
コード例 #12
0
ファイル: test_config.py プロジェクト: EHRI/rspub-core
    def test_load_configuration(self):
        Configurations.remove_configuration("test_load_1")
        Configurations.remove_configuration("test_load_2")
        Configuration.reset()

        cfg1 = Configuration()
        cfg2 = Configuration()
        self.assertIs(cfg1, cfg2)
        self.assertEquals(Configurations.current_configuration_name(),
                          cfg1.name())
        self.assertEquals(Configurations.current_configuration_name(),
                          cfg2.name())

        Configurations.save_configuration_as("test_load_1")
        self.assertEquals("test_load_1", cfg1.name())
        Configuration.reset()

        cfg3 = Configuration()
        self.assertIsNot(cfg1, cfg3)
        self.assertEquals(Configurations.current_configuration_name(),
                          cfg3.name())

        Configurations.save_configuration_as("test_load_2")
        self.assertEquals("test_load_1", cfg1.name())
        self.assertEquals("test_load_1", cfg2.name())
        self.assertEquals("test_load_2", cfg3.name())

        Configurations.load_configuration("test_load_1")
        cfg4 = Configuration()
        self.assertEquals("test_load_1", cfg1.name())
        self.assertEquals("test_load_1", cfg2.name())
        self.assertEquals("test_load_2", cfg3.name())
        self.assertEquals("test_load_1", cfg4.name())
コード例 #13
0
ファイル: test_config.py プロジェクト: EHRI/rspub-core
 def test_list_configurations(self):
     configurations = Configurations()
     for c in configurations.list_configurations():
         print(c)
コード例 #14
0
ファイル: wmain.py プロジェクト: cegesoma/rspub-gui
 def populate_model(self):
     self.list_model.clear()
     for cfg in Configurations.list_configurations():
         item = QStandardItem(cfg)
         self.list_model.appendRow(item)
コード例 #15
0
    def __init__(self, config_name=None, resource_dir=config, metadata_dir=config, description_dir=config,
                 url_prefix=config, strategy=config, selector_file=config,
                 simple_select_file=config, select_mode=config, plugin_dir=config,
                 history_dir=config, max_items_in_list=config, zero_fill_filename=config, is_saving_pretty_xml=config,
                 is_saving_sitemaps=config, has_wellknown_at_root=config,
                 exp_scp_server=config, exp_scp_port=config, exp_scp_user=config,
                 exp_scp_document_root=config, zip_filename=config,
                 imp_scp_server=config, imp_scp_port=config, imp_scp_user=config,
                 imp_scp_remote_path=config, imp_scp_local_path=config,
                 **kwargs):
        """
        :samp:`Construct an instance of {RsParameters}`

        All ``parameters`` will get their value from

        1. the _named argument in `\*\*kwargs`. (this is for cloning instances of RsParameters). If not available:
        2. the named argument. If not available:
        3. the parameter as saved in the current configuration. If not available:
        4. the default configuration value.

        :param str config_name: the name of the configuration to read. If given, sets the current configuration.
        :param str resource_dir: ``parameter`` :func:`resource_dir`
        :param str metadata_dir: ``parameter`` :func:`metadata_dir`
        :param str description_dir: ``parameter`` :func:`description_dir`
        :param str url_prefix: ``parameter`` :func:`url_prefix`
        :param Union[Strategy, int, str] strategy: ``parameter`` :func:`strategy`
        :param str selector_file: ``parameter`` :func:`selector_file`
        :param str simple_select_file: ``parameter`` :func:`simple_select_file`
        :param SelectMode select_mode: ``parameter`` :func:`select_mode`
        :param str plugin_dir: ``parameter`` :func:`plugin_dir`
        :param str history_dir: ``parameter`` :func:`history_dir`
        :param int max_items_in_list: ``parameter`` :func:`max_items_in_list`
        :param int zero_fill_filename: ``parameter`` :func:`zero_fill_filename`
        :param bool is_saving_pretty_xml: ``parameter`` :func:`is_saving_pretty_xml`
        :param bool is_saving_sitemaps: ``parameter`` :func:`is_saving_sitemaps`
        :param bool has_wellknown_at_root: ``parameter`` :func:`has_wellknown_at_root`
        :param str exp_scp_server: ``parameter`` :func:`exp_scp_server`
        :param int exp_scp_port: ``parameter`` :func:`exp_scp_port`
        :param str exp_scp_user: ``parameter`` :func:`exp_scp_user`
        :param str exp_scp_document_root: ``parameter`` :func:`exp_scp_document_root`
        :param str zip_filename: ``parameter`` :func:`zip_filename`
        :param str imp_scp_server: ``parameter`` :func:`imp_scp_server`
        :param int imp_scp_port: ``parameter`` :func:`imp_scp_port`
        :param str imp_scp_user: ``parameter`` :func:`imp_scp_user`
        :param str imp_scp_remote_path: ``parameter`` :func:`imp_scp_remote_path`
        :param str imp_scp_local_path: ``parameter`` :func:`imp_scp_local_path`
        :param kwargs: named arguments, same as parameters, but preceded by _
        :raises: :exc:`ValueError` if a parameter is not valid or if the configuration with the given `config_name` is not found
        """
        kwargs.update({
            "resource_dir": resource_dir,
            "metadata_dir": metadata_dir,
            "description_dir": description_dir,
            "url_prefix": url_prefix,
            "strategy": strategy,
            "selector_file": selector_file,
            "simple_select_file": simple_select_file,
            "select_mode": select_mode,
            "plugin_dir": plugin_dir,
            "history_dir": history_dir,
            "max_items_in_list": max_items_in_list,
            "zero_fill_filename": zero_fill_filename,
            "is_saving_pretty_xml": is_saving_pretty_xml,
            "is_saving_sitemaps": is_saving_sitemaps,
            "has_wellknown_at_root": has_wellknown_at_root,
            "exp_scp_server": exp_scp_server,
            "exp_scp_port": exp_scp_port,
            "exp_scp_user": exp_scp_user,
            "exp_scp_document_root": exp_scp_document_root,
            "zip_filename": zip_filename,
            "imp_scp_server": imp_scp_server,
            "imp_scp_port": imp_scp_port,
            "imp_scp_user": imp_scp_user,
            "imp_scp_remote_path": imp_scp_remote_path,
            "imp_scp_local_path": imp_scp_local_path,
        })
        if config_name:
            cfg = Configurations.load_configuration(config_name)
        else:
            cfg = Configuration()

        self._resource_dir = None
        _resource_dir_ = self.__arg__("_resource_dir", cfg.resource_dir(), **kwargs)
        self.resource_dir = _resource_dir_

        self._metadata_dir = None
        _metadata_dir_ = self.__arg__("_metadata_dir", cfg.metadata_dir(), **kwargs)
        self.metadata_dir = _metadata_dir_

        self._description_dir = None
        _description_dir_ = self.__arg__("_description_dir", cfg.description_dir(), **kwargs)
        self.description_dir = _description_dir_

        self._url_prefix = None
        _url_prefix_ = self.__arg__("_url_prefix", cfg.url_prefix(), **kwargs)
        self.url_prefix = _url_prefix_

        self._strategy = None
        _strategy_ = self.__arg__("_strategy", cfg.strategy(), **kwargs)
        self.strategy = _strategy_

        self._selector_file = None
        _selector_file_ = self.__arg__("_selector_file", cfg.selector_file(), **kwargs)
        self.selector_file = _selector_file_

        self._simple_select_file = None
        _simple_select_file_ = self.__arg__("_simple_select_file", cfg.simple_select_file(), **kwargs)
        self.simple_select_file = _simple_select_file_

        self._select_mode = None
        _select_mode_ = self.__arg__("_select_mode", cfg.select_mode(), **kwargs)
        self.select_mode = _select_mode_

        self._plugin_dir = None
        _plugin_dir_ = self.__arg__("_plugin_dir", cfg.plugin_dir(), **kwargs)
        self.plugin_dir = _plugin_dir_

        self._history_dir = None
        _history_dir_ = self.__arg__("_history_dir", cfg.history_dir(), **kwargs)
        self.history_dir = _history_dir_

        self._max_items_in_list = None
        _max_items_in_list_ = self.__arg__("_max_items_in_list", cfg.max_items_in_list(), **kwargs)
        self.max_items_in_list = _max_items_in_list_

        self._zero_fill_filename = None
        _zero_fill_filename_ = self.__arg__("_zero_fill_filename", cfg.zero_fill_filename(), **kwargs)
        self.zero_fill_filename = _zero_fill_filename_

        self._is_saving_pretty_xml = self.__arg__("_is_saving_pretty_xml", cfg.is_saving_pretty_xml(), **kwargs)
        self._is_saving_sitemaps = self.__arg__("_is_saving_sitemaps", cfg.is_saving_sitemaps(), **kwargs)
        self._has_wellknown_at_root = self.__arg__("_has_wellknown_at_root", cfg.has_wellknown_at_root(), **kwargs)

        self._exp_scp_server = None
        _exp_scp_server_ = self.__arg__("_exp_scp_server", cfg.exp_scp_server(), **kwargs)
        self.exp_scp_server = _exp_scp_server_

        self._exp_scp_port = None
        _exp_scp_port_ = self.__arg__("_exp_scp_port", cfg.exp_scp_port(), **kwargs)
        self.exp_scp_port = _exp_scp_port_

        self._exp_scp_user = None
        _exp_scp_user_ = self.__arg__("_exp_scp_user", cfg.exp_scp_user(), **kwargs)
        self.exp_scp_user = _exp_scp_user_

        self._exp_scp_document_root = None
        _exp_scp_document_root_ = self.__arg__("_exp_scp_document_root", cfg.exp_scp_document_root(), **kwargs)
        self.exp_scp_document_root = _exp_scp_document_root_

        self._zip_filename = None
        _zip_filename_ = self.__arg__("_zip_filename", cfg.zip_filename(), **kwargs)
        self.zip_filename = _zip_filename_

        self._imp_scp_server = None
        _imp_scp_server_ = self.__arg__("_imp_scp_server", cfg.imp_scp_server(), **kwargs)
        self.imp_scp_server = _imp_scp_server_

        self._imp_scp_port = None
        _imp_scp_port_ = self.__arg__("_imp_scp_port", cfg.imp_scp_port(), **kwargs)
        self.imp_scp_port = _imp_scp_port_

        self._imp_scp_user = None
        _imp_scp_user_ = self.__arg__("_imp_scp_user", cfg.imp_scp_user(), **kwargs)
        self.imp_scp_user = _imp_scp_user_

        self._imp_scp_remote_path = None
        _imp_scp_remote_path_ = self.__arg__("_imp_scp_remote_path", cfg.imp_scp_remote_path(), **kwargs)
        self.imp_scp_remote_path = _imp_scp_remote_path_

        self._imp_scp_local_path = None
        _imp_scp_local_path_ = self.__arg__("_imp_scp_local_path", cfg.imp_scp_local_path(), **kwargs)
        self.imp_scp_local_path = _imp_scp_local_path_

        self.last_execution = self.__arg__("last_execution", cfg.last_excution(), **kwargs)
        self.last_strategy = self.__arg__("last_strategy", cfg.last_strategy(), **kwargs)
        self.last_sitemaps = self.__arg__("last_sitemaps", cfg.last_sitemaps(), **kwargs)