コード例 #1
0
ファイル: gen_messages.py プロジェクト: bartslinger/pprzlink
def gen_messages(opts) :
    """Generate pprzlink message formatters and parsers using options.
    This function allows python scripts under Windows to control generators
    using the same interface as shell scripts under Unix"""

    fname = opts.definition

    # Enable validation by default, disabling it if explicitly requested
    if opts.validate:
        try:
            from lib.genxmlif import GenXmlIfError
            from lib.minixsv import pyxsval
        except:
            print("WARNING: Unable to load XML validator libraries. XML validation will not be performed")
            opts.validate = False

    def pprz_validate(fname, schema, errorLimitNumber) :
        """Uses minixsv to validate an XML file with a given XSD schema file. We define pprz_validate
           here because it relies on the XML libs that were loaded in gen_messages(), so it can't be called standalone"""
        # use default values of minixsv, location of the schema file must be specified in the XML file
        try:
            domTreeWrapper = pyxsval.parseAndValidate(fname, xsdFile=schema, errorLimit=errorLimitNumber)
        except pyxsval.XsvalError as errstr:
            print(errstr)
            return 1
        except GenXmlIfError as errstr:
            print(errstr)
            return 1
        return 0

    # Process XML file, validating as necessary.
    validation_result = 0
    if opts.validate:
        print("Validating msg_class %s in %s" % (opts.class_name, fname))
        validation_result = pprz_validate(fname, schemaFile, opts.error_limit)
    else:
        print("Validation skipped for msg_class %s in %s." % (opts.class_name, fname))

    print("Parsing %s" % fname)
    xml = pprz_parse.PPRZXML(fname, opts.class_name, opts.protocol)

    if pprz_parse.check_duplicates(xml):
        sys.exit(1)

    print("Found %u PPRZLink messages of msg_class %s in XML file %s" % (
        pprz_parse.total_msgs(xml), opts.class_name, fname))

    if opts.only_validate:
        sys.exit(validation_result)

    # Convert language option to lowercase and validate
    opts.language = opts.language.lower()
    if opts.language == 'c':
        import gen_messages_c
        gen_messages_c.generate(opts.output, xml)
    else:
        print("Unsupported language %s" % opts.language)
コード例 #2
0
ファイル: gen_messages.py プロジェクト: yannickj/pprzlink
def gen_messages(opts):
    """Generate pprzlink message formatters and parsers using options.
    This function allows python scripts under Windows to control generators
    using the same interface as shell scripts under Unix"""

    fname = opts.definition

    # Enable validation by default, disabling it if explicitly requested
    if opts.validate:
        try:
            from lxml import etree
        except:
            print(
                "WARNING: Unable to load XML validator libraries. XML validation will not be performed"
            )
            opts.validate = False

    def pprz_validate(fname, schema):
        """Uses minixsv to validate an XML file with a given XSD schema file. We define pprz_validate
           here because it relies on the XML libs that were loaded in gen_messages(), so it can't be called standalone"""
        try:
            xmlschema_doc = etree.parse(schema)
            xmlschema = etree.XMLSchema(xmlschema_doc)
            f_doc = etree.parse(fname)
            xmlschema.assertValid(f_doc)
        except Exception as errstr:
            print(errstr)
            return 1
        return 0

    # Process XML file, validating as necessary.
    validation_result = 0
    if opts.validate:
        import os.path
        directory = os.path.dirname(fname)
        schemaFile = os.path.join(directory, schemaFileName)
        if not os.path.isfile(schemaFile):
            print("Schema file %s does not exist. Trying default path." %
                  (schemaFile))
            schemaFile = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), schemaFileName)
            if not os.path.isfile(schemaFile):
                print("Schema default file %s does not exist. Leaving." %
                      (schemaFile))
                sys.exit(1)
        print("Validating msg_class %s in %s with %s" %
              (opts.class_name, fname, schemaFile))

        validation_result = pprz_validate(fname, schemaFile)
    else:
        print("Validation skipped for msg_class %s in %s." %
              (opts.class_name, fname))

    print("Parsing %s" % fname)
    xml = pprz_parse.PPRZXML(fname, opts.class_name, opts.protocol)

    if pprz_parse.check_duplicates(xml):
        sys.exit(1)

    print("Found %u PPRZLink messages of msg_class %s in XML file %s" %
          (pprz_parse.total_msgs(xml), opts.class_name, fname))

    if opts.only_validate:
        sys.exit(validation_result)

    # Convert language option to lowercase and validate
    opts.language = opts.language.lower()
    if opts.language == 'c':
        gen_message_c = __import__(xml.generator_module + "_c")
        gen_message_c.generate(opts.output, xml)
    elif opts.language == 'c_standalone':
        gen_message_c_standalone = __import__(xml.generator_module +
                                              "_c_standalone")
        gen_message_c_standalone.generate(opts.output, xml, opts.opt)
    else:
        print("Unsupported language %s" % opts.language)
コード例 #3
0
            print(errstr)
            return 1
        return 0

    # Process XML file, validating as necessary.
    validation_result = 0
    if opts.validate:
        print("Validating %s" % fname)
        validation_result = pprz_validate(fname, schemaFile, opts.error_limit)
    else:
        print("Validation skipped for %s." % fname)

    print("Parsing %s" % fname)
    xml = pprz_parse.PPRZXML(fname, opts.class_name, opts.protocol)

    if pprz_parse.check_duplicates(xml):
        sys.exit(1)

    print("Found %u PPRZLink message types in XML file %s" %
          (pprz_parse.total_msgs(xml), fname))

    if opts.only_validate:
        sys.exit(validation_result)

    # Convert language option to lowercase and validate
    opts.language = opts.language.lower()
    if opts.language == 'c':
        import gen_messages_c
        gen_messages_c.generate(opts.output, xml)
    else:
        print("Unsupported language %s" % opts.language)
コード例 #4
0
def gen_messages(opts):
    """Generate pprzlink message formatters and parsers using options.
    This function allows python scripts under Windows to control generators
    using the same interface as shell scripts under Unix"""

    fname = opts.definition

    # Enable validation by default, disabling it if explicitly requested
    if opts.validate:
        try:
            from lib.genxmlif import GenXmlIfError
            from lib.minixsv import pyxsval
        except:
            print(
                "WARNING: Unable to load XML validator libraries. XML validation will not be performed"
            )
            opts.validate = False

    def pprz_validate(fname, schema, errorLimitNumber):
        """Uses minixsv to validate an XML file with a given XSD schema file. We define pprz_validate
           here because it relies on the XML libs that were loaded in gen_messages(), so it can't be called standalone"""
        # use default values of minixsv, location of the schema file must be specified in the XML file
        try:
            domTreeWrapper = pyxsval.parseAndValidate(
                fname, xsdFile=schema, errorLimit=errorLimitNumber)
        except pyxsval.XsvalError as errstr:
            print(errstr)
            return 1
        except GenXmlIfError as errstr:
            print(errstr)
            return 1
        return 0

    # Process XML file, validating as necessary.
    validation_result = 0
    if opts.validate:
        print("Validating msg_class %s in %s" % (opts.class_name, fname))
        validation_result = pprz_validate(fname, schemaFile, opts.error_limit)
    else:
        print("Validation skipped for msg_class %s in %s." %
              (opts.class_name, fname))

    print("Parsing %s" % fname)
    xml = pprz_parse.PPRZXML(fname, opts.class_name, opts.protocol)

    if pprz_parse.check_duplicates(xml):
        sys.exit(1)

    print("Found %u PPRZLink messages of msg_class %s in XML file %s" %
          (pprz_parse.total_msgs(xml), opts.class_name, fname))

    if opts.only_validate:
        sys.exit(validation_result)

    # Convert language option to lowercase and validate
    opts.language = opts.language.lower()
    if opts.language == 'c':
        import gen_messages_c
        gen_messages_c.generate(opts.output, xml)
    else:
        print("Unsupported language %s" % opts.language)
コード例 #5
0
ファイル: gen_messages.py プロジェクト: EwoudSmeur/pprzlink
            print(errstr)
            return 1
        return 0

    # Process XML file, validating as necessary.
    validation_result = 0
    if opts.validate:
        print("Validating msg_class %s in %s" % (opts.class_name, fname))
        validation_result = pprz_validate(fname, schemaFile, opts.error_limit)
    else:
        print("Validation skipped for msg_class %s in %s." % (opts.class_name, fname))

    print("Parsing %s" % fname)
    xml = pprz_parse.PPRZXML(fname, opts.class_name, opts.protocol)

    if pprz_parse.check_duplicates(xml):
        sys.exit(1)

    print("Found %u PPRZLink messages of msg_class %s in XML file %s" % (
        pprz_parse.total_msgs(xml), opts.class_name, fname))

    if opts.only_validate:
        sys.exit(validation_result)

    # Convert language option to lowercase and validate
    opts.language = opts.language.lower()
    if opts.language == 'c':
        import gen_messages_c
        gen_messages_c.generate(opts.output, xml)
    else:
        print("Unsupported language %s" % opts.language)