fileutil.write: accept mode=, and use it in Node.write_config

I want mode="w" (i.e. text, with newline conversion) for code that
writes newline-terminated strings (which should also be human readable)
to files. I like to use things like "cat .tahoe/permutation-seed"
without seeing the seed jammed together with the next command prompt.
This commit is contained in:
Brian Warner 2013-03-18 17:30:57 -07:00
parent 7130a247cf
commit ff64a0fef5
2 changed files with 3 additions and 3 deletions

View File

@ -279,7 +279,7 @@ class Node(service.MultiService):
"""Write a string to a config file."""
fn = os.path.join(self.basedir, name)
try:
open(fn, mode).write(value)
fileutil.write(fn, value, mode)
except EnvironmentError, e:
self.log("Unable to write config file '%s'" % fn)
self.log(e)

View File

@ -255,8 +255,8 @@ def write_atomically(target, contents, mode="b"):
f.close()
move_into_place(target+".tmp", target)
def write(path, data):
wf = open(path, "wb")
def write(path, data, mode="wb"):
wf = open(path, mode)
try:
wf.write(data)
finally: