utils¶
-
ska.low.mccs.utils.
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
Example:
class MyDevice(Device): @command def some_command(self): if condition: pass else: tango_throw("Condition not true")
- Parameters
msg ([type]) – [description]
reason (str, optional) – the tango api DevError description string, defaults to “API_CommandFailed”
severity (tango.ErrSeverity, optional) – the tango error severity, defaults to tango.ErrSeverity.ERR
_origin (str, optional) – the calling object name, defaults to None (autodetected) Note that autodetection only works for class methods not e.g. decorators
-
ska.low.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.low.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
- Raises
FileNotFoundException – if no file is found at the schema path provided
json.JSONDecodeError – if the file at the specified schema path is not valid JSON
- 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.