temporary checkin... switching gears to another project for a bit

This commit is contained in:
brent s 2017-03-06 11:35:17 -05:00
parent 608a50ce8f
commit fbf92367d5
3 changed files with 76 additions and 3 deletions

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<aif xmlns="https://aif.square-r00t.net/aif.xsd">
<aif xmlns="http://aif.square-r00t.net/aif.xsd">
<storage>
<disk name="sda" type="gpt">
<part num="1" size="10%" fstype="ef00" />
<part num="2" size="90%" fstype="8300" />
</disk>
<mount source="/dev/sda1" mountpt="/mnt" />
<mount source="/dev/sda1" mountpt="/mnt/boot" order="2" />
<mount source="/dev/sda2" mountpt="/mnt" order="1" />
</storage>
<network hostname="aiftest.square-r00t.net">
<iface name="auto" addressing="dhcp" />
@ -72,7 +73,8 @@
<package name="sed" repo="core" />
</software>
</pacman>
<bootloader>
<bootloader efi="true">
<type>GRUB</type>
<where>/boot</where>
</bootloader>
</aif>

View File

@ -14,6 +14,7 @@
</xs:element>
</xs:element>
<xs:element name="mount"><!-- mountpoint -->
<xs:element name="order" /><!-- optional. the "weight" to give this mount point. -->
<xs:element name="source" /><!-- the device to mount, e.g. /dev/sda1 -->
<xs:element name="mountpt" /><!-- where to mount, e.g. /boot -->
<xs:element name="type" /><!-- the filesystem type. optional; should normally be auto-detected. -->
@ -126,10 +127,18 @@
<!-- BEGIN BOOTLOADER -->
<xs:element name="bootloader">
<xs:element name="type" /><!-- the type of bootloader. one of "grub", "lilo", "syslinux"... -->
<xs:element name="efi" /><!-- boolean. UEFI support. if false, strictly MBR. -->
<xs:element name="where" /><!-- if efi is true, the mountpoint for the ESP (from within the chroot). if false, the device (or partition) to install the bootloader on. -->
</xs:element>
<!-- END BOOTLOADER -->

<!-- BEGIN CUSTOM SCRIPT -->
<xs:element name="scripts">
<xs:element name="script">
<xs:element name="uri" /><!-- a URI where to find the file. http://, https://, ftp://, file://, etc. -->
<xs:element name="lang" /><!-- optional. the language of the script. "bash", "python3", "python2", "awk" (if you're insane), etc. -->
</xs:element>
</xs:element>
<!-- END CUSTOM SCRIPT -->
</xs:element>
</xs:schema>

62
aifverify.py Executable file
View File

@ -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)