backup_file
- File objects with automated backup¶
Backup a file or directory to make editing reversible.
Implement the context manager protocol, so as to be suitable to be used with the with statement. When used in this fashion changes are discarded when an exception is thrown.
-
class
BackupDir
(dir_, ext='.BAK', mode=1)[source]¶ Move or copy a directory that needs to be recreated or modified.
-
__exit__
(exc_type, exc_val, exc_tb)[source]¶ When the controlling with statement is exited normally discard the backup directory, otherwise restore it to its original place.
-
__init__
(dir_, ext='.BAK', mode=1)[source]¶ Prepare to backup the dir_ directory.
The backup will be created in dir_’s parent directory, which must be writable, with extension ext. If mode is MOVE, the default, the original directory will be moved to the backup destination; if mode is COPY it will be copied there.
-
-
class
BackupFile
(file_, ext='.BAK', dir='.', mode=2)[source]¶ Implements a read only file object used to automatically back up a file that has to be modified.
-
__exit__
(exc_type, exc_val, exc_tb)[source]¶ When the controlling with statement is exited normally discard the backup file, otherwise restore it to its original place.
-
__init__
(file_, ext='.BAK', dir='.', mode=2)[source]¶ Prepare to backup file_, either a file-like object or a path.
The backup file will be created in directory dir with extension ext. If mode is COPY the original file will be copied to the backup destination; if mode is MOVE it will be moved there.
-
close
()[source]¶ Close the backup file and release the corresponding reference.
The backup file may not be reopened.
-
name
¶ The name of the file to be backed up.
-
-
exception
NotSavedError
[source]¶ Raised when commit or rollback is called on an inactive BackUpFile or BackUpDirectory.