forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch SantiagoTorres:fix-write-example
spdx#133 Signed-off-by: Philippe Ombredanne <[email protected]>
- Loading branch information
Showing
1 changed file
with
10 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
@@ -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") | ||
|
@@ -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") | ||
|
@@ -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( | ||
|
@@ -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)) |