diff --git a/tuned/commands/__init__.py b/tuned/commands/__init__.py deleted file mode 100644 index 4e7dc2b..0000000 --- a/tuned/commands/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -import base -import repository - -__all__ = ["repository", "get_repository", "Command"] - -def get_repository(): - return repository.CommandRepository.get_instance() - -Command = base.Command diff --git a/tuned/commands/base.py b/tuned/commands/base.py deleted file mode 100644 index 744da5d..0000000 --- a/tuned/commands/base.py +++ /dev/null @@ -1,32 +0,0 @@ -class Command(object): - """ - Base class for all commands. - - Commands contain algorithms and system commands to change the tuning on live - system and are also able to revert the changes they have done. - - Methods requiring reimplementation: - - execute(self, args) - - revert(self, args) - """ - def __init__(self, name, desc = ""): - self._name = name - self._desc = desc - - @property - def name(self): - return self._desc - - @property - def desc(self): - return self._desc - - @desc.setter - def desc(self, desc): - self._desc = desc - - def execute(self, args): - raise NotImplementedError() - - def revert(self, args): - raise NotImplementedError() diff --git a/tuned/commands/exception.py b/tuned/commands/exception.py deleted file mode 100644 index 413965a..0000000 --- a/tuned/commands/exception.py +++ /dev/null @@ -1,22 +0,0 @@ -import tuned.exceptions - -class LoadCommandException(tuned.exceptions.TunedException): - def __init__(self, command_name, inner_exception = None): - super(self.__class__, self).__init__() - self._command_name = command_name - self._inner_exception = inner_exception - - @property - def command_name(self): - return self._command_name - - @property - def inner_exception(self): - return self._inner_exception - - def __str__(self): - message = "Unable to load command '%s'" % self._command_name - if self._inner_exception is not None: - message += " (%s)" % str(self._inner_exception) - - return message[0].lower() + message[1:] diff --git a/tuned/commands/repository.py b/tuned/commands/repository.py deleted file mode 100644 index 28eb95c..0000000 --- a/tuned/commands/repository.py +++ /dev/null @@ -1,43 +0,0 @@ -import tuned.patterns -import tuned.logs -import tuned.utils -import tuned.commands -import tuned.commands.exception -import tuned.utils.storage - -log = tuned.logs.get() - -class CommandRepository(tuned.patterns.Singleton): - def __init__(self): - super(self.__class__, self).__init__() - self._loader = tuned.utils.PluginLoader("tuned.commands", "command_", tuned.plugins.Command) - self._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) - - # Store the previously set values - storage = tuned.utils.storage.Storage.get_instance() - storage.data[command_name] = previous_args - storage.save() - - def _load_command(self, command_name) - log.debug("loading command %s" % command_name) - try: - command_cls = self._loader.load(command_name) - command_instance = command_cls() - self._commands[command_instance.name](command_instance) - return command_instance - except Exception as exception: - command_exception = tuned.plugins.exception.LoadCommandException(command_name, exception) - raise command_exception - - def delete(self, command_name): - log.debug("removing command %s" % command_name) - del self._commands[command_name]