def __loadXMLFiles(self, xmlLocation): with open(xmlLocation, 'r') as xmlFile: xml = xmlFile.read() if xml == '': raise EmptyLogFile('%s is empty' % xmlLocation) obj = make_instance(xml) del xml # Release memory return obj
def __loadFromCache(self, xml, xsd): hashPath = self.__getXmlHashFile(xml) xmlHash = self.__hashFile(xml) xsdHash = self.__hashFile(xsd) if not os.path.exists(hashPath): return (False, xmlHash, xsdHash) with open(hashPath, 'r') as hashFile: cachedXMLHash = hashFile.readline().strip() cachedXSDHash = hashFile.readline().strip() if cachedXMLHash != xmlHash or cachedXSDHash != xsdHash: return (False, xmlHash, xsdHash) self.configuration = make_instance(xml) return (True, xmlHash, xsdHash)
def __loadAndValidate(self, xml, xsd, xmlHash, xsdHash): try: # Validate the config file pyxsval.parseAndValidate( inputFile=xml, xsdFile=xsd, **Objectify.KWARGS) except Exception: raise Exception(format_exc()) #gnosis.xml.objectify._XO_node = Node.Node #gnosis.xml.objectify._XO_interface = Interface.Interface self.configuration = make_instance(xml) hashPath = self.__getXmlHashFile(xml) try: with open(hashPath, 'w') as hashFile: hashFile.write("%s\n%s" % (xmlHash, xsdHash)) hashFile.close() except IOError, e: self.logger.error(e)
def __loadFromCache(self, xml, xsd): hashPath = self.__getXmlHashFile(xml) xmlHash = self.__hashFile(xml) xsdHash = self.__hashFile(xsd) if not os.path.exists(hashPath): self.logger.debug("Hash doesn't exist: %s" % hashPath) return (False, xmlHash, xsdHash) hashFile = open(hashPath, 'r') cachedXMLHash = hashFile.readline().strip() cachedXSDHash = hashFile.readline().strip() hashFile.close() if cachedXMLHash != xmlHash or cachedXSDHash != xsdHash: self.logger.info("Incorrect Hashes: %s - %s, %s - %s" % (cachedXMLHash, xmlHash, cachedXSDHash, xsdHash)) return (False, xmlHash, xsdHash) self.configuration = make_instance(xml) return (True, xmlHash, xsdHash)