parent
077eb7d868
commit
e9397e3faf
1 changed files with 4 additions and 29 deletions
|
|
@ -13,46 +13,21 @@ class CommandRepository(tuned.patterns.Singleton):
|
|||
self._loader = tuned.utils.PluginLoader("tuned.commands", "command_", tuned.plugins.Command)
|
||||
self._commands = {}
|
||||
|
||||
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):
|
||||
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)))
|
||||
return self._commands[command_name].execute(args)
|
||||
|
||||
def execute(self, command_name, args):
|
||||
previous_args = self._execute(command_name, args)
|
||||
previous_args = self._commands[command_name].execute(args)
|
||||
|
||||
# Store the previously set values
|
||||
storage = tuned.utils.storage.Storage.get_instance()
|
||||
|
||||
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.data[command_name] = previous_args
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue