armi.utils.pathTools module

This module contains commonly used functions relating to directories, files and path manipulations.

armi.utils.pathTools.armiAbsPath(*pathParts)[source]

Convert a list of path components to an absolute path, without drive letters if possible.

armi.utils.pathTools.copyOrWarn(filepathDescription, sourcePath, destinationPath)[source]

Copy a file or directory, or warn if the filepath doesn’t exist.

Parameters:
  • filepathDescription (str) – a description of the file and/or operation being performed.

  • sourcePath (str) – Filepath to be copied.

  • destinationPath (str) – Copied filepath.

armi.utils.pathTools.isFilePathNewer(path1, path2)[source]

Returns true if path1 is newer than path2.

Returns true if path1 is newer than path2, or if path1 exists and path2 does not, otherwise raises an IOError.

armi.utils.pathTools.isAccessible(path)[source]

Check whether user has access to a given path.

Parameters:

path (str) – a directory or file

armi.utils.pathTools.separateModuleAndAttribute(pathAttr)[source]

Return True of the specified python module, and attribute of the module exist.

Parameters:

pathAttr (str) – Path to a python module followed by the desired attribute. e.g.: /path/to/my/thing.py:MyClass

Notes

The attribute of the module could be a class, function, variable, etc.

Raises:

ValueError: – If there is no : separating the path and attr.

armi.utils.pathTools.importCustomPyModule(modulePath)[source]

Dynamically import a custom module.

Parameters:

modulePath (str) – Path to a python module.

Returns:

userSpecifiedModule – The imported python module.

Return type:

module

armi.utils.pathTools.moduleAndAttributeExist(pathAttr)[source]

Return True if the specified python module, and attribute of the module exist.

Parameters:

pathAttr (str) – Path to a python module followed by the desired attribute. e.g.: /path/to/my/thing.py:MyClass

Returns:

True if the specified python module, and attribute of the module exist.

Return type:

bool

Notes

The attribute of the module could be a class, function, variable, etc.

armi.utils.pathTools.cleanPath(path, mpiRank=0, forceClean=False)[source]

Recursively delete a path. This function checks for a few cases we know to be OK to delete: (1) Any TemporaryDirectoryChanger or output cache instance and (2) anything under the ARMI _FAST_PATH.

Be careful with editing this! Do not make it a generic can-delete-anything function, because it could in theory delete anything a user has write permissions on.

Returns:

success – True if file was deleted. False if it was not.

Return type:

bool