mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-03 11:44:11 +00:00
make and use set_config instead of internals
This commit is contained in:
parent
9220dd12ef
commit
3d7055711a
@ -321,6 +321,21 @@ class _Config(object):
|
|||||||
)
|
)
|
||||||
return default
|
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):
|
def get_config_from_file(self, name, required=False):
|
||||||
"""Get the (string) contents of a config file, or None if the file
|
"""Get the (string) contents of a config file, or None if the file
|
||||||
did not exist. If required=True, raise an exception rather than
|
did not exist. If required=True, raise an exception rather than
|
||||||
|
@ -124,12 +124,10 @@ def add_grid_manager_cert(options):
|
|||||||
print("Already have file '{}'".format(cert_path), file=options.parent.parent.stderr)
|
print("Already have file '{}'".format(cert_path), file=options.parent.parent.stderr)
|
||||||
return 1
|
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()
|
gm_certs = config.get_config("storage", "grid_manager_certificate_files", "").split()
|
||||||
if cert_fname not in gm_certs:
|
if cert_fname not in gm_certs:
|
||||||
gm_certs.append(cert_fname)
|
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)))
|
# print("grid_manager_certificate_files in {}: {}".format(config_path, len(gm_certs)))
|
||||||
|
|
||||||
|
@ -316,6 +316,12 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
|
|||||||
yield client.create_client(basedir)
|
yield client.create_client(basedir)
|
||||||
self.failUnless(ns.called)
|
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):
|
class TestMissingPorts(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user