plugin commands: add numeric priority to enforce execution order
This commit is contained in:
parent
fcc0c5c6f4
commit
63558e96c1
2 changed files with 10 additions and 3 deletions
|
|
@ -227,7 +227,7 @@ class Plugin(object):
|
|||
"""
|
||||
Initialize commands.
|
||||
"""
|
||||
self._commands = {}
|
||||
self._commands = collections.OrderedDict()
|
||||
self._autoregister_commands()
|
||||
self._check_commands()
|
||||
|
||||
|
|
@ -249,14 +249,19 @@ class Plugin(object):
|
|||
info["custom"] = None
|
||||
info["set"] = member
|
||||
info["per_device"] = member._command["per_device"]
|
||||
info["priority"] = member._command["priority"]
|
||||
elif "get" in member._command:
|
||||
info["get"] = member
|
||||
elif "custom" in member._command:
|
||||
info["custom"] = member
|
||||
info["per_device"] = member._command["per_device"]
|
||||
info["priority"] = member._command["priority"]
|
||||
|
||||
self._commands[command_name] = info
|
||||
|
||||
# sort commands by priority
|
||||
self._commands = collections.OrderedDict(sorted(self._commands.iteritems(), key=lambda (name, info): info["priority"]))
|
||||
|
||||
def _check_commands(self):
|
||||
"""
|
||||
Check if all commands are defined correctly.
|
||||
|
|
|
|||
|
|
@ -17,12 +17,13 @@ __all__ = ["command_set", "command_get", "command_custom"]
|
|||
# return current_foo
|
||||
#
|
||||
|
||||
def command_set(name, per_device=False):
|
||||
def command_set(name, per_device=False, priority=0):
|
||||
def wrapper(method):
|
||||
method._command = {
|
||||
"set": True,
|
||||
"name": name,
|
||||
"per_device": per_device,
|
||||
"priority": priority,
|
||||
}
|
||||
return method
|
||||
|
||||
|
|
@ -37,12 +38,13 @@ def command_get(name):
|
|||
return method
|
||||
return wrapper
|
||||
|
||||
def command_custom(name, per_device=False):
|
||||
def command_custom(name, per_device=False, priority=0):
|
||||
def wrapper(method):
|
||||
method._command = {
|
||||
"custom": True,
|
||||
"name": name,
|
||||
"per_device": per_device,
|
||||
"priority": priority,
|
||||
}
|
||||
return method
|
||||
return wrapper
|
||||
|
|
|
|||
Loading…
Reference in a new issue