utils

ska.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.

Parameters
  • func – the function to call

  • kwargs – parameters to be jsonified and passed to func

Ptype func

callable

Ptype kwargs

any

Returns

the return value of func

Example

Suppose you need to use MccsMaster.Allocate() to command a master 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} json_string=json.dumps(parameters) master.Allocate(json_string)

save yourself the trouble and

call_with_json(master.Allocate,

id=id, stations=stations, tiles=tiles)

class ska.mccs.utils.json_input(schema_path=None)[source]

Method decorator that parses and validates JSON input into a python object. The wrapped method is thus called with a JSON string, but can be implemented as if it had been passed an object.

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

Parameters

schema_path – an optional path to a schema against which the JSON should be validated. Not working at the moment, so leave it None.

Ptype

string

Example

Conceptually, MccsMaster.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:

@json_input def MccsMaster.Allocate(id, stations, tiles):

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