fileutil.write: accept mode=, and use it in Node.write_config
authorBrian Warner <warner@lothar.com>
Tue, 19 Mar 2013 00:30:57 +0000 (17:30 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 19 Mar 2013 00:34:57 +0000 (17:34 -0700)
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
src/allmydata/util/fileutil.py

index a0f6b1380c7c00cf9862f76eb00c72a2290c152b..8873e5c798232ab1d009de76e05b5436b3803d25 100644 (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)
index 7add35cb41a968c2952c17e159b00eca149cde00..8eb8e9fb6cd360a74fdc4c62147bc0fd0b98df09 100644 (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: