Exemplo n.º 1
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.º 2
0
    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())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
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.º 5
0
    def test03_read(self):
        # print("\n>>> Testing read")
        Configuration._set_configuration_filename("rspub_test.cfg")
        new_path = os.path.dirname(os.path.realpath(__file__))
        config1 = Configuration()
        config2 = Configuration()

        config1.set_plugin_dir(new_path)
        self.assertEquals(config1.plugin_dir(), new_path)
        config1.set_plugin_dir(None)
        self.assertEquals(config1.plugin_dir(), None)

        self.assertEquals(config2.plugin_dir(), None)

        Configuration.reset()
Exemplo n.º 6
0
    def test_strategy(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(Strategy.resourcelist, rsp.strategy)

        rsp = RsParameters(strategy=Strategy.inc_changelist)
        self.assertEquals(Strategy.inc_changelist, rsp.strategy)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.strategy, Strategy.inc_changelist)

        rsp = RsParameters(strategy=1)
        self.assertEquals(Strategy.new_changelist, rsp.strategy)

        rsp = RsParameters(strategy="inc_changelist")
        self.assertEquals(Strategy.inc_changelist, rsp.strategy)

        with self.assertRaises(Exception) as context:
            rsp.strategy = 20056
        #print(context.exception)
        self.assertEquals("20056 is not a valid Strategy",
                          context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 7
0
    def test_history_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(None, rsp.history_dir)

        rsp = RsParameters(history_dir="foo/bar/baz")
        self.assertEquals("foo/bar/baz", rsp.history_dir)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("foo/bar/baz", rsp2.history_dir)

        expected = os.path.join(rsp.abs_metadata_dir(), "foo/bar/baz")
        self.assertEquals(expected, rsp.abs_history_dir())

        rsp.history_dir = None
        self.assertIsNone(rsp.abs_history_dir())

        rsp.history_dir = "history"
        self.assertEquals("history", rsp.history_dir)

        rsp.history_dir = ""
        self.assertEquals(None, rsp.history_dir)

        with self.assertRaises(Exception) as context:
            rsp.history_dir = 42
        #print(context.exception)
        self.assertEquals(
            "Value for history_dir should be string. 42 is <class 'int'>",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 8
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.º 9
0
    def test_last_strategy(self):
        Configuration().core_clear()
        rsp = RsParameters()

        self.assertIsNone(rsp.last_strategy)

        rsp.last_strategy = Strategy.inc_changelist
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEqual(Strategy.inc_changelist, rsp2.last_strategy)

        self.save_configuration_test(rsp)
Exemplo n.º 10
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")
Exemplo n.º 11
0
    def test_metadata_dir(self):
        user_home = os.path.expanduser("~")

        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("metadata", rsp.metadata_dir)
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(user_home, "metadata"))

        resource_dir = user_home

        rsp = RsParameters(metadata_dir=os.path.join("foo", "md1"),
                           resource_dir=resource_dir)
        # print(rsp.abs_metadata_dir())
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(resource_dir, "foo", "md1"))
        # @ToDo test for windows pathnames: 'foo\md1', 'C:foo\bar\baz'

        here = os.path.dirname(__file__)
        rsp.resource_dir = here
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(here, "foo", "md1"))

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.abs_metadata_dir(),
                          os.path.join(here, "foo", "md1"))

        with self.assertRaises(Exception) as context:
            rsp.metadata_dir = os.path.expanduser("~")
        # print(context.exception)
        self.assertEquals(
            "Invalid value for metadata_dir: path should not be absolute: " +
            os.path.expanduser("~"), context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.metadata_dir = "/foo/bar"
        # print(context.exception)
        self.assertEquals(
            "Invalid value for metadata_dir: path should not be absolute: /foo/bar",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        # cannot check if metadata_dir will be a directory, because relative to resource_dir
        # this = os.path.basename(__file__)
        # with self.assertRaises(Exception) as context:
        #     rsp.metadata_dir = this
        # #print(context.exception)
        # self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 12
0
    def do_reset(self, line):
        """
reset::

    Reset the configuration to default settings.

        """
        global PARAS
        if self.__confirm__("Reset configuration '%s' to default settings?" %
                            PARAS.configuration_name()):
            Configuration().core_clear()
            PARAS = RsParameters()
            PARAS.save_configuration()
            self.do_list_parameters(line)
Exemplo n.º 13
0
    def test_zero_fill_filename(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(4, rsp.zero_fill_filename)

        rsp = RsParameters(zero_fill_filename=10)
        self.assertEquals(10, rsp.zero_fill_filename)

        # contamination test
        rsp.zero_fill_filename = 8
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(8, rsp2.zero_fill_filename)

        self.save_configuration_test(rsp)
Exemplo n.º 14
0
    def test_imp_scp_server(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("example.com", rsp.imp_scp_server)

        # contamination test
        rsp.imp_scp_server = "imp.server.name.com"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("imp.server.name.com", rsp2.imp_scp_server)

        rsp.imp_scp_server = "imp.server.name.nl"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("imp.server.name.nl", rsp3.imp_scp_server)

        self.save_configuration_test(rsp)
Exemplo n.º 15
0
    def test_imp_scp_user(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("username", rsp.imp_scp_user)

        # contamination test
        rsp.imp_scp_user = "******"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("kees", rsp2.imp_scp_user)

        rsp.imp_scp_user = "******"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("joe", rsp3.imp_scp_user)

        self.save_configuration_test(rsp)
Exemplo n.º 16
0
    def test_imp_scp_port(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(22, rsp.imp_scp_port)

        # contamination test
        rsp.imp_scp_port = 2222
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(2222, rsp2.imp_scp_port)

        rsp.imp_scp_port = 1234
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(1234, rsp3.imp_scp_port)

        self.save_configuration_test(rsp)
Exemplo n.º 17
0
    def test_imp_scp_remote_path(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("~", rsp.imp_scp_remote_path)

        # contamination test
        rsp.imp_scp_remote_path = "/var/rs/"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("/var/rs", rsp2.imp_scp_remote_path)

        rsp.imp_scp_remote_path = "/opt/ehri/rs"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("/opt/ehri/rs", rsp3.imp_scp_remote_path)

        self.save_configuration_test(rsp)
Exemplo n.º 18
0
    def test_exp_scp_document_root(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("/var/www/html", rsp.exp_scp_document_root)

        # contamination test
        rsp.exp_scp_document_root = "/opt/rs/"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("/opt/rs", rsp2.exp_scp_document_root)

        rsp.exp_scp_document_root = "/var/www/html/ehri/rs"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("/var/www/html/ehri/rs", rsp3.exp_scp_document_root)

        self.save_configuration_test(rsp)
Exemplo n.º 19
0
    def test_plugin_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(None, rsp.plugin_dir)

        user_home = os.path.expanduser("~")
        rsp.plugin_dir = user_home
        self.assertEquals(user_home, rsp.plugin_dir)

        # contamination test
        rsp.plugin_dir = None
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(None, rsp2.plugin_dir)

        rsp.plugin_dir = user_home
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(user_home, rsp3.plugin_dir)

        self.save_configuration_test(rsp)
Exemplo n.º 20
0
    def test_description_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertIsNone(rsp.description_dir)

        rsp.description_dir = "."
        self.assertEquals(os.getcwd(), rsp.description_dir)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.getcwd(), rsp2.description_dir)

        with self.assertRaises(Exception) as context:
            rsp.description_dir = "/foo/bar"
        #print(context.exception)
        self.assertIsInstance(context.exception, ValueError)

        self.assertEquals(os.getcwd(), rsp.description_dir)
        self.save_configuration_test(rsp)
Exemplo n.º 21
0
    def test_imp_scp_local_path(self):
        # defaults to configuration defaults
        user_home = os.path.expanduser("~")

        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(user_home, rsp.imp_scp_local_path)

        # contamination test
        rsp.imp_scp_local_path = os.path.join(user_home, "local", "rs")
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.path.join(user_home, "local", "rs"),
                          rsp2.imp_scp_local_path)

        rsp.imp_scp_local_path = os.path.join(user_home, "rs", "local")
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.path.join(user_home, "rs", "local"),
                          rsp3.imp_scp_local_path)

        self.save_configuration_test(rsp)
Exemplo n.º 22
0
    def test_booleans(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertTrue(rsp.is_saving_pretty_xml)
        self.assertTrue(rsp.is_saving_sitemaps)
        self.assertTrue(rsp.has_wellknown_at_root)

        rsp = RsParameters(is_saving_pretty_xml=False,
                           is_saving_sitemaps=False,
                           has_wellknown_at_root=False)
        self.assertFalse(rsp.is_saving_pretty_xml)
        self.assertFalse(rsp.is_saving_sitemaps)
        self.assertFalse(rsp.has_wellknown_at_root)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertFalse(rsp2.is_saving_pretty_xml)
        self.assertFalse(rsp2.is_saving_sitemaps)
        self.assertFalse(rsp2.has_wellknown_at_root)

        self.save_configuration_test(rsp)
Exemplo n.º 23
0
    def test_max_items_in_list(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(50000, rsp.max_items_in_list)

        rsp = RsParameters(max_items_in_list=1)
        self.assertEquals(1, rsp.max_items_in_list)

        # contamination test
        rsp.max_items_in_list = 12345
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(12345, rsp2.max_items_in_list)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = "foo"
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: not a number foo",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = 0
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: value should be between 1 and 50000",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = 50001
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: value should be between 1 and 50000",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 24
0
    def test_zip_filename(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEqual(
            os.path.join(os.path.expanduser("~"), "resourcesync.zip"),
            rsp.zip_filename)

        rsp.zip_filename = "bar"
        self.assertEqual("bar.zip", rsp.zip_filename)

        rsp.zip_filename = "foo."
        self.assertEqual("foo.zip", rsp.zip_filename)

        rsp.zip_filename = "/"
        self.assertEqual("/.zip", rsp.zip_filename)

        # contamination test
        rsp.zip_filename = "/foo/bar.zip"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEqual("/foo/bar.zip", rsp2.zip_filename)

        self.save_configuration_test(rsp)
Exemplo n.º 25
0
    def test_resource_dir(self):
        user_home = os.path.expanduser("~")

        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(rsp.resource_dir, user_home + os.sep)

        resource_dir = user_home

        rsp = RsParameters(resource_dir=resource_dir)
        self.assertEquals(rsp.resource_dir, resource_dir + os.sep)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.resource_dir, resource_dir + os.sep)
        assert (rsp.__dict__ == rsp2.__dict__)

        with self.assertRaises(Exception) as context:
            rsp.resource_dir = "/foo/bar"
        #print(context.exception)
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 26
0
    def test_url_prefix(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(rsp.url_prefix, "http://www.example.com/")

        rsp = RsParameters(url_prefix="http://foo.bar.com")
        self.assertEquals(rsp.url_prefix, "http://foo.bar.com/")

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.url_prefix, "http://foo.bar.com/")

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "nix://foo.bar.com"
        #print(context.exception)
        self.assertEquals(
            "URL schemes allowed are 'http' or 'https'. Given: 'nix://foo.bar.com'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "https://.nl"
        #print(context.exception)
        self.assertEquals(
            "URL has invalid domain name: '.nl'. Given: 'https://.nl'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "https://foo.bar.com#foo"
        #print(context.exception)
        self.assertEquals(
            "URL should not have a fragment. Given: 'https://foo.bar.com#foo'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "http://foo.bar.com?what=this"
        #print(context.exception)
        self.assertEquals(
            "URL should not have a query string. Given: 'http://foo.bar.com?what=this'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "http://foo.bar.com/fragment#is"
        #print(context.exception)
        self.assertEquals(
            "URL should not have a fragment. Given: 'http://foo.bar.com/fragment#is'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.url_prefix = "http://foo.bar.com/ uhr.isrong"
        #print(context.exception)
        self.assertEquals(
            "URL is invalid. Given: 'http://foo.bar.com/ uhr.isrong'",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 27
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)
Exemplo n.º 28
0
 def reset(self):
     name = self.configuration_name()
     cfg = Configuration()
     cfg.core_clear()
     cfg.persist()
     self.__init__(config_name=name)