iotile.core.utilities.command_file

A parser/generator for a list of commands with arguments.

All commands are single words with arguments as follows:

command_name {arg1, arg2, arg3}

If the contents of argN contains a , or begins or ends with whitespace it is utf-8 encoded and stored as hex of the form hex:xxxxx

Module Contents

Command
class CommandFile(filetype, version, commands=None)

A versioned and typed list of commands.

Args:

filetype (str): The name of the file type version (str): An X.Y.Z version number commands (list): A list of Command objects used to

initialize the command file.
add(self, command, *args)

Add a command to this command file.

Args:
command (str): The command to add *args (str): The parameters to call the command with
save(self, outpath)

Save this command file as an ascii file.

Agrs:
outpath (str): The output path to save.
dump(self)

Dump all commands in this object to a string.

Returns:
str: An encoded list of commands separated by

characters suitable for saving to a file.

classmethod FromString(cls, indata)

Load a CommandFile from a string.

The string should be produced from a previous call to encode.

Args:
indata (str): The encoded input data.
Returns:
CommandFile: The decoded CommandFile object.
classmethod FromFile(cls, inpath)

Load a CommandFile from a path.

Args:
inpath (str): The path to the file to load
Returns:
CommandFile: The decoded CommandFile object.
classmethod encode(cls, command)

Encode a command as an unambiguous string.

Args:
command (Command): The command to encode.
Returns:
str: The encoded command
classmethod decode(cls, command_str)

Decode a string encoded command back into a Command object.

Args:
command_str (str): The encoded command string output from a
previous call to encode.
Returns:
Command: The decoded Command object.