From fbf92367d5543e7aef221732781b546291fae0e0 Mon Sep 17 00:00:00 2001 From: brent s Date: Mon, 6 Mar 2017 11:35:17 -0500 Subject: [PATCH] temporary checkin... switching gears to another project for a bit --- aif.xml | 8 ++++--- aif.xsd | 9 ++++++++ aifverify.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100755 aifverify.py diff --git a/aif.xml b/aif.xml index 692c68f..35a48b2 100644 --- a/aif.xml +++ b/aif.xml @@ -1,11 +1,12 @@ - + - + + @@ -72,7 +73,8 @@ - + GRUB + /boot \ No newline at end of file diff --git a/aif.xsd b/aif.xsd index 64f4e14..00d8732 100644 --- a/aif.xsd +++ b/aif.xsd @@ -14,6 +14,7 @@ + @@ -126,10 +127,18 @@ + + + + + + + + \ No newline at end of file diff --git a/aifverify.py b/aifverify.py new file mode 100755 index 0000000..74b7996 --- /dev/null +++ b/aifverify.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + + +import re +import os +import io +from lxml import etree +from urllib.request import urlopen + +cwd = os.path.dirname(os.path.realpath(__file__)) + +# Validate in the form of file:XSD/namespace. +xmlfiles = {} +#xmlfiles['aif.xml'] = 'https://aif.square-r00t.net/aif.xsd' +xmlfiles['aif.xml'] = 'aif.xsd' + +def validXSD(xsdfile): + print("Checking XSD: ", xsdfile) + webres = False + if re.match('^(https?|ftp)', xsdfile, re.IGNORECASE): + webres = True + if not webres: + with open('{0}/{1}'.format(cwd, xsdfile), 'rb') as f: + xsd_in = f.read() + else: + with urlopen(xsdfile) as f: + xsd_in = f.read() + xsd = False + try: + xsd_in = io.BytesIO(xsd_in) + xmlschema_doc = etree.parse(xsd_in) + xsd = etree.XMLSchema(xmlschema_doc) + except: + print('XSD: {0} failed.'.format(xsdfile)) + return(xsd) + +def validXML(xml, xsd): + print("Checking XML: ", xml) + xmlfile = xml + with open('{0}/{1}'.format(cwd, xml), 'rb') as f: + xml_in = f.read() + valid = False + try: + xml_in = io.BytesIO(xml_in) + xml = etree.parse(xml_in) + valid = xsd.validate(xml) + except: + print('XML: {0} failed.'.format(xmlfile)) + return(valid) + +def allValidXML(xmlfiles): + for key,value in xmlfiles.items(): + xmlfile = key + xsdfile = xmlfiles[xmlfile] + xml = False + xsdobj = validXSD(xsdfile) + xml = validXML(xmlfile, xsdobj) + return(xml) + + +if __name__ == '__main__': + allValidXML(xmlfiles)