CLI

CLI access

exos.api.exec_cli(cmds, timeout=0)[source]

Send a list of commands to the CLI and return the output. cmds must be a list of strings. This call will block until all commands have completed. The output is returned as a string.

If ignore_errors is False, the default, execution will stop after the first failed command and raise a CLICommandError.

exos.api.exec_cli_async(cmds, callback, timeout=0)[source]

Send a list of commands to the CLI and return the output via a callback. This function returns immediately. cmds must be a list of strings.

callback is called with each block of output, which is typically a single line. The first parameter to callback is either CLI_EVENT_EXEC_REPLY, indicating this is just another block of output, or CLI_EVENT_EXEC_DONE, indicating a command has completed. A CLI_EVENT_EXEC_DONE is passed for each command sent.

The second parameter to callback is the output itself, as a string.

exos.api.CLI_EVENT_EXEC_REPLY

Used in an exec_cli_async() callback to indicate this is part of the output.

exos.api.CLI_EVENT_EXEC_DONE

Used in an exec_cli_async() callback to indicate the current command has finished.

exos.api.CLI_EVENT_EXEC_TIMEOUT

Used in an exec_cli_async() callback to indicate the current command has timed out.

Extending the CLI

A Python process can extend the CLI. This is especially useful when coupled with the cmbackend.

exos.api.register_cli_tree()[source]

Register this process with the CLI daemon and add its commands to the CLI syntax tree. The CLI daemon will look for a CLI definitions file at clidef/<process_name>.xml where <process_name> is the value of exosapi.get_process_name().

Namespaces

EXOS namespaces can be used in the CLI for tab completion. Each namespace is a list of strings with an optional value.

exos.api.namespace_add(namespace, entry, value=None, vr_name=None)[source]

Add entry and optional value to the CLI namespace. Optionally scope the namespace to a vr_name.

exos.api.namespace_delete(namespace, entry, vr_name=None)[source]

Delete entry from the CLI namespace. Optionally scope the namespace to a vr_name.

exos.api.namespace_purge(namespace)[source]

Purge all entries from the CLI namespace. Optionally scope the namespace to a vr_name.

Exceptions

class exos.api.CLITimeoutError[source]

A CLI request timed out.

class exos.api.CLICommandError(error_msg, cmd)[source]

A CLI command returned an error message. The error_msg attribute is the message received from the CLI and cmd is the command that was being run at the time.