From c47ac6a556445e37dbb74fb7673ef4d9c697e629 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 7 Aug 2008 18:16:17 +0200 Subject: Add PersistentBackup space --- pyfirstaidkit/utils/backup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'pyfirstaidkit/utils/backup.py') diff --git a/pyfirstaidkit/utils/backup.py b/pyfirstaidkit/utils/backup.py index 7cfc1a5..96c7677 100644 --- a/pyfirstaidkit/utils/backup.py +++ b/pyfirstaidkit/utils/backup.py @@ -53,6 +53,10 @@ class BackupStoreInterface(object): def exists(self, name = None, path = None): raise NotImplemented() + class PersistentBackup(BackupStoreInterface.Backup): + def cleanup(self): + return False + def __init__(self): raise NotImplemented() @@ -179,6 +183,7 @@ class FileBackupStore(BackupStoreInterface): for name in _datakeys: self.delete(name) os.rmdir(self._path) + return True def exists(self, name=None, path=None): if name == None and path == None: @@ -202,6 +207,10 @@ class FileBackupStore(BackupStoreInterface): return False + class PersistentBackup(FileBackupStore.Backup): + def cleanup(self): + return False + def __init__(self, path): if self.__class__._singleton: raise BackupException("BackupStore with %s type can have only " @@ -227,16 +236,21 @@ class FileBackupStore(BackupStoreInterface): def closeBackup(self, id): if not self._backups.has_key(id): raise BackupException("Backup with id %s does not exist" % (id,)) - self._backups[id].cleanup() - del self._backups[id] + if self._backups[id].cleanup(): + del self._backups[id] def __del__(self): if self.__class__._singleton is None: return + backupEmpty = True + for id,backup in self._backups.iteritems(): - backup.cleanup() - os.rmdir(self._path) + backupEmpty = backupEmpty and backup.cleanup() + + if backupEmpty: + os.rmdir(self._path) + print("Backup closed") @classmethod -- cgit