HWRF
trunk@4391
|
This class is intended to be used with the Python "with TempDir() as t" syntax. More...
This class is intended to be used with the Python "with TempDir() as t" syntax.
Example:
Public Member Functions | |
def | __init__ |
Creates a TempDir. More... | |
def | name_make_dir (self) |
Decide the name of the directory, and create the directory. More... | |
def | mkdir_cd (self) |
Creates the temporary directory and chdirs the current process into that directory. More... | |
def | cd_out (self) |
Exit the temporary directory created by mkdir_cd and return to the original directory, if possible. More... | |
def | cd_rmdir (self) |
CD out and remove the old directory. More... | |
def | exception_info (self) |
Called to dump information to a log, or failing that, the terminal if an unexpected exception is caught. More... | |
def | __enter__ (self) |
This is a simple wrapper around mkdir_cd that is intended to be used with in a "with" block. More... | |
def | __exit__ (self, etype, value, traceback) |
Exit the 'with' block. More... | |
Public Attributes | |
dirname | |
The name of the target directory. More... | |
suffix | |
Temporary directory name suffix. | |
prefix | |
Temporary directory name prefix. | |
print_on_exception | |
Should we print exceptions before exiting the directory? | |
dir | |
The directory object. More... | |
olddir | |
The name of the directory we came from. More... | |
def produtil.cd.TempDir.__init__ | ( | self, | |
suffix = '.tmp' , |
|||
prefix = 'tempdir.' , |
|||
dir = None , |
|||
keep = False , |
|||
logger = None , |
|||
print_on_exception = True , |
|||
add_perms = perm_add , |
|||
remove_perms = perm_remove , |
|||
keep_on_error = True , |
|||
cd = True |
|||
) |
Creates a TempDir.
suffix,prefix,dir | Passed to the tempfile.mkdtemp to generate the directory name. Meanings are the same as in that constructor. See the Python documentation for details. |
keep | Controls directory deletion if the "with" block returns without an exception. If False, the directory is deleted. Default: keep=False |
logger | A logging.logger for log messages |
print_on_exception | Print exceptions before leaving the dir |
add_perms | Permissions to add to the directory. Default: 755. |
remove_perms | Permissions to remove from the directory. Default: setuid and world write. |
keep_on_error | Controls directory deletion if the "with" block raises an Exception or GeneratorExit, or subclass thereof. If False, the directory is deleted under those circumstances. Default: keep_on_error=True. |
cd | If True (default), cd to the directory in the "with" block and cd back out afterwards. If False, then only directory creation and deletion happens. |
def produtil.cd.TempDir.__enter__ | ( | self | ) |
def produtil.cd.TempDir.__exit__ | ( | self, | |
etype, | |||
value, | |||
traceback | |||
) |
Exit the 'with' block.
This is a simple wrapper around cd_rmdir that is intended to be used with in a "with" block. This subroutine is automatically called at the end of the block. It will call cd_rmdir to delete the directory unless an exception is thrown that is NOT a subclass of Exception or GeneratorExit. The removal is skipped to allow the program to exit quickly in case of a fatal signal (ie.: SIGQUIT, SIGTERM, SIGINT, SIGHUP).
etype,value,traceback | exception information |
def produtil.cd.TempDir.cd_out | ( | self | ) |
Exit the temporary directory created by mkdir_cd and return to the original directory, if possible.
Definition at line 135 of file cd.py.
Referenced by produtil.cd.TempDir.__exit__(), and produtil.cd.TempDir.cd_rmdir().
def produtil.cd.TempDir.cd_rmdir | ( | self | ) |
CD out and remove the old directory.
This subroutine exits the temporary directory created by mkdir_cd, and then deletes that temporary directory. After this routine, the process will be in its original directory (from before the call to mkdir_cd) if possible, or otherwise it will be in the root directory (/).
It is the caller's responsibility to ensure this function is not called if keep_on_error=True and an error occurs.
Definition at line 141 of file cd.py.
Referenced by produtil.cd.TempDir.__exit__().
def produtil.cd.TempDir.exception_info | ( | self | ) |
Called to dump information to a log, or failing that, the terminal if an unexpected exception is caught.
Definition at line 181 of file cd.py.
Referenced by produtil.cd.TempDir.__exit__().
def produtil.cd.TempDir.mkdir_cd | ( | self | ) |
Creates the temporary directory and chdirs the current process into that directory.
It calls self.name_make_dir() to do the naming and directory creation.
Definition at line 126 of file cd.py.
Referenced by produtil.cd.TempDir.__enter__().
def produtil.cd.TempDir.name_make_dir | ( | self | ) |
Decide the name of the directory, and create the directory.
Also create any path components leading up to the directory.
Definition at line 108 of file cd.py.
Referenced by produtil.cd.TempDir.mkdir_cd().
produtil.cd.TempDir.dir |
The directory object.
Definition at line 78 of file cd.py.
Referenced by produtil.cd.TempDir.name_make_dir().
produtil.cd.TempDir.dirname |
The name of the target directory.
Definition at line 72 of file cd.py.
Referenced by produtil.cd.TempDir.cd_rmdir(), produtil.cd.TempDir.exception_info(), produtil.cd.TempDir.mkdir_cd(), produtil.cd.TempDir.name_make_dir(), and produtil.cd.NamedDir.name_make_dir().
produtil.cd.TempDir.olddir |
The name of the directory we came from.
Definition at line 79 of file cd.py.
Referenced by produtil.cd.TempDir.cd_out(), and produtil.cd.TempDir.mkdir_cd().