summaryrefslogtreecommitdiffstats
path: root/ipapython/sysrestore.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2012-06-08 08:31:37 +0200
committerRob Crittenden <rcritten@redhat.com>2012-06-10 21:23:10 -0400
commitc856fb60737612781fab30760bceeb8bbf6312d9 (patch)
treebea9c1f3240e876ac28eeb5db3eea2c5b9a036b3 /ipapython/sysrestore.py
parent4507dcda58bbe663597c43672f91af7225e2a9b4 (diff)
downloadfreeipa-c856fb60737612781fab30760bceeb8bbf6312d9.tar.gz
freeipa-c856fb60737612781fab30760bceeb8bbf6312d9.tar.xz
freeipa-c856fb60737612781fab30760bceeb8bbf6312d9.zip
Add sysupgrade state file
When IPA package is being updated, some of the configuration files are also updated. Sometimes it may be useful to store upgrade meta information for next package upgrades. For example an information that some config file was already updated and we don't want to update it again if user purposedly reverted the change. This patch adds a new StateFile in /var/lib/ipa/sysupgrade which is capable of holding this information. New sysupgrade.py module was created to provide simple API to access the upgrade state information.
Diffstat (limited to 'ipapython/sysrestore.py')
-rw-r--r--ipapython/sysrestore.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index 82817acad..7720fd6e3 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -41,7 +41,7 @@ SYSRESTORE_STATEFILE = "sysrestore.state"
class FileStore:
"""Class for handling backup and restore of files"""
- def __init__(self, path = SYSRESTORE_PATH):
+ def __init__(self, path = SYSRESTORE_PATH, index_file = SYSRESTORE_INDEXFILE):
"""Create a _StoreFiles object, that uses @path as the
base directory.
@@ -49,7 +49,7 @@ class FileStore:
about the original location of the saved files.
"""
self._path = path
- self._index = self._path + "/" + SYSRESTORE_INDEXFILE
+ self._index = os.path.join(self._path, index_file)
self.random = random.Random()
@@ -279,7 +279,7 @@ class StateFile:
enabled=False
"""
- def __init__(self, path = SYSRESTORE_PATH):
+ def __init__(self, path = SYSRESTORE_PATH, state_file = SYSRESTORE_STATEFILE):
"""Create a StateFile object, loading from @path.
The dictionary @modules, a member of the returned object,
@@ -290,7 +290,7 @@ class StateFile:
The keys in these latter dictionaries are arbitrary strings
and the values may either be strings or booleans.
"""
- self._path = path+"/"+SYSRESTORE_STATEFILE
+ self._path = os.path.join(path, state_file)
self.modules = {}
@@ -359,25 +359,44 @@ class StateFile:
self.save()
- def restore_state(self, module, key):
+ def get_state(self, module, key):
"""Return the value of an item of system state from @module,
- identified by the string @key, and remove it from the backed
- up system state.
+ identified by the string @key.
If the item doesn't exist, #None will be returned, otherwise
the original string or boolean value is returned.
"""
-
if not self.modules.has_key(module):
return None
- if not self.modules[module].has_key(key):
- return None
+ return self.modules[module].get(key, None)
- value = self.modules[module][key]
- del self.modules[module][key]
+ def delete_state(self, module, key):
+ """Delete system state from @module, identified by the string
+ @key.
- self.save()
+ If the item doesn't exist, no change is done.
+ """
+ try:
+ del self.modules[module][key]
+ except KeyError:
+ pass
+ else:
+ self.save()
+
+ def restore_state(self, module, key):
+ """Return the value of an item of system state from @module,
+ identified by the string @key, and remove it from the backed
+ up system state.
+
+ If the item doesn't exist, #None will be returned, otherwise
+ the original string or boolean value is returned.
+ """
+
+ value = self.get_state(module, key)
+
+ if value is not None:
+ self.delete_state(module, key)
return value