def _load_current(self): """ Gets the devices XML for the current instrument""" # Read the data from file try: self._data = self._file_io.load_devices_file(self.get_devices_filename()) except IOError as err: self._data = self.get_blank_devices() print_and_log("Unable to load devices file. %s. The PV data will default to a blank set of devices." % err, "MINOR") return try: # Check against the schema ConfigurationSchemaChecker.check_xml_data_matches_schema(os.path.join(self._schema_folder, SCREENS_SCHEMA), self._data) except ConfigurationInvalidUnderSchema as err: self._data = self.get_blank_devices() print_and_log(err.message) return try: self._add_to_version_control("New change found in devices file") except Exception as err: print_and_log("Unable to add new data to version control. " + str(err), "MINOR") self._vc.commit("Blockserver started, devices updated")
def save_devices_xml(self, xml_data): """ Saves the xml in the current "screens.xml" config file. Args: xml_data (string): The XML to be saved """ try: ConfigurationSchemaChecker.check_xml_data_matches_schema(os.path.join(self._schema_folder, SCREENS_SCHEMA), xml_data) except ConfigurationInvalidUnderSchema as err: print_and_log(err.message) return try: if not os.path.exists(FILEPATH_MANAGER.devices_dir): os.makedirs(FILEPATH_MANAGER.devices_dir) self._file_io.save_devices_file(self.get_devices_filename(), xml_data) except IOError as err: print_and_log("Unable to save devices file. %s. The PV data will not be updated." % err, "MINOR") return # Update PVs self.update(xml_data, "Device screens modified by client") print_and_log("Devices saved to " + self.get_devices_filename())
def test_valid_blocks_xml_matches_schema(self): self.cs.set_config_details(TEST_CONFIG) xml = ConfigurationXmlConverter.blocks_to_xml(self.cs.get_block_details(), MACROS) try: ConfigurationSchemaChecker.check_xml_data_matches_schema(os.path.join(self.schema_dir, "blocks.xsd"), xml) except: self.fail()
def test_valid_components_xml_matches_schema(self): conf = Configuration(MACROS) conf.components["COMP1"] = "COMP1" conf.components["COMP2"] = "COMP2" xml = ConfigurationXmlConverter.components_to_xml(conf.components) try: ConfigurationSchemaChecker.check_xml_data_matches_schema(os.path.join(self.schema_dir, "components.xsd"), xml) except: self.fail()
def _check_valid(self, path): """ Check the validity of the device screens file and return the xml data contained within if valid Args: path (string): The location of the file Returns: The device screens data as a string of xml """ extension = path[-4:] if extension != ".xml": raise NotConfigFileException("File not xml") xml_data = self._manager.load_devices(path) with self._schema_lock: ConfigurationSchemaChecker.check_xml_data_matches_schema(self._schema_filepath, xml_data) return xml_data
def _check_againgst_schema(self, xml, filename): regex = re.compile(re.escape(".xml"), re.IGNORECASE) name = regex.sub(".xsd", filename) schema_path = os.path.join(FILEPATH_MANAGER.schema_dir, name) ConfigurationSchemaChecker.check_xml_data_matches_schema(schema_path, xml)