Exemplo n.º 1
0
    def test02_instance(self):
        # print("\n>>> Testing _instance")
        Configuration._set_configuration_filename("rspub_core.cfg")

        config1 = Configuration()
        config2 = Configuration()

        assert config1 == config2

        path1 = config1.config_path
        if platform.system() == "Darwin":
            assert path1 == os.path.expanduser("~") + "/.config/rspub/core"
        elif platform.system() == "Windows":
            path_expected = os.path.join(os.path.expanduser("~"), "AppData",
                                         "Local", "rspub", "core")
            assert path1 == path_expected
        elif platform.system() == "Linux":
            assert path1 == os.path.expanduser("~") + "/.config/rspub/core"
        else:
            assert path1 == os.path.expanduser("~") + "/rspub/core"

        config1.core_clear()
        assert config1.resource_dir() == os.path.expanduser("~")
        new_path = os.path.dirname(os.path.realpath(__file__))
        config1.set_resource_dir(new_path)
        assert config2.resource_dir() == new_path

        config2.persist()
        config1 = None
        config2 = None

        Configuration.reset()
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.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())
Exemplo n.º 3
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_document_root(self.document_root)
        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)

        if on_disk:
            cfg.persist()
Exemplo n.º 4
0
 def reset(self):
     name = self.configuration_name()
     cfg = Configuration()
     cfg.core_clear()
     cfg.persist()
     self.__init__(config_name=name)