Skip to content

Commit

Permalink
Updates README files and example files.
Browse files Browse the repository at this point in the history
Adds new example file rdf_to_tv.py.

Signed-off-by: Ahmed H. Ismail <[email protected]>
  • Loading branch information
a-h-i committed Aug 3, 2014
1 parent d4b827b commit dc17960
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ Expected Features:

Current Status:
===============
* RDF Parser unimplemented.
* RDF Parser implemented.
* Tag/value parser implemented
* Tag/value writer implemented.
* RDF/Writer incomplete.


How to use:
===========

Expand All @@ -46,6 +49,12 @@ Run 'python write_tv_ex.py sample.tag' to test it.
The file 'pp_tv.py' demonstrates how to parse a tag/value file and print it out.
To test it run 'python pp_tv.py Examples/SPDXTagExample.tag pretty.tag'.

The file 'parse_rdf.py' demonstrates how to parse a RDF/xml file and print out
document information.
To test it run 'python parse_rdf.py Examples/SPDXRdfExample.rdf'

The file 'rdf_to_tv.py' demonstrates how to convert a RDF file to a tag/value one.
To test it run 'python rdf_to_tv.py Examples/SPDXRdfExample.rdf converted.tag'

Installation:
=============
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Expected Features:

Current Status:
===============
* RDF Parser unimplemented.
* RDF Parser implemented.
* Tag/value parser implemented
* Tag/value writer implemented.
* RDF/Writer incomplete.


Expand Down Expand Up @@ -46,6 +48,12 @@ Run `python write_tv_ex.py sample.tag` to test it.
The file `pp_tv.py` demonstrates how to parse a tag/value file and print it out.
To test it run `python pp_tv.py Examples/SPDXTagExample.tag pretty.tag`.

The file `parse_rdf.py` demonstrates how to parse a RDF/xml file and print out
document information.
To test it run `python parse_rdf.py Examples/SPDXRdfExample.rdf`

The file `rdf_to_tv.py` demonstrates how to convert a RDF file to a tag/value one.
To test it run `python rdf_to_tv.py Examples/SPDXRdfExample.rdf converted.tag`

Installation:
=============
Expand Down
23 changes: 23 additions & 0 deletions parse_rdf.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python
if __name__ == '__main__':
import sys
import spdx.file as spdxfile
from spdx.parsers.rdf import Parser
from spdx.parsers.loggers import StandardLogger
from spdx.parsers.rdfbuilders import Builder
Expand All @@ -12,6 +14,11 @@
print 'Creators:'
for c in doc.creation_info.creators:
print '\t{0}'.format(c)
print 'Document review information:'
for review in doc.reviews:
print '\tReviewer: {0}'.format(review.reviewer)
print '\tDate: {0}'.format(review.review_date)
print '\tComment: {0}'.format(review.comment)
print 'Creation comment: {0}'.format(doc.creation_info.comment)
print 'Package Name: {0}'.format(doc.package.name)
print 'Package Version: {0}'.format(doc.package.version)
Expand All @@ -28,6 +35,22 @@
print 'Package Copyright text: {0}'.format(doc.package.cr_text)
print 'Package summary: {0}'.format(doc.package.summary)
print 'Package description: {0}'.format(doc.package.description)
print 'Package Files:'
VALUES = {
spdxfile.FileType.SOURCE: 'SOURCE',
spdxfile.FileType.OTHER: 'OTHER',
spdxfile.FileType.BINARY: 'BINARY',
spdxfile.FileType.ARCHIVE: 'ARCHIVE'
}
for f in doc.files:
print '\tFile name: {0}'.format(f.name)
print '\tFile type: {0}'.format(VALUES[f.type])
print '\tFile Checksum: {0}'.format(f.chk_sum.value)
print '\tFile license concluded: {0}'.format(f.conc_lics)
print '\tFile license info in file: {0}'.format(','.join(
map(lambda l: l.identifier, f.licenses_in_file)))
print '\tFile artifact of project name: {0}'.format(','.join(f.artifact_of_project_name))

print 'Document Extracted licenses:'
for lics in doc.extracted_licenses:
print '\tIdentifier: {0}'.format(lics.identifier)
Expand Down
1 change: 1 addition & 0 deletions parse_tv_ex.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
if __name__ == '__main__':
import sys
from spdx.parsers.tagvalue import Parser
Expand Down
4 changes: 3 additions & 1 deletion pp_tv.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
# Parses a tag/value file
# and prints it out formatted.
# usage pp_tv <inputfile> <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
Expand All @@ -17,7 +19,7 @@
document, error = p.parse(data)
if not error:
print 'Parsing Successful'
with open(target, 'w') as out:
with codecs.open(target, mode='w', encoding='utf-8') as out:
try:
write_document(document, out)
except InvalidDocumentError:
Expand Down
29 changes: 29 additions & 0 deletions rdf_to_tv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
4 changes: 3 additions & 1 deletion write_tv_ex.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python
if __name__ == '__main__':
import sys
import codecs
from spdx.writers.tagvalue import write_document, InvalidDocumentError
from spdx.document import Document, License, LicenseConjuction, ExtractedLicense
from spdx.version import Version
Expand Down Expand Up @@ -70,7 +72,7 @@
doc.add_extr_lic(lic)

file = sys.argv[1]
with open(file, 'w') as out:
with codecs.open(file, mode='w', encoding='utf-8') as out:
try:
write_document(doc, out)
except InvalidDocumentError:
Expand Down

0 comments on commit dc17960

Please sign in to comment.