zooui.backup.backupmanager module¶
Backup manager for automatic scene file backups with per-scene directories.
- class zooui.backup.backupmanager.BackupManager(config)[source]
Bases:
object- Constructor :
BackupManager(config: Dict[str, Any])
- Parameters :
- configDict[str, Any]
Configuration dictionary with autosave settings
BackupManager(config) –> None
Backup manager that creates per-scene backup directories under the XDG data directory with naming convention: {scene_filename}_{4char_path_hash}/
Each scene directory contains backups named: yy_mm_dd_hh_mm_filename_hash.pzs
Rotation is per-scene (keeps last N backups per scene). Scene directories expire after a configurable number of days since the last backup was written.
- Method :
BackupManager.__init__(config)
- Parameters :
- configDict[str, Any]
Configuration dictionary
BackupManager.__init__(config) –> None
Initialize backup manager with configuration.
- Parameters:
config – Configuration dictionary with ‘max_backups’ (default: 20), ‘expire_days’ (default: 7), ‘backup_dir’ (default: XDG data dir / backups)
- _get_scene_dir(source_path)[source]
Get the per-scene backup directory for a given source file.
Directory name format: {filename_stem}_{4char_hash_of_absolute_path}
- Parameters:
source_path – Path to the scene file
- Returns:
Per-scene backup directory path
- Return type:
Path
- _ensure_backup_dir()[source]
Ensure backup root directory exists.
- _show_error_dialog(message)[source]
Show error dialog without parent widget.
- _generate_backup_filename(source_path)[source]
Generate backup filename with format: yy_mm_dd_hh_mm_filename_hash.pzs
- Parameters:
source_path – Path to original file
- Returns:
Generated backup filename
- Return type:
str
- create_backup(source_path)[source]
- Method :
BackupManager.create_backup(source_path)
- Parameters :
- source_pathstr
Path to the scene file to backup
BackupManager.create_backup(source_path) –> Optional[str]
Create a backup of the scene file in its per-scene directory. Rotation and expiration cleanup are triggered automatically.
- Parameters:
source_path – Path to the scene file to backup
- Returns:
Path to created backup file, or None if failed
- Return type:
Optional[str]
- _rotate_backups(scene_dir)[source]
Keep only the last N backups within a scene directory, delete oldest ones.
- Parameters:
scene_dir – The per-scene backup directory to rotate
- _cleanup_expired()[source]
Delete expired backup scene directories.
Directories are considered expired if their mtime is older than expire_days (default 7). Empty or non-backup directories are also cleaned up.
- Returns:
Number of directories deleted
- Return type:
int
- cleanup_expired_dirs()[source]
- Method :
BackupManager.cleanup_expired_dirs()
- Parameters :
None
BackupManager.cleanup_expired_dirs() –> int
Public method to delete expired backup scene directories.
- Returns:
Number of directories deleted
- Return type:
int
- cleanup_flat_backups()[source]
- Method :
BackupManager.cleanup_flat_backups()
- Parameters :
None
BackupManager.cleanup_flat_backups() –> int
Delete legacy flat backup files from the root backup directory. Used for migrating from the old flat structure to the new per-scene directory structure. Only deletes *.pzs files directly in the backup root (not in subdirectories).
- Returns:
Number of flat backup files deleted
- Return type:
int
- get_backup_count(source_path=None)[source]
- Method :
BackupManager.get_backup_count(source_path=None)
- Parameters :
- source_pathOptional[str]
Path to the scene file (counts backups for specific scene), or None (counts backups across all scenes)
BackupManager.get_backup_count(source_path=None) –> int
Get current number of backup files.
- Parameters:
source_path – Optional scene path to count backups for a specific scene. If None, counts all backups across all scenes.
- Returns:
Number of backup files
- Return type:
int
- list_backups(source_path=None)[source]
- Method :
BackupManager.list_backups(source_path=None)
- Parameters :
- source_pathOptional[str]
Path to the scene file (lists backups for specific scene), or None (lists backups across all scenes)
BackupManager.list_backups(source_path=None) –> List[str]
List all backup files sorted by modification time (newest first).
- Parameters:
source_path – Optional scene path to list backups for a specific scene. If None, lists all backups across all scenes.
- Returns:
List of backup file paths relative to backup root
- Return type:
List[str]
- cleanup_all()[source]
- Method :
BackupManager.cleanup_all()
- Parameters :
None
BackupManager.cleanup_all() –> int
Delete all backup files and directories.
- Returns:
Number of items (files + directories) deleted
- Return type:
int
See Also¶
zooui/windows/dialogwindows/autosavesettingsdialog - Autosave settings UI
zooui/config - Autosave configuration
Program Configuration - User configuration guide