Utils module (ska_low_mccs.utils)

Module for MCCS utils.

call_with_json(func, **kwargs)[source]

Allows the calling of a command that accepts a JSON string as input, with the actual unserialised parameters.

For example, suppose you need to use Allocate(resources) command to tell a controller device to allocate certain stations and tiles to a subarray. Allocate accepts a single JSON string argument. Instead of


parameters={"id": id, "stations": stations, "tiles": tiles}

save yourself the trouble and


call_with_json(controller.Allocate, id=id, stations=stations, tiles=tiles)
  • func – the function handle to call

  • kwargs – parameters to be jsonified and passed to func


the return value of func

class json_input(schema_path=None)[source]

Method decorator that parses and validates JSON input into a python dictionary, which is then passed to the method as kwargs. The wrapped method is thus called with a JSON string, but can be implemented as if it had been passed a sequence of named arguments.

If the string cannot be parsed as JSON, an exception is raised.

For example, conceptually, MccsController.Allocate() takes as arguments a subarray id, an array of stations, and an array of tiles. In practice, however, these arguments are encoded into a JSON string. Implement the function with its conceptual parameters, then wrap it in this decorator:


def MccsController.Allocate(id, stations, tiles):

The decorator will provide the JSON interface and handle the decoding for you.


Initialises a callable json_input object, to function as a device method generator.


schema_path (typing.Optional[str]) – an optional path to a schema against which the JSON should be validated. Not working at the moment, so leave it None.

tango_raise(msg, reason='API_CommandFailed', severity=tango.ErrSeverity.ERR, _origin=None)[source]

Helper function to provide a concise way to throw tango.Except.throw_exception.


class MyDevice(Device):
    def some_command(self):
        if condition:
            tango_throw("Condition not true")
  • msg (str) – message

  • reason (str) – the tango api tango.DevError description string, defaults to “API_CommandFailed”

  • severity (tango.ErrSeverity) – the tango error severity, defaults to tango.ErrSeverity.ERR

  • _origin (typing.Optional[str]) – the calling object name, defaults to None (autodetected) Note that autodetection only works for class methods not e.g. decorators


TypeError – if used from an object that is not a tango device instance

Return type