コード例 #1
0
 def __parse_rdf(self, data):
     from spdx.parsers.rdf import Parser
     from spdx.parsers.rdfbuilders import Builder
     from spdx.parsers.loggers import StandardLogger
     p = Parser(Builder(), StandardLogger())
     document, error = p.parse(data)
     if error:
         return (None, error)
     else:
         return (document, None)
コード例 #2
0
 def __parse_tagvalue(self, data):
     from spdx.parsers.tagvalue import Parser
     from spdx.parsers.tagvaluebuilders import Builder
     from spdx.parsers.loggers import StandardLogger
     p = Parser(Builder(), StandardLogger())
     p.build()
     document, error = p.parse(data)
     if error:
         return (None, error)
     else:
         return (document, None)
コード例 #3
0
ファイル: tv_to_rdf.py プロジェクト: omi10859/tools-python
def convert(infile_name, outfile_name):
    tagvalueparser = Parser(Builder(), StandardLogger())
    tagvalueparser.build()
    with open(infile_name) as infile:
        data = infile.read()
        document, error = tagvalueparser.parse(data)
        if not error:
            # print map(lambda c: c.name, document.creation_info.creators)
            print 'Parsing Successful'
            with open(outfile_name, mode='w') as out:
                write_document(document, out, validate=True)
        else:
            print 'Errors encountered while parsing tag value file.'
            messages = []
            document.validate(messages)
            print '\n'.join(messages)
コード例 #4
0
def TAG_to_RDF(infile_name, outfile_name):
    tagvalueparser = Parser(Builder(), StandardLogger())
    tagvalueparser.build()
    with open(infile_name) as infile:
        data = infile.read()
        document, error = tagvalueparser.parse(data)
        if not error:
            # print(map(lambda c: c.name, document.creation_info.creators))
            print("Parsing Successful")
            with open(outfile_name, mode="w") as out:
                write_document(document, out, validate=True)
        else:
            print("Errors encountered while parsing tag value file.")
            messages = []
            document.validate(messages)
            print("\n".join(messages))
コード例 #5
0
def TAG_to_YAML(infile_name, outfile_name):
    # if __name__ == "__main__":
    # import sys
    from spdx.parsers.tagvalue import Parser
    from spdx.parsers.loggers import StandardLogger
    from spdx.parsers.tagvaluebuilders import Builder
    from spdx.writers.yaml import write_document

    # file = sys.argv[1]
    p = Parser(Builder(), StandardLogger())
    p.build()
    with open(infile_name) as f:
        data = f.read()
        document, error = p.parse(data)
        if not error:
            with open(outfile_name, "w") as out:
                write_document(document, out)
        else:
            print("Errors encountered while parsing")
コード例 #6
0
ファイル: tv_to_rdf.py プロジェクト: 0t1s1/tools-python
def tv_to_rdf(infile_name, outfile_name):
    """
    Convert a SPDX file from tag/value format to RDF format.
    Return True on sucess, False otherwise.
    """
    parser = Parser(Builder(), StandardLogger())
    parser.build()
    with open(infile_name) as infile:
        data = infile.read()
        document, error = parser.parse(data)
        if not error:
            with open(outfile_name, mode="w") as outfile:
                write_document(document, outfile)
            return True
        else:
            print("Errors encountered while parsing RDF file.")
            messages = ErrorMessages()
            document.validate(messages)
            print("\n".join(messages.messages))
            return False
コード例 #7
0
def parse_TAG(file):
    from spdx.parsers.tagvalue import Parser
    from spdx.parsers.loggers import StandardLogger
    from spdx.parsers.tagvaluebuilders import Builder

    p = Parser(Builder(), StandardLogger())
    p.build()
    with open(file) as f:
        data = f.read()
        document, error = p.parse(data)
        if not error:
            print("Parsing Successful")
            print(
                "Document Version {0}.{1}".format(
                    document.version.major, document.version.minor
                )
            )
            print("Package name : {0}".format(document.package.name))
            print("Creators : ")
            for creator in document.creation_info.creators:
                print(creator.name)
        else:
            print("Errors encountered while parsing")
コード例 #8
0
#!/usr/bin/env python

# Parses a tag/value file and writes it out pretty-printed.
# Usage: pp_tv <infile> <outfile>

if __name__ == '__main__':
    import sys
    import codecs
    from spdx.writers.tagvalue import write_document, InvalidDocumentError
    from spdx.parsers.tagvalue import Parser
    from spdx.parsers.loggers import StandardLogger
    from spdx.parsers.tagvaluebuilders import Builder
    source = sys.argv[1]
    target = sys.argv[2]
    p = Parser(Builder(), StandardLogger())
    p.build()
    with open(source, 'r') as f:
        data = f.read()
        document, error = p.parse(data)
        if not error:
            print 'Parsing Successful'
            with codecs.open(target, mode='w', encoding='utf-8') as out:
                try:
                    write_document(document, out)
                except InvalidDocumentError:
                    print 'Document is Invalid'
                    messages = []
                    document.validate(messages)
                    print '\n'.join(messages)
        else:
            print 'Errors encountered while parsing'
コード例 #9
0
 def setUp(self):
     self.p = Parser(Builder(), StandardLogger())
     self.p.build()