Exemplo n.º 1
0
    def save_configuration(self, on_disk=True):
        """
        ``function`` :samp:`Save current configuration`

        Save the current values of parameters to configuration. If `on_disk` is **True** (the default)
        persist the configuration to disk under the current configuration name.

        :param on_disk: **True** if configuration should be saved to disk, **False** otherwise

        See also: :func:`~rspub.core.config.Configurations.current_configuration_name`
        """
        cfg = Configuration()

        cfg.set_resource_dir(self.resource_dir)
        cfg.set_metadata_dir(self.metadata_dir)
        cfg.set_description_dir(self.description_dir)
        cfg.set_url_prefix(self.url_prefix)
        cfg.set_strategy(self.strategy)
        cfg.set_selector_file(self.selector_file)
        cfg.set_simple_select_file(self.simple_select_file)
        cfg.set_select_mode(self.select_mode)
        cfg.set_history_dir(self.history_dir)
        cfg.set_plugin_dir(self.plugin_dir)
        cfg.set_max_items_in_list(self.max_items_in_list)
        cfg.set_zero_fill_filename(self.zero_fill_filename)
        cfg.set_is_saving_pretty_xml(self.is_saving_pretty_xml)
        cfg.set_is_saving_sitemaps(self.is_saving_sitemaps)
        cfg.set_has_wellknown_at_root(self.has_wellknown_at_root)
        cfg.set_last_execution(self.last_execution)
        cfg.set_last_strategy(self.last_strategy)
        cfg.set_last_sitemaps(self.last_sitemaps)
        #
        cfg.set_exp_scp_server(self.exp_scp_server)
        cfg.set_exp_scp_port(self.exp_scp_port)
        cfg.set_exp_scp_user(self.exp_scp_user)
        cfg.set_exp_scp_document_root(self.exp_scp_document_root)
        #
        cfg.set_zip_filename(self.zip_filename)
        #
        cfg.set_imp_scp_server(self.imp_scp_server)
        cfg.set_imp_scp_port(self.imp_scp_port)
        cfg.set_imp_scp_user(self.imp_scp_user)
        cfg.set_imp_scp_remote_path(self.imp_scp_remote_path)
        cfg.set_imp_scp_local_path(self.imp_scp_local_path)

        if on_disk:
            cfg.persist()
Exemplo n.º 2
0
    def test_persist(self):
        filename = "rspub_test_persist.cfg"
        Configuration._set_configuration_filename(filename)

        cfg = Configuration()
        if os.path.exists(cfg.config_file):
            os.remove(cfg.config_file)  # not atomic
        # time.sleep(2)
        self.assertFalse(os.path.exists(cfg.config_file))

        cfg.set_metadata_dir("foo/bar/md1")
        self.assertEquals(cfg.metadata_dir(), "foo/bar/md1")

        cfg.set_history_dir(None)
        self.assertIsNone(cfg.history_dir())

        cfg.set_max_items_in_list(42)
        self.assertEquals(42, cfg.max_items_in_list())
        cfg.set_is_saving_pretty_xml(False)
        self.assertEquals(False, cfg.is_saving_pretty_xml())

        cfg.set_last_sitemaps([])
        self.assertEquals([], cfg.last_sitemaps())

        cfg.set_last_sitemaps(
            ["foo/bar/bas.txt", "foo/bar/bord.txt", "foo/bar/barst.txt"])
        self.assertEquals(
            ["foo/bar/bas.txt", "foo/bar/bord.txt", "foo/bar/barst.txt"],
            cfg.last_sitemaps())

        cfg.persist()
        self.assertTrue(os.path.exists(cfg.config_file))
        #time.sleep(1)

        Configuration._set_configuration_filename(filename)
        cfg2 = Configuration()
        self.assertEquals(42, cfg2.max_items_in_list())
        self.assertEquals(False, cfg2.is_saving_pretty_xml())
        self.assertEquals(
            ["foo/bar/bas.txt", "foo/bar/bord.txt", "foo/bar/barst.txt"],
            cfg.last_sitemaps())