minixsvWrapper.py
Go to the documentation of this file.
00001 #!/usr/local/bin/python
00002 
00003 import sys
00004 import getopt
00005 from ..genxmlif          import GenXmlIfError
00006 from xsvalErrorHandler import ErrorHandler, XsvalError
00007 from ..minixsv           import *
00008 from pyxsval           import parseAndValidate
00009 
00010 
00011 ##########################################
00012 # minixsv Wrapper for calling minixsv from command line
00013 
00014 validSyntaxText = '''\
00015 minixsv XML Schema Validator
00016 Syntax: minixsv [-h] [-?] [-p Parser] [-s XSD-Filename] XML-Filename
00017 
00018 Options:
00019 -h, -?:          Display this help text
00020 -p Parser:       XML Parser to be used 
00021                  (XMLIF_MINIDOM, XMLIF_ELEMENTTREE, XMLIF_4DOM
00022                   default: XMLIF_ELEMENTTREE)
00023 -s XSD-FileName: specify the schema file for validation 
00024                  (if not specified in XML-File)
00025 '''
00026 
00027 def checkShellInputParameter():
00028     """check shell input parameters."""
00029     xmlInputFilename = None
00030     xsdFilename = None
00031     xmlParser = "XMLIF_ELEMENTTREE"
00032     try:
00033         (options, arguments) = getopt.getopt(sys.argv[1:], '?hp:s:')
00034 
00035         if ('-?','') in options or ('-h','') in options:
00036             print validSyntaxText
00037             sys.exit(-1)
00038         else:
00039             if len (arguments) == 1:
00040                 xmlInputFilename = arguments[0]
00041                 for o, a in options:
00042                     if o == "-s":
00043                         xsdFilename = a
00044                     if o == "-p":
00045                         if a in (XMLIF_MINIDOM, XMLIF_ELEMENTTREE, XMLIF_4DOM):
00046                             xmlParser = a    
00047                         else:
00048                             print 'Invalid XML parser %s!' %(a)
00049                             sys.exit(-1)
00050             else:
00051                 print 'minixsv needs one argument (XML input file)!'
00052                 sys.exit(-1)
00053 
00054     except getopt.GetoptError, errstr:
00055         print errstr
00056         sys.exit(-1)
00057     return xmlInputFilename, xsdFilename, xmlParser
00058 
00059 
00060 def main():
00061     xmlInputFilename, xsdFileName, xmlParser = checkShellInputParameter()
00062     try:
00063         parseAndValidate (xmlInputFilename, xsdFile=xsdFileName, xmlIfClass=xmlParser)
00064     except IOError, errstr:
00065         print errstr
00066         sys.exit(-1)
00067     except GenXmlIfError, errstr:
00068         print errstr
00069         sys.exit(-1)
00070     except XsvalError, errstr:
00071         print errstr
00072         sys.exit(-1)
00073     
00074 if __name__ == "__main__":
00075     main()
00076     


mavlink
Author(s): Lorenz Meier
autogenerated on Sun May 22 2016 04:05:43