From ff64a0fef5879d3651bc3db6ca0522d96b217d45 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 18 Mar 2013 17:30:57 -0700 Subject: [PATCH] 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. --- src/allmydata/node.py | 2 +- src/allmydata/util/fileutil.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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: -- 2.45.2