cement.utils.fs

Common File System Utilities.

cement.utils.fs.abspath(path)[source]

Return an absolute path, while also expanding the ~ user directory shortcut.

Parameters:path (str) – The original path to expand.
Returns:The fully expanded, absolute path to the given path
Return type:str

Example

from cement.utils import fs

fs.abspath('~/some/path')
fs.abspath('./some.file')
cement.utils.fs.backup(path, suffix='.bak')[source]

Rename a file or directory safely without overwriting an existing backup of the same name.

Parameters:
  • path (str) – The path to the file or directory to make a backup of.
  • suffix (str) – The suffix to rename files with.
Returns:

The new path of backed up file/directory

Return type:

str

Example

from cement.core.utils import fs

fs.backup('/path/to/original/file')
cement.utils.fs.join(*args, **kwargs)[source]

Return a complete, joined path, by first calling abspath() on the first item to ensure the final path is complete.

Parameters:paths (list) – A list of paths to join together.
Returns:The complete and absolute joined path.
Return type:list

Example

from cement.utils import fs

fs.join('~/some/path', 'some/other/relevant/paht')