fileutils¶
File utilities.
New in version 1.8.
-
oslo_utils.fileutils.
delete_if_exists
(path, remove=<built-in function unlink>)¶ Delete a file, but ignore file not found error.
Parameters: - path – File to delete
- remove – Optional function to remove passed path
-
oslo_utils.fileutils.
ensure_tree
(path, mode=511)¶ Create a directory (and any ancestor directories required)
Parameters: - path – Directory to create
- mode – Directory creation permissions
-
oslo_utils.fileutils.
remove_path_on_error
(*args, **kwds)¶ Protect code that wants to operate on PATH atomically. Any exception will cause PATH to be removed.
Parameters: - path – File to work with
- remove – Optional function to remove passed path
-
oslo_utils.fileutils.
write_to_tempfile
(content, path=None, suffix=”, prefix=’tmp’)¶ Create a temporary file containing data.
Create a temporary file containing specified content, with a specified filename suffix and prefix. The tempfile will be created in a default location, or in the directory path, if it is not None. path and its parent directories will be created if they don’t exist.
Parameters: - content – bytestring to write to the file
- path – same as parameter ‘dir’ for mkstemp
- suffix – same as parameter ‘suffix’ for mkstemp
- prefix – same as parameter ‘prefix’ for mkstemp
For example: it can be used in database tests for creating configuration files.
New in version 1.9.