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.

This is mostly useful on Windows systems, where drive letters are not well defined across systems. In these cases, it is useful to try to convert to a UNC path if possible.

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

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

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

  • sourcePath (str) – Path of the file to be copied.

  • destinationPath (str) – Path for the copied file.

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)[source]

Recursively delete a path.

!!! careful with this !!! It can delete the entire cluster.

We add copious os.path.exists checks in case an MPI set of things is trying to delete everything at the same time. Always check filenames for some special flag when calling this, especially with full permissions on the cluster. You could accidentally delete everyone’s work with one misplaced line! This doesn’t ask questions.

Safety nets include an allow-list of paths.

This makes use of shutil.rmtree and os.remove

Returns:

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

Return type:

bool