armi.utils.directoryChangers module

class armi.utils.directoryChangers.DirectoryChanger(destination, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]

Bases: object

Utility to change directory.

Use with ‘with’ statements to execute code in a different dir, guaranteeing a clean return to the original directory

>>> with DirectoryChanger('C:\whatever')
...     pass
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. Note that if any of these files do not exist then the file will be skipped and a warning will be provided.

  • dumpOnException (bool, optional) – Flag to tell system to retrieve the entire directory if an exception is raised within a the context manager.

Establish the new and return directories

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

close()[source]

User requested close.

moveFiles()[source]

Copy filesToMove into the destination directory on entry.

retrieveFiles()[source]

Copy filesToRetrieve back into the initial directory on exit.

class armi.utils.directoryChangers.TemporaryDirectoryChanger(root=None, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]

Bases: armi.utils.directoryChangers.DirectoryChanger

Create temporary directory, changes into it, and if there is no error/exception generated when using a with statement, it deletes the directory.

Notes

If there is an error/exception generated while in a with statement, the temporary directory contents will be copied to the original directory and then the temporary directory will be deleted.

classmethod GetRandomDirectory(root)[source]
class armi.utils.directoryChangers.ForcedCreationDirectoryChanger(destination, filesToMove=None, filesToRetrieve=None, dumpOnException=True)[source]

Bases: armi.utils.directoryChangers.DirectoryChanger

Creates the directory tree necessary to reach your desired destination

armi.utils.directoryChangers.directoryChangerFactory()[source]