summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-08-07 18:16:17 +0200
committerMartin Sivak <msivak@redhat.com>2008-08-07 18:16:35 +0200
commitc47ac6a556445e37dbb74fb7673ef4d9c697e629 (patch)
tree5140c32f0d003108fbb3252af01baa0b773fcae0 /pyfirstaidkit
parent7e334e5e4626d8696e8127e494c9eee2fcbb8474 (diff)
downloadfirstaidkit-c47ac6a556445e37dbb74fb7673ef4d9c697e629.tar.gz
firstaidkit-c47ac6a556445e37dbb74fb7673ef4d9c697e629.tar.xz
firstaidkit-c47ac6a556445e37dbb74fb7673ef4d9c697e629.zip
Add PersistentBackup space
Diffstat (limited to 'pyfirstaidkit')
-rw-r--r--pyfirstaidkit/utils/backup.py22
1 files changed, 18 insertions, 4 deletions
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