diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-09-20 17:56:22 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-09-20 17:56:22 -0700 |
commit | e8a10a41d22876d555084def823817337d9c2a80 (patch) | |
tree | 200f2f26a2bc362d0a55fdf7a743b26cf5d97ff0 /cloudinit/util.py | |
parent | 94b9647e4df742982cac8a2c2925fb4894281dbf (diff) | |
download | vyos-cloud-init-e8a10a41d22876d555084def823817337d9c2a80.tar.gz vyos-cloud-init-e8a10a41d22876d555084def823817337d9c2a80.zip |
Use only util methods for reading/loading/appending/peeking
at files since it is likely soon that we will add a new
way of adjusting the root of files read, also it is useful
for debugging to track what is being read/written in a central
fashion.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 33da73eb..18000301 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -952,6 +952,12 @@ def find_devs_with(criteria=None, oformat='device', return entries +def peek_file(fname, max_bytes): + LOG.debug("Peeking at %s (max_bytes=%s)", fname, max_bytes) + with open(fname, 'rb') as ifh: + return ifh.read(max_bytes) + + def load_file(fname, read_cb=None, quiet=False): LOG.debug("Reading from %s (quiet=%s)", fname, quiet) ofh = StringIO() @@ -1281,6 +1287,10 @@ def uptime(): return uptime_str +def append_file(path, content): + write_file(path, content, omode="ab", mode=None) + + def ensure_file(path, mode=0644): write_file(path, content='', omode="ab", mode=mode) |