1
"""File-system utils"""
7
def create_file(path, content):
8
"""Create a file with the given content.
10
@param path: The path to the file.
11
@param content: The content to be written in the file.
18
def append_file(path, content):
19
"""Append a file with the given content.
21
The file is created, if it doesn't exist already.
23
@param path: The path to the file.
24
@param content: The content to be written in the file at the end.
31
def read_file(path, limit=None):
32
"""Return the content of the given file.
34
@param path: The path to the file.
35
@param limit: An optional read limit. If positive, read up to that number
36
of bytes from the beginning of the file. If negative, read up to that
37
number of bytes from the end of the file.
38
@return content: The content of the file, possibly trimmed to C{limit}.
41
if limit and os.path.getsize(path) > abs(limit):
45
fd.seek(limit, whence)
51
def touch_file(path, offset_seconds=None):
52
"""Touch a file, creating it if it doesn't exist.
54
@param path: the path to the file to be touched.
55
@param offset_seconds: a signed integer number of seconds to offset the
56
atime and mtime of the file from the current time.
61
if offset_seconds is not None:
62
offset_time = long(time.time()) + offset_seconds
63
touch_time = (offset_time, offset_time)
66
os.utime(path, touch_time)