Skip to content

Commit a3679d3

Browse files
committed
[issue-184] squashed review commits
- correct checksum in json example - add JSONExample2.2 from spec but exclude in tests since 2.2 is not yet completely supported - add files only once if they appear in multiple packages - parse only spdxid in documentDescribes, delete commented out code - delete unused XMLWriter and JsonYamlWriter class, updated xml test results - rework create_document_describes method - delete surrounding document in json/yaml test - rename licenseinfoinfiles method according to variable - rename chk_sum/ check_sum to chksum/checksum - delete duplicated relationships from json/yaml/xml Signed-off-by: Meret Behrens <[email protected]>
1 parent bf03cc6 commit a3679d3

28 files changed

+369
-474
lines changed

data/SPDXJsonExample.json

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"checksums": [
4343
{
4444
"checksumValue": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
45-
"algorithm": "checksumAlgorithm_sha1"
45+
"algorithm": "SHA1"
4646
}
4747
],
4848
"versionInfo": "Version 0.9.2",
@@ -71,7 +71,7 @@
7171
"checksums": [
7272
{
7373
"checksumValue": "3ab4e1c67a2d28fced849ee1bb76e7391b93f125",
74-
"algorithm": "checksumAlgorithm_sha1"
74+
"algorithm": "SHA1"
7575
}
7676
],
7777
"fileTypes": [
@@ -89,7 +89,7 @@
8989
"checksums": [
9090
{
9191
"checksumValue": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
92-
"algorithm": "checksumAlgorithm_sha1"
92+
"algorithm": "SHA1"
9393
}
9494
],
9595
"fileTypes": [
@@ -112,7 +112,7 @@
112112
{
113113
"checksum": {
114114
"checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2759",
115-
"algorithm": "checksumAlgorithm_sha1"
115+
"algorithm": "SHA1"
116116
},
117117
"spdxDocument": "https://spdx.org/spdxdocs/spdx-tools-v2.1-3F2504E0-4F89-41D3-9A0C-0305E82C3301",
118118
"externalDocumentId": "DocumentRef-spdx-tool-2.1"
@@ -128,23 +128,6 @@
128128
"annotator": "Person: Jim Reviewer"
129129
}
130130
],
131-
"relationships": [
132-
{
133-
"spdxElementId": "SPDXRef-DOCUMENT",
134-
"relatedSpdxElement": "SPDXRef-Package",
135-
"relationshipType": "CONTAINS"
136-
},
137-
{
138-
"spdxElementId": "SPDXRef-DOCUMENT",
139-
"relatedSpdxElement": "SPDXRef-File",
140-
"relationshipType": "DESCRIBES"
141-
},
142-
{
143-
"spdxElementId": "SPDXRef-DOCUMENT",
144-
"relatedSpdxElement": "SPDXRef-Package",
145-
"relationshipType": "DESCRIBES"
146-
}
147-
],
148131
"dataLicense": "CC0-1.0",
149132
"reviewers": [
150133
{
@@ -160,11 +143,11 @@
160143
],
161144
"hasExtractedLicensingInfos": [
162145
{
163-
"extractedText": "This package includes the GRDDL parser developed by Hewlett Packard under the following license:\n\u00a9 Copyright 2007 Hewlett-Packard Development Company, LP\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: \n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. \nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. \nThe name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. \nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
146+
"extractedText": "This package includes the GRDDL parser developed by Hewlett Packard under the following license:\n\u00a9 Copyright 2007 Hewlett-Packard Development Company, LP\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\nThe name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
164147
"licenseId": "LicenseRef-2"
165148
},
166149
{
167-
"extractedText": "The CyberNeko Software License, Version 1.0\n\n \n(C) Copyright 2002-2005, Andy Clark. All rights reserved.\n \nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n\n1. Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer. \n\n2. Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in\n the documentation and/or other materials provided with the\n distribution.\n\n3. The end-user documentation included with the redistribution,\n if any, must include the following acknowledgment: \n \"This product includes software developed by Andy Clark.\"\n Alternately, this acknowledgment may appear in the software itself,\n if and wherever such third-party acknowledgments normally appear.\n\n4. The names \"CyberNeko\" and \"NekoHTML\" must not be used to endorse\n or promote products derived from this software without prior \n written permission. For written permission, please contact \n [email protected].\n\n5. Products derived from this software may not be called \"CyberNeko\",\n nor may \"CyberNeko\" appear in their name, without prior written\n permission of the author.\n\nTHIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED\nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\nOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS\nBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, \nOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT \nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR \nBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
150+
"extractedText": "The CyberNeko Software License, Version 1.0\n\n\n(C) Copyright 2002-2005, Andy Clark. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n\n1. Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in\n the documentation and/or other materials provided with the\n distribution.\n\n3. The end-user documentation included with the redistribution,\n if any, must include the following acknowledgment:\n \"This product includes software developed by Andy Clark.\"\n Alternately, this acknowledgment may appear in the software itself,\n if and wherever such third-party acknowledgments normally appear.\n\n4. The names \"CyberNeko\" and \"NekoHTML\" must not be used to endorse\n or promote products derived from this software without prior\n written permission. For written permission, please contact\n [email protected].\n\n5. Products derived from this software may not be called \"CyberNeko\",\n nor may \"CyberNeko\" appear in their name, without prior written\n permission of the author.\n\nTHIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED\nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\nOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS\nBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\nOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\nBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
168151
"comment": "This is tye CyperNeko License",
169152
"licenseId": "LicenseRef-3",
170153
"name": "CyberNeko License",

data/SPDXXmlExample.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,4 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</extractedText>
237237
<SPDXID>SPDXRef-Snippet</SPDXID>
238238
<fileId>SPDXRef-DoapSource</fileId>
239239
</snippets>
240-
<relationships>
241-
<spdxElementId>SPDXRef-DOCUMENT</spdxElementId>
242-
<relatedSpdxElement>SPDXRef-File</relatedSpdxElement>
243-
<relationshipType>DESCRIBES</relationshipType>
244-
</relationships>
245-
<relationships>
246-
<spdxElementId>SPDXRef-DOCUMENT</spdxElementId>
247-
<relatedSpdxElement>SPDXRef-Package</relatedSpdxElement>
248-
<relationshipType>DESCRIBES</relationshipType>
249-
</relationships>
250-
<relationships>
251-
<spdxElementId>SPDXRef-DOCUMENT</spdxElementId>
252-
<relatedSpdxElement>SPDXRef-Package</relatedSpdxElement>
253-
<relationshipType>CONTAINS</relationshipType>
254-
</relationships>
255240
</Document>

data/SPDXYamlExample.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,6 @@ Document:
170170
SPDXID: SPDXRef-DOCUMENT
171171
name: Sample_Document-V2.1
172172
documentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301
173-
relationships:
174-
- spdxElementId: "SPDXRef-DOCUMENT"
175-
relatedSpdxElement: "SPDXRef-Package"
176-
relationshipType: "DESCRIBES"
177-
- spdxElementId: "SPDXRef-DOCUMENT"
178-
relatedSpdxElement: "SPDXRef-Package"
179-
relationshipType: "CONTAINS"
180-
- spdxElementId: "SPDXRef-DOCUMENT"
181-
relatedSpdxElement: "SPDXRef-File"
182-
relationshipType: "DESCRIBES"
183173
reviewers:
184174
- comment: Another example reviewer.
185175
reviewDate: '2011-03-13T00:00:00Z'

examples/write_tv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
testfile1.type = FileType.BINARY
3535
testfile1.spdx_id = "TestFilet#SPDXRef-FILE"
3636
testfile1.comment = "This is a test file."
37-
testfile1.chk_sum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
37+
testfile1.chksum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
3838
testfile1.conc_lics = License.from_identifier("BSD-2-Clause")
3939
testfile1.add_lics(License.from_identifier("BSD-2-Clause"))
4040
testfile1.copyright = SPDXNone()
@@ -46,7 +46,7 @@
4646
testfile2.type = FileType.SOURCE
4747
testfile2.spdx_id = "TestFile2#SPDXRef-FILE"
4848
testfile2.comment = "This is a test file."
49-
testfile2.chk_sum = Algorithm("SHA1", "bb154f28d1cf0646ae21bb0bec6c669a2b90e113")
49+
testfile2.chksum = Algorithm("SHA1", "bb154f28d1cf0646ae21bb0bec6c669a2b90e113")
5050
testfile2.conc_lics = License.from_identifier("Apache-2.0")
5151
testfile2.add_lics(License.from_identifier("Apache-2.0"))
5252
testfile2.copyright = NoAssert()
@@ -58,7 +58,7 @@
5858
package.file_name = "twt.jar"
5959
package.spdx_id = 'TestPackage#SPDXRef-PACKAGE'
6060
package.download_location = "http://www.tagwritetest.test/download"
61-
package.check_sum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
61+
package.checksum = Algorithm("SHA1", "c537c5d99eca5333f23491d47ededd083fefb7ad")
6262
package.homepage = SPDXNone()
6363
package.verif_code = "4e3211c67a2d28fced849ee1bb76e7391b93feba"
6464
license_set = LicenseConjunction(

spdx/cli_tools/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def main(file, force):
5050
"Package Download Location: {0}".format(doc.package.download_location)
5151
)
5252
print("Package Homepage: {0}".format(doc.package.homepage))
53-
if doc.package.check_sum:
54-
print("Package Checksum: {0}".format(doc.package.check_sum.value))
53+
if doc.package.checksum:
54+
print("Package Checksum: {0}".format(doc.package.checksum.value))
5555
print("Package Attribution Text: {0}".format(doc.package.attribution_text))
5656
print("Package verification code: {0}".format(doc.package.verif_code))
5757
print(
@@ -77,7 +77,7 @@ def main(file, force):
7777
for f in doc.files:
7878
print("\tFile name: {0}".format(f.name))
7979
print("\tFile type: {0}".format(VALUES[f.type]))
80-
print("\tFile Checksum: {0}".format(f.chk_sum.value))
80+
print("\tFile Checksum: {0}".format(f.chksum.value))
8181
print("\tFile license concluded: {0}".format(f.conc_lics))
8282
print(
8383
"\tFile license info in file: {0}".format(

spdx/file.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class File(object):
4242
- comment: File comment str, Optional zero or one.
4343
- type: one of FileType.SOURCE, FileType.BINARY, FileType.ARCHIVE
4444
and FileType.OTHER, optional zero or one.
45-
- chk_sum: SHA1, Mandatory one.
45+
- chksum: SHA1, Mandatory one.
4646
- conc_lics: Mandatory one. document.License or utils.NoAssert or utils.SPDXNone.
4747
- licenses_in_file: list of licenses found in file, mandatory one or more.
4848
document.License or utils.SPDXNone or utils.NoAssert.
@@ -58,12 +58,12 @@ class File(object):
5858
-attribution_text: optional string.
5959
"""
6060

61-
def __init__(self, name, spdx_id=None, chk_sum=None):
61+
def __init__(self, name, spdx_id=None, chksum=None):
6262
self.name = name
6363
self.spdx_id = spdx_id
6464
self.comment = None
6565
self.type = None
66-
self.checksums = [None]
66+
self.checksums = [chksum]
6767
self.conc_lics = None
6868
self.licenses_in_file = []
6969
self.license_comment = None
@@ -83,15 +83,15 @@ def __lt__(self, other):
8383
return self.name < other.name
8484

8585
@property
86-
def chk_sum(self):
86+
def chksum(self):
8787
"""
8888
Backwards compatibility, return first checksum.
8989
"""
9090
# NOTE Package.check_sum but File.chk_sum
9191
return self.checksums[0]
9292

93-
@chk_sum.setter
94-
def chk_sum(self, value):
93+
@chksum.setter
94+
def chksum(self, value):
9595
self.checksums[0] = value
9696

9797
def add_lics(self, lics):
@@ -190,12 +190,12 @@ def validate_type(self, messages):
190190
return messages
191191

192192
def validate_checksum(self, messages):
193-
if not isinstance(self.chk_sum, checksum.Algorithm):
193+
if not isinstance(self.chksum, checksum.Algorithm):
194194
messages.append(
195195
"File checksum must be instance of spdx.checksum.Algorithm"
196196
)
197197
else:
198-
if not self.chk_sum.identifier == "SHA1":
198+
if not self.chksum.identifier == "SHA1":
199199
messages.append("File checksum algorithm must be SHA1")
200200

201201
return messages

spdx/package.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ def are_files_analyzed(self):
106106
# return self.files_analyzed or self.files_analyzed is None
107107

108108
@property
109-
def check_sum(self):
109+
def checksum(self):
110110
"""
111111
Backwards compatibility, return first checksum.
112112
"""
113113
# NOTE Package.check_sum but File.chk_sum
114114
return self.checksums[0]
115115

116-
@check_sum.setter
117-
def check_sum(self, value):
116+
@checksum.setter
117+
def checksum(self, value):
118118
self.checksums[0] = value
119119

120120
def add_file(self, fil):
@@ -283,12 +283,12 @@ def validate_str_fields(self, fields, optional, messages):
283283
return messages
284284

285285
def validate_checksum(self, messages):
286-
if self.check_sum is not None:
287-
if not isinstance(self.check_sum, checksum.Algorithm):
286+
if self.checksum is not None:
287+
if not isinstance(self.checksum, checksum.Algorithm):
288288
messages.append(
289289
"Package checksum must be instance of spdx.checksum.Algorithm"
290290
)
291-
elif not self.check_sum.identifier == "SHA1":
291+
elif not self.checksum.identifier == "SHA1":
292292
messages.append(
293293
"First checksum in package must be SHA1."
294294
)
@@ -300,10 +300,10 @@ def calc_verif_code(self):
300300

301301
for file_entry in self.files:
302302
if (
303-
isinstance(file_entry.chk_sum, checksum.Algorithm)
304-
and file_entry.chk_sum.identifier == "SHA1"
303+
isinstance(file_entry.chksum, checksum.Algorithm)
304+
and file_entry.chksum.identifier == "SHA1"
305305
):
306-
sha1 = file_entry.chk_sum.value
306+
sha1 = file_entry.chksum.value
307307
else:
308308
sha1 = file_entry.calc_chksum()
309309
hashes.append(sha1)

0 commit comments

Comments
 (0)