Added Utils.writef (counterpart of Utils.readf)

This commit is contained in:
Thomas Nagy 2012-02-12 15:27:38 +01:00
parent 3368341313
commit ef0c80e3b6
1 changed files with 23 additions and 0 deletions

View File

@ -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