Commit e84b2e3e authored by Jelte Jansen's avatar Jelte Jansen
Browse files

function to create and 'parse' ccsession commands, and a list of fixed (non-module) command names

git-svn-id: svn:// e5f2f494-b856-4b98-b285-d166d9295462
parent fa51470d
......@@ -74,6 +74,37 @@ def create_answer(rcode, arg = None):
return { 'result': [ rcode ] }
# 'fixed' commands
"""Fixed names for command and configuration messages"""
COMMAND_COMMANDS_UPDATE = "commands_update"
COMMAND_SPECIFICATION_UPDATE = "specification_update"
COMMAND_GET_COMMANDS_SPEC = "get_commands_spec"
COMMAND_GET_CONFIG = "get_config"
COMMAND_SET_CONFIG = "set_config"
COMMAND_GET_MODULE_SPEC = "get_module_spec"
def parse_command(msg):
"""Parses what may be a command message. If it looks like one,
the function returns (command, value) where command is a
string. If it is not, this function returns None, None"""
if type(msg) == dict and len(msg.items()) == 1:
cmd, value = msg.popitem()
if type(cmd) == str:
return cmd, value
return None, None
def create_command(command_name, params = None):
"""Creates a module command message with the given command name (as
specified in the module's specification, and an optional params
# TODO: validate_command with spec
cmd = [ command_name ]
if params:
msg = { 'command': cmd }
return msg
class ModuleCCSession(ConfigData):
"""This class maintains a connection to the command channel, as
well as configuration options for modules. The module provides
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment