Skip to content

Commit

Permalink
Merge branch SantiagoTorres:fix-write-example
Browse files Browse the repository at this point in the history
spdx#133

Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Jun 11, 2021
2 parents 2c8fcd2 + b80690f commit b2c8c57
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/write_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

doc = Document()
doc.version = Version(1, 2)
doc.name = "Hello SPDX"
doc.spdx_id = "Test#SPDXRef-DOCUMENT"
doc.comment = "Example Document"
doc.namespace = "spdx"
doc.data_license = License.from_identifier("CC0-1.0")
doc.creation_info.add_creator(Person("Alice", "[email protected]"))
doc.creation_info.set_created_now()
Expand All @@ -32,6 +35,7 @@
# File
testfile1 = File("TestFile1")
testfile1.type = FileType.BINARY
testfile1.spdx_id = "TestFilet#SPDXRef-FILE"
testfile1.comment = "This is a test file."
testfile1.chk_sum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
testfile1.conc_lics = License.from_identifier("BSD-2-Clause")
Expand All @@ -43,6 +47,7 @@

testfile2 = File("TestFile2")
testfile2.type = FileType.SOURCE
testfile2.spdx_id = "TestFile2#SPDXRef-FILE"
testfile2.comment = "This is a test file."
testfile2.chk_sum = Algorithm("SHA1", "bb154f28d1cf0646ae21bb0bec6c669a2b90e113")
testfile2.conc_lics = License.from_identifier("Apache-2.0")
Expand All @@ -54,7 +59,9 @@
package.name = "TagWriteTest"
package.version = "1.0"
package.file_name = "twt.jar"
package.spdx_id = 'TestPackage#SPDXRef-PACKAGE'
package.download_location = "http://www.tagwritetest.test/download"
package.check_sum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
package.homepage = SPDXNone()
package.verif_code = "4e3211c67a2d28fced849ee1bb76e7391b93feba"
license_set = LicenseConjunction(
Expand Down Expand Up @@ -82,8 +89,9 @@
with codecs.open(file, mode="w", encoding="utf-8") as out:
try:
write_document(doc, out)
except InvalidDocumentError:
print("Document is Invalid")
except InvalidDocumentError as e:
print("Document is Invalid:\n\t", end="")
print("\n\t".join(e.args[0]))
messages = []
doc.validate(messages)
print("\n".join(messages))

0 comments on commit b2c8c57

Please sign in to comment.