snakeoil.fileutils module

file related operations, mainly reading

class snakeoil.fileutils.AtomicWriteFile(fp, binary=False, perms=None, uid=-1, gid=-1)[source]

Bases: AtomicWriteFile_mixin

File class that stores the changes in a tempfile.

Upon invocation of the close method, this class will use os.rename() to atomically replace the destination.

Similar to file protocol behavior, except that close must be called for the changes to be made live,

If along the way it’s decided that these changes should be discarded, invoke AtomicWriteFile.discard(); this will close the file without updating the target.

If this object falls out of memory without ever being discarded nor closed, the contents are discarded and a warning is issued.

class snakeoil.fileutils.AtomicWriteFile_mixin(fp, binary=False, perms=None, uid=-1, gid=-1)[source]

Bases: object

File class that stores the changes in a tempfile.

Upon invocation of the close method, this class will use os.rename() to atomically replace the destination.

Similar to file protocol behavior, except that close must be called for the changes to be made live,

If along the way it’s decided that these changes should be discarded, invoke AtomicWriteFile.discard(); this will close the file without updating the target.

If this object falls out of memory without ever being discarded nor closed, the contents are discarded and a warning is issued.

close()[source]

Close this file handle, atomically updating the target in the process.

Note that if we’re already closed, this method does nothing

discard()[source]

If we’ve not already flushed our changes to the target, discard them and close this file handle.

snakeoil.fileutils.mmap_or_open_for_read(path: str)[source]
snakeoil.fileutils.touch(fname: str, mode: int = 420, dir_fd=None, **kwargs)[source]

touch(1) equivalent

Parameters:
  • fname – file path

  • mode – file mode

See os.utime for other supported arguments.