def test_GIVEN_axis_param_with_NO_characteristic_value_WHEN_create_beamline_THEN_param_info_contains_empty_value(self):
        param = AxisParameter("MYVALUE", self.comp, ChangeAxis.POSITION)
        pvmanager = self.create_beamline(param)

        pv_definition = pvmanager.PVDB[PARAM_INFO_LOOKUP[BeamlineParameterGroup.COLLIMATION_PLANE]]
        pv_value = convert_from_json(dehex_and_decompress(pv_definition["value"]))

        assert_that(pv_value[0], has_entry("characteristic_value", ""))
 def test_interest_medium_pvs_correct(self):
     on_fly_pvs = self.ms.pv_list
     data = [json.loads(dehex_and_decompress(x)) for x in on_fly_pvs.values()]
     pv_names = []
     for item in data:
         if len(item) > 0:
             pv_names.extend([x[0] for x in item])
     for name in MEDIUM_PV_NAMES:
         self.assertTrue(name in pv_names)
    def test_GIVEN_axis_param_with_description_WHEN_create_beamline_THEN_param_info_contains_description(self):
        expected_description = "MOT:MTR0101.RBV"
        param = AxisParameter("MYVALUE", self.comp, ChangeAxis.POSITION,
                              description=expected_description)
        pvmanager = self.create_beamline(param)

        pv_definition = pvmanager.PVDB[PARAM_INFO_LOOKUP[BeamlineParameterGroup.COLLIMATION_PLANE]]
        pv_value = convert_from_json(dehex_and_decompress(pv_definition["value"]))

        assert_that(pv_value[0], has_entry("description", expected_description))
    def test_given_valid_devices_data_when_device_xml_saved_then_saved(self):
        # Arrange:
        self.dm.initialise()

        # Act: Save the new data to file
        self.dm.save_devices_xml(EXAMPLE_DEVICES)

        # Assert:
        # Device screens in blockserver should have been updated with value written to device manager
        self.assertEquals(EXAMPLE_DEVICES, dehex_and_decompress(self.bs.pvs[GET_SCREENS]))
    def test_given_invalid_devices_data_when_device_xml_saved_then_not_saved(self):
        # Arrange:
        self.dm.initialise()

        # Act: Save invalid new data to file
        self.dm.save_devices_xml(INVALID_DEVICES)

        # Assert
        # Should stay as blank (i.e. the previous value)
        self.assertEquals(self.dm.get_blank_devices(), dehex_and_decompress(self.bs.pvs[GET_SCREENS]))
    def get_iocs(self):
        """ Get a list of IOCs from DatabaseServer.

        Returns:
            list : A list of IOC names
        """
        try:
            rawjson = dehex_and_decompress(ChannelAccess.caget(self._blockserver_prefix + "IOCS"))
            return json.loads(rawjson).keys()
        except:
            return list()
    def write(self, reason, value):
        """A method called by SimpleServer when a PV is written to the DatabaseServer over Channel Access.

        Args:
            reason (string): The PV that is being requested (without the PV prefix)
            value (string): The data being written to the 'reason' PV

        Returns:
            bool : True
        """
        status = True
        try:
            if reason == 'ED:RBNUMBER:SP':
                #print_and_log("Updating to use experiment ID: " + value, "INFO", "DBSVR")
                self._ed.updateExperimentID(value)
            elif reason == 'ED:USERNAME:SP':
                self._ed.updateUsername(dehex_and_decompress(value))
        except Exception as err:
            value = compress_and_hex(convert_to_json("Error: " + str(err)))
            print_and_log(str(err), "MAJOR")
        # store the values
        if status:
            self.setParam(reason, value)
        return status
 def _blocknames_callback(epics_args, user_args):
     names = json.loads(dehex_and_decompress(waveform_to_string(epics_args['pv_value'])))
     if self.block_names is None or names != self.block_names:
         self.block_names = names
         print "Updated"
 def decodepv(self, pv):
     return json.loads(dehex_and_decompress(self.ca.caget(pv)))
    def write(self, reason, value):
        """A method called by SimpleServer when a PV is written to the BlockServer over Channel Access. The write
            commands are queued as Channel Access is single-threaded.

            Note that the filewatcher is disabled as part of the write queue so any operations that intend to modify
            files should use the write queue.

        Args:
            reason (string): The PV that is being requested (without the PV prefix)
            value (string): The data being written to the 'reason' PV

        Returns:
            string : "OK" in compressed and hexed JSON if function succeeds. Otherwise returns the Exception in
            compressed and hexed JSON.
        """
        status = True
        try:
            data = dehex_and_decompress(value).strip('"')
            if reason == BlockserverPVNames.LOAD_CONFIG:
                with self.write_lock:
                    self.write_queue.append((self.load_config, (data,), "LOADING_CONFIG"))
            elif reason == BlockserverPVNames.SAVE_CONFIG:
                with self.write_lock:
                    self.write_queue.append((self.save_active_config, (data,), "SAVING_CONFIG"))
            elif reason == BlockserverPVNames.RELOAD_CURRENT_CONFIG:
                with self.write_lock:
                    self.write_queue.append((self.reload_current_config, (), "RELOAD_CURRENT_CONFIG"))
            elif reason == BlockserverPVNames.START_IOCS:
                with self.write_lock:
                    self.write_queue.append((self.start_iocs, (convert_from_json(data),), "START_IOCS"))
            elif reason == BlockserverPVNames.STOP_IOCS:
                with self.write_lock:
                    self.write_queue.append((self._ioc_control.stop_iocs, (convert_from_json(data),), "STOP_IOCS"))
            elif reason == BlockserverPVNames.RESTART_IOCS:
                with self.write_lock:
                    self.write_queue.append((self._ioc_control.restart_iocs, (convert_from_json(data), True),
                                             "RESTART_IOCS"))
            elif reason == BlockserverPVNames.SET_CURR_CONFIG_DETAILS:
                with self.write_lock:
                    self.write_queue.append((self._set_curr_config, (convert_from_json(data),), "SETTING_CONFIG"))
            elif reason == BlockserverPVNames.SAVE_NEW_CONFIG:
                with self.write_lock:
                    self.write_queue.append((self.save_inactive_config, (data,), "SAVING_NEW_CONFIG"))
            elif reason == BlockserverPVNames.SAVE_NEW_COMPONENT:
                with self.write_lock:
                    self.write_queue.append((self.save_inactive_config, (data, True), "SAVING_NEW_COMP"))
            elif reason == BlockserverPVNames.DELETE_CONFIGS:
                with self.write_lock:
                    self.write_queue.append((self._config_list.delete, (convert_from_json(data),),
                                             "DELETE_CONFIGS"))
            elif reason == BlockserverPVNames.DELETE_COMPONENTS:
                with self.write_lock:
                    self.write_queue.append((self._config_list.delete, (convert_from_json(data), True),
                                             "DELETE_COMPONENTS"))
            elif reason == BlockserverPVNames.BUMPSTRIP_AVAILABLE_SP:
                self.bumpstrip = data
                with self.write_lock:
                    self.write_queue.append((self.update_bumpstrip_availability, None, "UPDATE_BUMPSTRIP"))
            else:
                status = False
                # Check to see if it is a on-the-fly PV
                for h in self.on_the_fly_handlers:
                    if h.write_pv_exists(reason):
                        with self.write_lock:
                            self.write_queue.append((h.handle_pv_write, (reason, data), "SETTING_CONFIG"))
                        status = True
                        break

        except Exception as err:
            value = compress_and_hex(convert_to_json("Error: " + str(err)))
            print_and_log(str(err), "MAJOR")
        else:
            if status:
                value = compress_and_hex(convert_to_json("OK"))

        # store the values
        if status:
            self.setParam(reason, value)
        return status
 def get_block_rules_json(self):
     return json.loads(dehex_and_decompress(self.bs.pvs[BlockserverPVNames.GROUP_RULES]))
def put_and_decode_ans(pv, value):
    caput(pv, compress_and_hex(value), wait=True)
    raw = caget(pv, True)
    js = dehex_and_decompress(raw)
    ans = json.loads(js)
    return ans
def get_and_decode(pv):
    raw = caget(pv, True)
    js = dehex_and_decompress(raw)
    ans = json.loads(js)
    return ans