make and use set_config instead of internals

This commit is contained in:
meejah 2019-04-08 22:35:07 -06:00
parent 9220dd12ef
commit 3d7055711a
3 changed files with 22 additions and 3 deletions

View File

@ -321,6 +321,21 @@ class _Config(object):
)
return default
def set_config(self, section, option, value):
"""
Set a config options in a section and re-write the tahoe.cfg file
"""
if option.endswith(".furl") and self._contains_unescaped_hash(value):
raise UnescapedHashError(section, option, item)
try:
self.config.add_section(section)
except ConfigParser.DuplicateSectionError:
pass
self.config.set(section, option, value)
with open(self._config_fname, "w") as f:
self.config.write(f)
def get_config_from_file(self, name, required=False):
"""Get the (string) contents of a config file, or None if the file
did not exist. If required=True, raise an exception rather than

View File

@ -124,12 +124,10 @@ def add_grid_manager_cert(options):
print("Already have file '{}'".format(cert_path), file=options.parent.parent.stderr)
return 1
cfg = config.config # why aren't methods we call on cfg in _Config itself?
gm_certs = config.get_config("storage", "grid_manager_certificate_files", "").split()
if cert_fname not in gm_certs:
gm_certs.append(cert_fname)
cfg.set("storage", "grid_manager_certificate_files", " ".join(gm_certs))
config.set_config("storage", "grid_manager_certificate_files", " ".join(gm_certs))
# print("grid_manager_certificate_files in {}: {}".format(config_path, len(gm_certs)))

View File

@ -316,6 +316,12 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
yield client.create_client(basedir)
self.failUnless(ns.called)
def test_set_config_new_section(self):
basedir = "test_node/test_set_config_new_section"
config = config_from_string(basedir, "", "")
config.set_config("foo", "bar", "value1")
config.set_config("foo", "bar", "value2")
class TestMissingPorts(unittest.TestCase):
"""