From: Brian Warner Date: Tue, 19 Mar 2013 00:30:57 +0000 (-0700) Subject: fileutil.write: accept mode=, and use it in Node.write_config X-Git-Tag: allmydata-tahoe-1.10a1~5 X-Git-Url: https://git.rkrishnan.org/specifications/install.html?a=commitdiff_plain;h=ff64a0fef5879d3651bc3db6ca0522d96b217d45;p=tahoe-lafs%2Ftahoe-lafs.git 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. --- diff --git a/src/allmydata/node.py b/src/allmydata/node.py index a0f6b138..8873e5c7 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -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) diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 7add35cb..8eb8e9fb 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -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: