noc.core.fileutils

Module Contents

noc.core.fileutils.safe_rewrite(path, text, mode=None)
Create new file filled with "text" safely
noc.core.fileutils.safe_append(path, text)
Append the text to the end of the file
noc.core.fileutils.is_differ(path, content)
Check file content is differ from string
noc.core.fileutils.rewrite_when_differ(path, content)
Rewrites file when content is differ
Returns boolean signalling wherher file was rewritten
noc.core.fileutils.read_file(path)
Read file and return file's content.
Return None when file does not exists
noc.core.fileutils.copy_file(f, t, mode=None)
Copy File
noc.core.fileutils.write_tempfile(text)
Create temporary file, write content and return path
class noc.core.fileutils.temporary_file(text='')

Bases: object

Temporary file context manager.

Writes data to temporary file an returns path. Unlinks temporary file on exit USAGE:

with temporary_file(“line1
line2”) as p:
subprocess.Popen([“wc”,”-l”,p])
__enter__(self)
__exit__(self, type, value, tb)
noc.core.fileutils.in_dir(file, dir)
Check file is inside dir
noc.core.fileutils.urlopen(url, auto_deflate=False)
urlopen wrapper
noc.core.fileutils.make_persistent(path, tmp_suffix='.tmp')
Make file persistent removing `tmp_suffix` suffix
Parameters:path – File path
Returns:True if file has been moved, false otherwise