summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Andres Granados <jgranado@redhat.com>2008-08-07 19:02:36 +0200
committerJoel Andres Granados <jgranado@redhat.com>2008-08-07 19:06:31 +0200
commit51a175634d24eec42ad5a7cbe23660b42a63470c (patch)
tree49d6c1c1d8d3ed7bc562cff8ab98eb1b86774eaa
parentd26d9504b6eced4cebe9c81f304858a45725a1ee (diff)
downloadfirstaidkit-51a175634d24eec42ad5a7cbe23660b42a63470c.tar.gz
firstaidkit-51a175634d24eec42ad5a7cbe23660b42a63470c.tar.xz
firstaidkit-51a175634d24eec42ad5a7cbe23660b42a63470c.zip
Create a new backup directory every time, unless the user tells us otherwise.
Use tempfile to create safe backup directories. User should define backup.fullpath if he wants to override the default behaviour. User can also choose the directory where the backup directory goes.
-rw-r--r--pyfirstaidkit/configuration.py3
-rw-r--r--pyfirstaidkit/interpret.py4
-rw-r--r--pyfirstaidkit/utils/backup.py23
3 files changed, 21 insertions, 9 deletions
diff --git a/pyfirstaidkit/configuration.py b/pyfirstaidkit/configuration.py
index 499c0a8..b25bf1b 100644
--- a/pyfirstaidkit/configuration.py
+++ b/pyfirstaidkit/configuration.py
@@ -44,7 +44,8 @@ def createDefaultConfig(config):
config.log.fallbacks = "firstaidkit.log,/tmp/firstaidkit.log,/dev/null"
config.plugin.disabled = ""
config.backup.method = "file"
- config.backup.path = "/tmp/firstaidkitbackup"
+ config.backup.rootpath = "/tmp/fakbackup"
+ config.backup.fullpath = ""
# Setup a sane default root directory.
if os.path.isdir("/mnt/sysimage"):
diff --git a/pyfirstaidkit/interpret.py b/pyfirstaidkit/interpret.py
index 71c1152..8817b04 100644
--- a/pyfirstaidkit/interpret.py
+++ b/pyfirstaidkit/interpret.py
@@ -49,7 +49,9 @@ class Tasker:
self._reporting = reporting
if backups is None:
- self._backups = FileBackupStore(cfg.backup.path)
+ self._backups = FileBackupStore(rootpath = cfg.backup.rootpath,
+ fullpath = cfg.backup.fullpath)
+ cfg.backup.fullpath = self._backups._path
else:
self._backups = backups
diff --git a/pyfirstaidkit/utils/backup.py b/pyfirstaidkit/utils/backup.py
index f7670c2..79e4b85 100644
--- a/pyfirstaidkit/utils/backup.py
+++ b/pyfirstaidkit/utils/backup.py
@@ -25,6 +25,7 @@ import hashlib
import weakref
import cPickle as pickle
import copy
+import tempfile
class BackupException(Exception):
pass
@@ -209,20 +210,28 @@ class FileBackupStore(BackupStoreInterface):
return False
- def __init__(self, path):
+ def __init__(self, rootpath = "/tmp", fullpath = ""):
if self.__class__._singleton:
raise BackupException("BackupStore with %s type can have only "
"one instance" % (self.__name__,))
assert self.__class__._singleton==None
- self._path = path
- self._backups = {}
- if os.path.isdir(self._path):
- raise BackupException("Backupdir %s already exists. Erase dir or "
- "change backup dir." % self._path)
+ if fullpath:
+ if os.path.isdir(fullpath):
+ raise BackupException("Backupdir %s already exists. Erase "
+ "dir or change backup dir." % self._path)
+ else:
+ self._path = fullpath
+ os.makedirs(fullpath)
+
else:
- os.makedirs(self._path)
+ if not os.path.isdir(rootpath):
+ os.makedirs(rootpath)
+ self._path = tempfile.mkdtemp(prefix = "firstaidkitbackup-", dir = rootpath)
+
+ self._backups = {}
+
self.__class__._singleton = weakref.proxy(self)
print("Backup system initialized")