Loading csp-lmc-common/utils/decorators.py +48 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ sys.path.insert(0, utils_path) import tango import cspcommons from cspcommons import AdminMode, CmdExecState from cspcommons import AdminMode, ObsState, CmdExecState import functools class AdminModeCheck(object): Loading Loading @@ -50,6 +50,52 @@ class AdminModeCheck(object): return f(*args, **kwargs) return admin_mode_check VALID_OBS_STATE = {'abort' : [ObsState.CONFIGURING, ObsState.SCANNING], 'reset' : [ObsState.ABORTED], 'configscan' : [ObsState.IDLE, ObsState.READY], 'scan' : [ObsState.READY], 'endscan' : [ObsState.SCANNING], 'endsb' : [ObsState.READY, ObsState.IDLE], 'addbeam' : [ObsState.IDLE], 'removebeam' : [ObsState.IDLE] } class StateAndObsStateCheck(object): """ Class designed to be a decorator for the CspMaster methods. It checks the obsMode attribute value """ def __init__(self, args=False, kwargs=False): self._args = args self._kwargs = kwargs def __call__(self, f): @functools.wraps(f) def obs_state_check(*args, **kwargs): # get the device instance dev_instance = args[0] cmd_to_execute = self._args # check if the sub-array State is On, otherwise throws an exception if dev_instance.get_state() != tango.DevState.ON: msg_args = (cmd_to_execute, dev_instance.get_state()) err_msg = ("{} command can't be issued when the" " State is {} ".format(*msg_args)) tango.Except.throw_exception("Command not executable", err_msg, "StateAndObsStateCheck decorator", tango.ErrSeverity.ERR) # Check the obsState attribute value: valid values for the command to # execute are defined by VALID_OBS_STATE dictionary if dev_instance._obs_state in VALID_OBS_STATE[cmd_to_execute.lower()]: msg_args = (cmd_to_execute, ObsState(dev_instance._obs_state).name) err_msg = ("{} command can't be issued when the" " obsState is {} ".format(*msg_args)) tango.Except.throw_exception("Command not executable", err_msg, "ObsStateCheck decorator", tango.ErrSeverity.ERR) return f(*args, **kwargs) return obs_state_check class CmdInputArgsCheck(object): """ Class designed to be a decorator for the CspMaster methods. Loading Loading
csp-lmc-common/utils/decorators.py +48 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ sys.path.insert(0, utils_path) import tango import cspcommons from cspcommons import AdminMode, CmdExecState from cspcommons import AdminMode, ObsState, CmdExecState import functools class AdminModeCheck(object): Loading Loading @@ -50,6 +50,52 @@ class AdminModeCheck(object): return f(*args, **kwargs) return admin_mode_check VALID_OBS_STATE = {'abort' : [ObsState.CONFIGURING, ObsState.SCANNING], 'reset' : [ObsState.ABORTED], 'configscan' : [ObsState.IDLE, ObsState.READY], 'scan' : [ObsState.READY], 'endscan' : [ObsState.SCANNING], 'endsb' : [ObsState.READY, ObsState.IDLE], 'addbeam' : [ObsState.IDLE], 'removebeam' : [ObsState.IDLE] } class StateAndObsStateCheck(object): """ Class designed to be a decorator for the CspMaster methods. It checks the obsMode attribute value """ def __init__(self, args=False, kwargs=False): self._args = args self._kwargs = kwargs def __call__(self, f): @functools.wraps(f) def obs_state_check(*args, **kwargs): # get the device instance dev_instance = args[0] cmd_to_execute = self._args # check if the sub-array State is On, otherwise throws an exception if dev_instance.get_state() != tango.DevState.ON: msg_args = (cmd_to_execute, dev_instance.get_state()) err_msg = ("{} command can't be issued when the" " State is {} ".format(*msg_args)) tango.Except.throw_exception("Command not executable", err_msg, "StateAndObsStateCheck decorator", tango.ErrSeverity.ERR) # Check the obsState attribute value: valid values for the command to # execute are defined by VALID_OBS_STATE dictionary if dev_instance._obs_state in VALID_OBS_STATE[cmd_to_execute.lower()]: msg_args = (cmd_to_execute, ObsState(dev_instance._obs_state).name) err_msg = ("{} command can't be issued when the" " obsState is {} ".format(*msg_args)) tango.Except.throw_exception("Command not executable", err_msg, "ObsStateCheck decorator", tango.ErrSeverity.ERR) return f(*args, **kwargs) return obs_state_check class CmdInputArgsCheck(object): """ Class designed to be a decorator for the CspMaster methods. Loading