diff options
-rwxr-xr-x | firstaidkitrevert | 76 | ||||
-rw-r--r-- | plugins/grub/grub.py | 2 | ||||
-rw-r--r-- | pyfirstaidkit/utils/backup.py | 10 |
3 files changed, 44 insertions, 44 deletions
diff --git a/firstaidkitrevert b/firstaidkitrevert index f8b0ce4..3a6061b 100755 --- a/firstaidkitrevert +++ b/firstaidkitrevert @@ -16,21 +16,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import getopt, sys, os, os.path, pickle +import getopt, sys, os, os.path, pickle, logging from pyfirstaidkit import Config from pyfirstaidkit import reporting from pyfirstaidkit import initLogger from pyfirstaidkit.plugins import PluginSystem from pyfirstaidkit.dependency import Dependencies - -import logging - - - -# backup object location inside the backup directory. -# FIXME: Take this value from the Backup class. -bolocation = "__meta.pickle" +from pyfirstaidkit.utils.backup import FileBackupStore def usage(name): print("""Usage: @@ -50,45 +43,38 @@ opts: present in directory. """) % (name,) -def revert(picklepath, plugin, report): - """ user the plugin revert function with the backup object stored in path. +def revert(backup, plugin, report): + """ use the plugin revert function with the backup object stored in path. - path - Path to pickle file for backup object of plugin. - plugin - module that has the revert fuction. + backup - BackupPersistent object. + plugin - The plugin class. + report - the reporting object. """ - # We recover the backup object from the pickle file. - try: - fd = open(picklepath, 'rb') - backup = pickle.load(fd) - fd.close() - except: - Logger.critical("FAK Revert: An error has occured while accessing the backup " \ - "object for %s." % plugin) - sys.exit(1) # We try to execute the plugin revert function. try: plugink = plugin.get_plugin() plugink.revert(backup, report) except: - Logger.warning("FAK Revert: An Erro has occured whle executing the revert " \ - "function for plugin %s/" % plugin) + Logger.warning("FAK Revert: An Error has occured whle executing the " \ + "revert function for plugin %s/" % plugin) -def findPicklePath(plugin): - retval = os.path.join(Config.revert.dir, \ - plugin.__name__.split('.')[-1:][0], bolocation) - if os.path.isfile(retval): - return retval +def findPluginIdPath(plugin): + pluginid = plugin.__name__.split('.')[-1:][0] + pluginpath = os.path.join(Config.revert.dir, pluginid) + if os.path.isdir(pluginpath): + retval = (pluginid, pluginpath) else: - # Ask the plugin for the directory name. - try: - retval = os.path.join(Config.revert.dir, plugin.getBackupId()) - except: - Logger.warning("FAK Revert: No backup directory was found for %s." \ - % plugin.__name__) - retval = "" + pluginid = plugin.getBackupId() + pluginpath = os.path.join(Config.revert.dir, pluginid) + if os.path.isdir(pluginpath): + retval = (pluginid, pluginpath) + else: + Logger.warning("FAK Revert: No backup directory was found " \ + "for %s." % plugin.__name__) + retval = (None, None) # FIXME: if there is a change of the namespace for the current # plugin being different from the namespace of the same plugin @@ -96,7 +82,6 @@ def findPicklePath(plugin): return retval - if __name__ == "__main__": try: (opts, vars) = getopt.getopt(sys.argv[1:], "c:P", \ @@ -172,8 +157,8 @@ if __name__ == "__main__": try: ps = PluginSystem(report, Dependencies()) except: - Logger.critical("FAK Revert: An error has occured while creating the Plugin " \ - "system.") + Logger.critical("FAK Revert: An error has occured while creating " \ + "the Plugin system.") sys.exit(1) if Config.revert.all == "True": @@ -181,8 +166,13 @@ if __name__ == "__main__": # we execute the revert for all plugins passed by the user. for plugin in plugins: - picklepath = findPicklePath(ps._plugins[plugin]) - if picklepath == "": - Logger.warning("FAK Revert: Revert found no backup object for %s" % plugin) + (id, path) = findPluginIdPath(ps._plugins[plugin]) + if id is None or path is None: + Logger.warning("FAK Revert: Revert found no backup object " \ + "for %s" % plugin) else: - revert(picklepath, ps._plugins[plugin], report) + # We create the backup persistent object bpo before passing it to + # the revert function. + bpo = FileBackupStore.BackupPersistent(id, path, reverting = True) + bpo.loadMeta() + revert(bpo, ps._plugins[plugin], report) diff --git a/plugins/grub/grub.py b/plugins/grub/grub.py index 3a4f247..8cc6eec 100644 --- a/plugins/grub/grub.py +++ b/plugins/grub/grub.py @@ -52,7 +52,7 @@ class Grub(Plugin): origin = Grub) try: fd = os.open(devpath, os.O_WRONLY) - first446btemp = os.write(fd, 446) + os.write(fd, first446bytes) os.close(fd) except IOError, ie: report.debug("There was an error writing to %s, It is very " \ diff --git a/pyfirstaidkit/utils/backup.py b/pyfirstaidkit/utils/backup.py index 244e223..be086fb 100644 --- a/pyfirstaidkit/utils/backup.py +++ b/pyfirstaidkit/utils/backup.py @@ -238,6 +238,16 @@ class FileBackupStore(BackupStoreInterface): return False class BackupPersistent(Backup): + def __init__(self, id, path, reverting = False): + self._id = id + self._path = path + self._metafile = "__meta.pickle" + self._data = {} # name -> (stored as, origin) + self._origin = {} # origin -> name + + if not reverting: + os.makedirs(self._path) + def cleanup(self): self.saveMeta() return False |