mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-21 18:06:46 +00:00
node: change get_or_create_config to strip whitespace and accept a filemode= argument
This commit is contained in:
parent
89ceb49309
commit
1428079a84
@ -78,7 +78,7 @@ class Node(service.MultiService):
|
|||||||
return None
|
return None
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_or_create_config(self, name, default_fn, mode="w"):
|
def get_or_create_config(self, name, default_fn, mode="w", filemode=None):
|
||||||
"""Try to get the (string) contents of a config file, and return it.
|
"""Try to get the (string) contents of a config file, and return it.
|
||||||
Any leading or trailing whitespace will be stripped from the data.
|
Any leading or trailing whitespace will be stripped from the data.
|
||||||
|
|
||||||
@ -95,10 +95,15 @@ class Node(service.MultiService):
|
|||||||
value = default_fn()
|
value = default_fn()
|
||||||
fn = os.path.join(self.basedir, name)
|
fn = os.path.join(self.basedir, name)
|
||||||
try:
|
try:
|
||||||
open(fn, mode).write(value)
|
f = open(fn, mode)
|
||||||
|
f.write(value)
|
||||||
|
f.close()
|
||||||
|
if filemode is not None:
|
||||||
|
os.chmod(fn, filemode)
|
||||||
except EnvironmentError, e:
|
except EnvironmentError, e:
|
||||||
self.log("Unable to write config file '%s'" % fn)
|
self.log("Unable to write config file '%s'" % fn)
|
||||||
self.log(e)
|
self.log(e)
|
||||||
|
value = value.strip()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def write_config(self, name, value, mode="w"):
|
def write_config(self, name, value, mode="w"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user