armi.utils.directoryChangers module¶
-
class
armi.utils.directoryChangers.DirectoryChanger(destination, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]¶ Bases:
objectUtility to change directory.
- Parameters
destination (str) – Path of directory to change into
filesToMove (list of str, optional) – Filenames to bring from the CWD into the destination
filesToRetrieve (list of str, optional) – Filenames to bring back from the destination to the cwd
dumpOnException (bool, optional) – Flag to tell system to retrieve the entire directory if an exception is raised within a the context manager.
with 'with' statements to execute code in a different dir, guaranteeing a clean (Use) –
to the original directory (return) –
with DirectoryChanger('C (>>>) –
pass (..) –
Establish the new and return directories
-
__enter__()[source]¶ At the inception of a with command, navigate to a new directory if one is supplied.
-
__exit__(exc_type, exc_value, traceback)[source]¶ At the termination of a with command, navigate back to the original directory.
-
open()[source]¶ User requested open, used to stalling the close from a with statement.
This method has been made for old uses of
os.chdir()and is not recommended. Please use the with statements
-
_retrieveEntireFolder()[source]¶ Retrieve all files to a dump directory.
This is used when an exception is caught by the DirectoryChanger to rescue the entire directory to aid in debugging. Typically this is only called if
dumpOnExceptionis True.
-
static
_transferFiles(initialPath, destinationPath, fileList)[source]¶ Transfer files into or out of the directory.
This is used in
moveFilesandretrieveFilesto shuffle files about when creating a target directory or when coming back, respectively. Beware that this usesshutil.copy()under the hood, which doesn’t play nicely with directories. Future revisions should improve this.- Parameters
initialPath (str) – Path to the folder to find files in.
destinationPath (str) – Path to the folder to move file to.
fileList (list of str or list of tuple) – File names to move from initial to destination. If this is a simple list of strings, the files will be transferred. Alternatively tuples of (initialName, finalName) are allowed if you want the file renamed during transit. In the non-tuple option, globs/wildcards are allowed.
warning: (.) – On Windows the max number of characters in a path is 260.: If you exceed this you will see FileNotFound errors here.
-
class
armi.utils.directoryChangers.TemporaryDirectoryChanger(root=None, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]¶ Bases:
armi.utils.directoryChangers.DirectoryChangerCreate temporary directory, changes into it, and if there is no error/exception generated when using a
withstatement, it deletes the directory.Notes
If there is an error/exception generated while in a
withstatement, the temporary directory contents will be copied to the original directory and then the temporary directory will be deleted.Establish the new and return directories
-
class
armi.utils.directoryChangers.ForcedCreationDirectoryChanger(destination, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]¶ Bases:
armi.utils.directoryChangers.DirectoryChangerCreates the directory tree necessary to reach your desired destination
Establish the new and return directories