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())
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()