armi.utils.directoryChangers module

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

Bases: object

Utility 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

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.

_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 dumpOnException is True.

static _transferFiles(initialPath, destinationPath, fileList)[source]

Transfer files into or out of the directory.

This is used in moveFiles and retrieveFiles to shuffle files about when creating a target directory or when coming back, respectively. Beware that this uses shutil.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.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.

Establish the new and return directories

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

Establish the new and return directories

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