diff --git a/tuned/commands/repository.py b/tuned/commands/repository.py index 28eb95c..48d35c4 100644 --- a/tuned/commands/repository.py +++ b/tuned/commands/repository.py @@ -13,21 +13,46 @@ class CommandRepository(tuned.patterns.Singleton): self._loader = tuned.utils.PluginLoader("tuned.commands", "command_", tuned.plugins.Command) self._commands = {} - def execute(self, command_name, args): + storage = tuned.utils.storage.Storage.get_instance() + if storage.data.has_key("commands"): + for command_name, args in data["sysctl"].iteritems(): + self._execute(command_name, args) + + storage.data["commands"] = {} + + def _execute(self, command_name, args): # Load command on-the-fly if not self._commands.has_key(command_name): self._load_command(command_name) # Execute command and get the previously set values. log.debug("executing command %s with args %s" % (command_name, unicode(args))) - previous_args = self._commands[command_name].execute(args) + return self._commands[command_name].execute(args) + + def execute(self, command_name, args): + previous_args = self._execute(command_name, args) # Store the previously set values storage = tuned.utils.storage.Storage.get_instance() - storage.data[command_name] = previous_args + + if not storage.data["commands"].has_key(command_name) + storage.data["commands"][command_name] = previous_args + storage.save() + else: + #TODO: Maybe do not even allow running execute twice + # in a row and show error instead? + pass + + def revert(self, command_name): + storage = tuned.utils.storage.Storage.get_instance() + if not storage.data["commands"].has_key(command_name): + return + + self._execute(command_name, storage.data["commands"][command_name]) + del storage.data["commands"][command_name] storage.save() - def _load_command(self, command_name) + def _load_command(self, command_name): log.debug("loading command %s" % command_name) try: command_cls = self._loader.load(command_name)