Adds an open_write_close() convenience func that does the right thing
without depending on python being reference counted to close (flush)
the file.  (that works today in C Python but is bad to depend on)

Also changes the existing similar write_one_line() function to explicitly
call close rather than just flush().  The unittest's fake file object
injection needed updating as a result.

Signed-off-by: Gregory Smith <gps@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2299 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 9437979..a80c873 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -114,10 +114,16 @@
     return open(filename, 'r').readline().rstrip('\n')
 
 
-def write_one_line(filename, str):
+def write_one_line(filename, line):
+    open_write_close(filename, line.rstrip('\n') + '\n')
+
+
+def open_write_close(filename, data):
     f = open(filename, 'w')
-    f.write(str.rstrip('\n') + '\n')
-    f.flush()
+    try:
+        f.write(data)
+    finally:
+        f.close()
 
 
 def read_keyval(path):