Commit 34916201 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

AT5-259: run autopep8 tool on file.

parent eaea06a1
Loading
Loading
Loading
Loading
Loading
+133 −118
Original line number Diff line number Diff line
@@ -18,13 +18,13 @@ separate TANGO Devices.
# Python standard library
import sys
import os
from future.utils import with_metaclass
from collections import defaultdict

import threading
import time
import json
file_path = os.path.dirname(os.path.abspath(__file__))
print(file_path)
from future.utils import with_metaclass
from collections import defaultdict

# PROTECTED REGION END# //MidCspSubarrayBase.standardlibray_import

# tango imports
@@ -85,26 +85,32 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                # numpy array
                receptors = device_proxy.receptors
            except tango.DevFailed as tango_err:
                self.logger.warn("__monitor_add_receptors:",tango_err.args[0].desc)
                self.logger.warn("__monitor_add_receptors:",
                                 tango_err.args[0].desc)
            if len(receptors):
                # get the ids in receptor_list that are also in receptor
                receptors_assigned = [value for value in receptor_list if value in receptors]
                self._num_dev_completed_task[cmd_name] = len(receptors_assigned)
                receptors_assigned = [
                    value for value in receptor_list if value in receptors]
                self._num_dev_completed_task[cmd_name] = len(
                    receptors_assigned)
                if len(receptors_assigned) == len(receptor_list):
                    self.logger.info("All required receptors asigned!!")
                    self._sc_subarray_cmd_progress[device][cmd_name] = 100
                    # calculate the real execution time for the command
                    self._cmd_duration_measured[cmd_name] = (time.time() - self._sc_subarray_cmd_starting_time[device])
                    self._cmd_duration_measured[cmd_name] = (
                        time.time() - self._sc_subarray_cmd_starting_time[device])
                    break
            # check if sub-element command ended throwing an exception: in this case the
            # 'cmd_ended_cb' callback is invoked.
            if self._sc_subarray_cmd_exec_state[device][cmd_name] == CmdExecState.FAILED:
                self._alarm_raised = True
                break
            elapsed_time = time.time() - self._sc_subarray_cmd_starting_time[device]
            elapsed_time = time.time() - \
                self._sc_subarray_cmd_starting_time[device]
            if (elapsed_time > self._sc_subarray_cmd_duration_expected[device][cmd_name] or
                    self._sc_subarray_cmd_exec_state[device][cmd_name] == CmdExecState.TIMEOUT):
                msg = ("Timeout executing {} command  on device {}".format(cmd_name, device))
                msg = ("Timeout executing {} command  on device {}".format(
                    cmd_name, device))
                self.logger.warn(msg)
                self._sc_subarray_cmd_exec_state[device][cmd_name] = CmdExecState.TIMEOUT
                break
@@ -145,28 +151,34 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
            try:
                receptors = device_proxy.receptors
            except AttributeError as attr_err:
                self.logger.warn("RemoveReceptors:{}"-format(str(attr_err)))
                self.logger.warn("RemoveReceptors:{}".format(str(attr_err)))
            if len(receptors):
                # get the ids in receptor_list that are no more present in receptors
                receptors_removed = [value for value in receptor_list if value not in receptors]
                self._num_dev_completed_task[cmd_name] = len(receptors) - len(receptor_list)
                receptors_removed = [
                    value for value in receptor_list if value not in receptors]
                self._num_dev_completed_task[cmd_name] = len(
                    receptors) - len(receptor_list)
                if len(receptors_removed) == len(receptor_list):
                    self._sc_subarray_cmd_progress[device][cmd_name] = 100
                    # calculate the real execution time for the command
                    self._cmd_duration_measured[cmd_name] = (time.time() - self._sc_subarray_cmd_starting_time[device])
                    self.logger.info("Receptors {} have been successfully removed".format(receptor_list))
                    self._cmd_duration_measured[cmd_name] = (
                        time.time() - self._sc_subarray_cmd_starting_time[device])
                    self.logger.info(
                        "Receptors {} have been successfully removed".format(receptor_list))
                    break
            else:
                self.logger.info("Receptors already successfully removed".format(receptor_list))
                self.logger.info("Receptors already successfully removed")
                break
            # check if sub-element command ended throwing an exception: in this case the
            # 'cmd_ended_cb' callback is invoked.
            if self._sc_subarray_cmd_exec_state[device][cmd_name] == CmdExecState.FAILED:
                break
            elapsed_time = time.time() - self._sc_subarray_cmd_starting_time[device]
            elapsed_time = time.time() - \
                self._sc_subarray_cmd_starting_time[device]
            if (elapsed_time > self._sc_subarray_cmd_duration_expected[device][cmd_name] or
                    self._sc_subarray_cmd_exec_state[device][cmd_name] == CmdExecState.TIMEOUT):
                msg = ("Timeout executing {} command  on device {}".format(cmd_name, device))
                msg = ("Timeout executing {} command  on device {}".format(
                    cmd_name, device))
                self.logger.warn(msg)
                self._sc_subarray_cmd_exec_state[device][cmd_name] = CmdExecState.TIMEOUT
                break
@@ -266,7 +278,6 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
    # Class Properties
    # ----------------


    # -----------------
    # Device Properties
    # -----------------
@@ -351,7 +362,6 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
        self._receptor_to_vcc_map = {}
        self._receptor_id_list = []

         
        # PROTECTED REGION END #    //  MidCspSubarrayBase.init_device

    def always_executed_hook(self):
@@ -427,7 +437,6 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
        return self._assigned_vcc
        # PROTECTED REGION END #    //  MidCspSubarrayBase.assignedVcc_read


    # --------
    # Commands
    # --------
@@ -493,25 +502,23 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                                                 for pair in receptor_to_vcc)
                # build the list of the installed receptors
                self._receptor_id_list = list(self._receptor_to_vcc_map.keys())
            print("available_receptors:", available_receptors)
            print("available_receptors:", type(available_receptors))
            if not any(available_receptors):
                log_msg = "No available receptor to add to subarray {}".format(self.SubID)
                self.dev_logging(log_msg, tango.LogLevel.LOG_WARN)
                log_msg = "No available receptor to add to subarray {}".format(
                    self.SubID)
                self.logger.warn(log_msg)
                return
            receptor_membership = csp_master_proxy.receptorMembership
            print("receptor_membership:", receptor_membership)
        except tango.DevFailed as df:
            msg = "Failure in getting receptors information:" + str(df.args[0].reason)
            msg = "Failure in getting receptors information:" + \
                str(df.args[0].reason)
            tango.Except.throw_exception("Command failed", msg,
                                         "AddReceptors", tango.ErrSeverity.ERR)
        except AttributeError as attr_err:
            msg = "Failure in reading {}: {}".format(str(attr_err.args[0]), attr_err.__doc__)
            msg = "Failure in reading {}: {}".format(
                str(attr_err.args[0]), attr_err.__doc__)
            tango.Except.throw_exception("Command failed", msg,
                                         "AddReceptors", tango.ErrSeverity.ERR)
        for receptorId in argin:
            print("receptorId:", receptorId)
            print("self._receptor_id_list:", self._receptor_id_list)
            # check if the specified receptor id is a valid number (that is, belongs to the list
            # of provided receptors)
            if receptorId in self._receptor_id_list:
@@ -543,6 +550,7 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
            receptor_to_assign = list(tmp)
            # forward the command to the CbfSubarray
            proxy.command_inout_asynch("AddReceptors", receptor_to_assign, self._cmd_ended_cb)
                
            self._command_thread['addreceptors'] = threading.Thread(target=self.__monitor_add_receptors,
                                                                    name="Thread-AddReceptors",
                                                                    args=(receptor_to_assign,))
@@ -556,6 +564,7 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                                         "AddReceptors",
                                         tango.ErrSeverity.ERR)
        # PROTECTED REGION END #    //  MidCspSubarrayBase.AddReceptors

    @AdminModeCheck('RemoveReceptors')
    def is_RemoveReceptors_allowed(self):

@@ -618,13 +627,15 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                                if self._sc_subarray_event_id[self.CbfSubarray][attr.lower()] == 0:
                                    evt_id = proxy.subscribe_event(attr, tango.EventType.CHANGE_EVENT,
                                                                   self._attributes_change_evt_cb, stateless=False)
                                    self._sc_subarray_event_id[self.CbfSubarray][attr.lower()] = evt_id
                                    self._sc_subarray_event_id[self.CbfSubarray][attr.lower(
                                    )] = evt_id
                            except tango.DevFailed as tango_err:
                                self.logger.info(tango_err.args[0].desc)
                        # forward the command to CbfSubarray
                        proxy.command_inout_asynch("RemoveReceptors", receptors_to_remove, self._cmd_ended_cb)
                        self._cmd_execution_state['removereceptors'] = CmdExecState.RUNNING
                        self._sc_subarray_cmd_starting_time[self.CbfSubarray] = time.time()
                        self._sc_subarray_cmd_starting_time[self.CbfSubarray] = time.time(
                        )
                        # Note: rembember to put the comma in args=(receptors_to_remove,) otherwise
                        # the list is received as a numpy array!
                        self._command_thread['removereceptors'] = threading.Thread(target=self.__monitor_remove_receptors,
@@ -633,7 +644,8 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):

                        self._command_thread['removereceptors'].start()
                        return
                self.logger.info("No receptor to remove from subarray {}".format(self.get_name()))
                self.logger.info(
                    "No receptor to remove from subarray {}".format(self.get_name()))
                self._cmd_execution_state['removereceptors'] = CmdExecState.IDLE
                return
            except tango.DevFailed as tango_err:
@@ -649,7 +661,8 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                                             "RemoveReceptors",
                                             tango.ErrSeverity.ERR)
        else:
            log_msg = "Subarray {} not registered!".format(str(self.CbfSubarray))
            log_msg = "Subarray {} not registered!".format(
                str(self.CbfSubarray))
            self.logger.error(log_msg)
            tango.Except.throw_exception("Command failed",
                                         log_msg,
@@ -690,14 +703,15 @@ class MidCspSubarrayBase(with_metaclass(DeviceMeta, CspSubarray)):
                log_msg = ("RemoveAllReceptors failure. Reason: {} "
                           "Desc: {}".format(df.args[0].reason,
                                             df.args[0].desc))
                self.dev_logging(log_msg, tango.LogLevel.LOG_ERROR)
                self.logger.error(log_msg)
                tango.Except.re_throw_exception(df, "Command failed",
                                                "CspSubarray RemoveAllReceptors command failed",
                                                "Command()",
                                                tango.ErrSeverity.ERR)
        else:
            log_msg = "Subarray {} not registered!".format(str(self.CbfSubarray))
            self.dev_logging(log_msg, tango.LogLevel.LOG_ERROR)
            log_msg = "Subarray {} not registered!".format(
                str(self.CbfSubarray))
            self.logger.error(log_msg)
            tango.Except.throw_exception("Command failed",
                                         log_msg,
                                         "RemoveAllReceptors",
@@ -715,5 +729,6 @@ def main(args=None, **kwargs):
    return run((MidCspSubarrayBase,), args=args, **kwargs)
    # PROTECTED REGION END #    //  MidCspSubarrayBase.main


if __name__ == '__main__':
    main()