The openstack_dashboard.openstack.common.fileutils ModuleΒΆ

openstack_dashboard.openstack.common.fileutils.delete_if_exists(path, remove=<built-in function unlink>)[source]

Delete a file, but ignore file not found error.

Parameters:
  • path – File to delete
  • remove – Optional function to remove passed path
openstack_dashboard.openstack.common.fileutils.ensure_tree(path)[source]

Create a directory (and any ancestor directories required)

Parameters:path – Directory to create
openstack_dashboard.openstack.common.fileutils.file_open(*args, **kwargs)[source]

Open file

see built-in file() documentation for more details

Note: The reason this is kept in a separate module is to easily be able to provide a stub module that doesn’t alter system state at all (for unit tests)

openstack_dashboard.openstack.common.fileutils.read_cached_file(filename, force_reload=False)[source]

Read from a file if it has been modified.

Parameters:force_reload – Whether to reload the file.
Returns:A tuple with a boolean specifying if the data is fresh or not.
openstack_dashboard.openstack.common.fileutils.remove_path_on_error(*args, **kwds)[source]

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
openstack_dashboard.openstack.common.fileutils.write_to_tempfile(content, path=None, suffix='', prefix='tmp')[source]

Create temporary file or use existing file.

This util is needed for creating temporary file with specified content, suffix and prefix. If path is not None, it will be used for writing content. If the path doesn’t exist it’ll be created.

Parameters:
  • content – content for temporary 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.

Previous topic

The openstack_dashboard.openstack Module

Next topic

The openstack_dashboard.openstack.common.importutils Module

This Page