-
Notifications
You must be signed in to change notification settings - Fork 1
/
rdf_to_tv.py
executable file
·29 lines (29 loc) · 1.19 KB
/
rdf_to_tv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# Converts an RDF file to tag/value format.
# usage rdf_to_tv <rdffile> <tagvaluefile>
if __name__ == '__main__':
import sys
import codecs
from spdx.parsers.rdf import Parser
from spdx.parsers.loggers import StandardLogger
from spdx.parsers.rdfbuilders import Builder
from spdx.writers.tagvalue import write_document, InvalidDocumentError
infile_name = sys.argv[1]
outfile_name = sys.argv[2]
rdfparser = Parser(Builder(), StandardLogger())
with open(infile_name) as infile:
document, error = rdfparser.parse(infile)
if not error:
# print map(lambda c: c.name, document.creation_info.creators)
print 'Parsing Successful'
with codecs.open(outfile_name, mode='w', encoding='utf-8') as outfile:
try:
write_document(document, outfile)
except InvalidDocumentError:
# Note document is valid if error is False
print 'Document is Invalid'
else:
print 'Errors encountered while parsing RDF file.'
messages = []
document.validate(messages)
print '\n'.join(messages)