Skip to content
Snippets Groups Projects
Select Git revision
  • d6fafdfec0551c3ea5bb56b9c284f56f377c2b7e
  • master default protected
  • MAM-56-prepare-update-for-sip-version-3
  • TMSS-1777
  • SDC-545_update_SIP
  • lofar_repo
  • 2.7.1
  • 2.8.0
8 results

validator.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    validator.py 980 B
    
    from lxml import etree
    import os
    
    d = os.path.dirname(os.path.realpath(__file__))
    
    def validate(xmlpath, xsdpath):
        '''validates given xml file against given xsd file'''
        with open(xsdpath) as xsd:
            xmlschema_doc = etree.parse(xsd)
            xmlschema = etree.XMLSchema(xmlschema_doc)
    
            with open(xmlpath) as xml:
                doc = etree.parse(xml)
                valid = xmlschema.validate(doc)
    
                if not valid:
                    try:
                        xmlschema.assertValid(doc)
                    except Exception as err:
                        print err
    
                return valid
    
    #expose a main method in this lib module which can be used by external programs
    #or by the bin/validatesip 'program'
    def main(xml):
        #do the proper calls to the SIP API
        # parse cmdline args etc
        try:
            xml = xml
            xsd = d+"/LTA-SIP.xsd"
            return validate(xml, xsd)
        except Exception as err:
            print "An error occurred:"
            print err