From ef0c80e3b6410fc156efe34f400d46401d80afbf Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sun, 12 Feb 2012 15:27:38 +0100 Subject: [PATCH] Added Utils.writef (counterpart of Utils.readf) --- waflib/Utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/waflib/Utils.py b/waflib/Utils.py index cf925639..208b086e 100644 --- a/waflib/Utils.py +++ b/waflib/Utils.py @@ -134,6 +134,29 @@ def readf(fname, m='r'): f.close() return txt +def writef(fname, data, m='w'): + """ + Write an entire file from a string, in practice the wrapper + node.write(..) should be used instead of this method:: + + def build(ctx): + from waflib import Utils + txt = Utils.writef(self.path.make_node('i_like_kittens').abspath(), 'some data') + self.path.make_node('i_like_kittens').write('some data') + + :type fname: string + :param fname: Path to file + :type data: string + :param data: The contents to write to the file + :type m: string + :param m: Open mode + """ + f = open(fname, m) + try: + txt = f.write(data) + finally: + f.close() + def h_file(filename): """ Compute a hash value for a file by using md5. This method may be replaced by