Skip to content

Commit d197a3a

Browse files
authored
Merge pull request spdx#148 from Yash-Varshney/task-3
CommunityBridge Project by Yash Varshney
2 parents 41a5e4a + efd0e59 commit d197a3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4922
-2695
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
[5]: https://ci.appveyor.com/api/projects/status/0bf9glha2yg9x8ef/branch/master?svg=true
1212
[6]: https://ci.appveyor.com/project/spdx/tools-python/branch/master
1313

14+
15+
# Information
16+
1417
This library implements an SPDX tag/value and RDF parser, validator and handler in Python.
1518
This is the result of an initial GSoC contribution by @[ah450](https://github.com/ah450) (or https://github.com/a-h-i) and
1619
is maintained by a community of SPDX adopters and enthusiasts.
@@ -41,37 +44,35 @@ Pypi: https://pypi.python.org/pypi/spdx-tools
4144

4245
# How to use
4346

44-
Example tag/value parsing usage:
45-
```Python
46-
from spdx.parsers.tagvalue import Parser
47-
from spdx.parsers.tagvaluebuilders import Builder
48-
from spdx.parsers.loggers import StandardLogger
49-
p = Parser(Builder(), StandardLogger())
50-
p.build()
51-
# data is a string containing the SPDX file.
52-
document, error = p.parse(data)
47+
## Command-line usage:
48+
49+
1. **PARSER** (for parsing any format):
50+
* Use `parser --file <filename>` where `<filename>` is the location of the file.
51+
Try running : `parser --file data/SPDXRdfExample.rdf`.
52+
53+
* Or you can use `parser` only and then it will automatically prompt/ask for `filename`.
5354

54-
```
55+
* for help - use `parser --help`
5556

56-
The `examples` directory contains several code samples. Here some of them:
5757

58-
* `parse_tv.py` is an example tag/value parsing usage.
59-
Try running `python parse_tv.py ../data/SPDXSimpleTag.tag `
58+
2. **CONVERTOR** (for converting one format to another):
59+
* If I/O formats are known:
60+
61+
* Use `convertor --infile/-i <input_file> --outfile/-o <output_file>` where `<input_file>` is the location of the file to be converted
62+
(Note: only RDF and Tag formated supported) and `<output_file>` is the location of the output file.
63+
Try running : `convertor --infile data/SPDXRdfExample.rdf --outfile output.json`
6064

61-
* `write_tv.py` provides an example of writing tag/value files.
62-
Run `python write_tv.py sample.tag` to test it.
65+
* If I/O formats are not known:
6366

64-
* `pp_tv.py` demonstrates how to pretty-print a tag/value file.
65-
To test it run `python pp_tv.py ../data/SPDXTagExample.tag pretty.tag`.
67+
* Use `convertor --from/-f <input_format> <input_file> --to/-t <output_format> <output_file>` where `<input_format>` is the manually enterred format of the input file (can be either rdf or tag)
68+
and `<out_format>` (can be tag, rdf, json, yaml, xml) is the manually enterred format of the output file.
69+
Try running : `convertor --from tag data/SPDXTagExample.in --to yaml output.out`
6670

67-
* `parse_rdf.py` demonstrates how to parse an RDF file and print out document
68-
information. To test it run `python parse_rdf.py ../data/SPDXRdfExample.rdf`
71+
* If anyone format is known and other is not, you can use the mixture of the above two points.
72+
Ex. : `convertor -f rdf data/SPDXRdfExample.xyz -o output.xml`
6973

70-
* `rdf_to_tv.py` demonstrates how to convert an RDF file to a tag/value one.
71-
To test it run `python rdf_to_tv.py ../data/SPDXRdfExample.rdf converted.tag`
74+
* for help - use `convertor --help`
7275

73-
* `pp_rdf.py` demonstrates how to pretty-print an RDF file, to test it run
74-
`python pp_rdf.py ../data/SPDXRdfExample.rdf pretty.rdf`
7576

7677

7778
# Installation

data/SPDXJsonExample.json

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"documentDescribes": [
66
{
77
"Package": {
8-
"id": "SPDXRef-Package",
8+
"SPDXID": "SPDXRef-Package",
99
"originator": "Organization: SPDX",
1010
"files": [
1111
{
@@ -28,14 +28,14 @@
2828
"licenseComments": "This license is used by Jena",
2929
"checksums": [
3030
{
31-
"value": "3ab4e1c67a2d28fced849ee1bb76e7391b93f125",
31+
"checksumValue": "3ab4e1c67a2d28fced849ee1bb76e7391b93f125",
3232
"algorithm": "checksumAlgorithm_sha1"
3333
}
3434
],
3535
"fileTypes": [
3636
"fileType_archive"
3737
],
38-
"id": "SPDXRef-File1"
38+
"SPDXID": "SPDXRef-File1"
3939
}
4040
},
4141
{
@@ -49,14 +49,14 @@
4949
"licenseConcluded": "Apache-2.0",
5050
"checksums": [
5151
{
52-
"value": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
52+
"checksumValue": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
5353
"algorithm": "checksumAlgorithm_sha1"
5454
}
5555
],
5656
"fileTypes": [
5757
"fileType_source"
5858
],
59-
"id": "SPDXRef-File2"
59+
"SPDXID": "SPDXRef-File2"
6060
}
6161
}
6262
],
@@ -77,17 +77,18 @@
7777
"sourceInfo": "Version 1.0 of the SPDX Translator application",
7878
"copyrightText": " Copyright 2010, 2011 Source Auditor Inc.",
7979
"packageVerificationCode": {
80-
"value": "4e3211c67a2d28fced849ee1bb76e7391b93feba",
81-
"excludedFilesNames": [
80+
"packageVerificationCodeValue": "4e3211c67a2d28fced849ee1bb76e7391b93feba",
81+
"packageVerificationCodeExcludedFiles": [
8282
"SpdxTranslatorSpdx.rdf",
8383
"SpdxTranslatorSpdx.txt"
8484
]
8585
},
8686
"licenseConcluded": "(Apache-1.0 AND LicenseRef-2 AND MPL-1.1 AND LicenseRef-3 AND LicenseRef-4 AND Apache-2.0 AND LicenseRef-1)",
87-
"supplier": "Organization: Linux Foundation",
87+
"supplier": "Organization: Linux Foundation",
88+
"attributionTexts" : [ "The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually." ],
8889
"checksums": [
8990
{
90-
"value": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
91+
"checksumValue": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
9192
"algorithm": "checksumAlgorithm_sha1"
9293
}
9394
],
@@ -111,23 +112,36 @@
111112
"externalDocumentRefs": [
112113
{
113114
"checksum": {
114-
"value": "d6a770ba38583ed4bb4525bd96e50461655d2759",
115+
"checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2759",
115116
"algorithm": "checksumAlgorithm_sha1"
116117
},
117-
"spdxDocumentNamespace": "https://spdx.org/spdxdocs/spdx-tools-v2.1-3F2504E0-4F89-41D3-9A0C-0305E82C3301",
118+
"spdxDocument": "https://spdx.org/spdxdocs/spdx-tools-v2.1-3F2504E0-4F89-41D3-9A0C-0305E82C3301",
118119
"externalDocumentId": "DocumentRef-spdx-tool-2.1"
119120
}
120121
],
121-
"namespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
122+
"documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
122123
"annotations": [
123124
{
124125
"comment": "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses",
125126
"annotationType": "REVIEW",
126-
"id": "SPDXRef-45",
127+
"SPDXID": "SPDXRef-45",
127128
"annotationDate": "2012-06-13T00:00:00Z",
128129
"annotator": "Person: Jim Reviewer"
129130
}
130131
],
132+
"relationships" : [ {
133+
"spdxElementId" : "SPDXRef-DOCUMENT",
134+
"relatedSpdxElement" : "SPDXRef-Package",
135+
"relationshipType" : "CONTAINS"
136+
}, {
137+
"spdxElementId" : "SPDXRef-DOCUMENT",
138+
"relatedSpdxElement" : "SPDXRef-File",
139+
"relationshipType" : "DESCRIBES"
140+
}, {
141+
"spdxElementId" : "SPDXRef-DOCUMENT",
142+
"relatedSpdxElement" : "SPDXRef-Package",
143+
"relationshipType" : "DESCRIBES"
144+
} ],
131145
"dataLicense": "CC0-1.0",
132146
"reviewers": [
133147
{
@@ -141,7 +155,7 @@
141155
"reviewDate": "2011-03-13T00:00:00Z"
142156
}
143157
],
144-
"extractedLicenseInfos": [
158+
"hasExtractedLicensingInfos": [
145159
{
146160
"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. ",
147161
"licenseId": "LicenseRef-2"
@@ -165,8 +179,8 @@
165179
"licenseId": "LicenseRef-1"
166180
}
167181
],
168-
"specVersion": "SPDX-2.1",
169-
"id": "SPDXRef-DOCUMENT",
182+
"spdxVersion": "SPDX-2.1",
183+
"SPDXID": "SPDXRef-DOCUMENT",
170184
"snippets": [
171185
{
172186
"comment": "This snippet was identified as significant and highlighted in this Apache-2.0 file, when a commercial scanner identified it as being derived from file foo.c in package xyz which is licensed under GPL-2.0-or-later.",
@@ -177,7 +191,7 @@
177191
"Apache-2.0"
178192
],
179193
"licenseComments": "The concluded license was taken from package xyz, from which the snippet was copied into the current file. The concluded license information was found in the COPYING.txt file in package xyz.",
180-
"id": "SPDXRef-Snippet",
194+
"SPDXID": "SPDXRef-Snippet",
181195
"fileId": "SPDXRef-DoapSource"
182196
}
183197
]

data/SPDXRdfExample.rdf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
</j.0:Project>
7979
</artifactOf>
8080
<licenseComments>This license is used by Jena</licenseComments>
81+
<attributionText>The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.</attributionText>
8182
<fileName>Jenna-2.6.3/jena-2.6.3-sources.jar</fileName>
8283
<fileType rdf:resource="http://spdx.org/rdf/terms#fileType_archive"/>
8384
<copyrightText>(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP</copyrightText>
@@ -115,6 +116,12 @@
115116
<annotator>Person: Jim Reviewer</annotator>
116117
</Annotation>
117118
</annotation>
119+
<relationship>
120+
<Relationship>
121+
<relationshipType rdf:resource="http://spdx.org/rdf/terms#relationshipType_describes"/>
122+
<relatedSpdxElement rdf:resource="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-Package"/>
123+
</Relationship>
124+
</relationship>
118125
<referencesFile>
119126
<File rdf:about="https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-File2">
120127
<copyrightText>Copyright 2010, 2011 Source Auditor Inc.</copyrightText>

data/SPDXSimpleTag.tag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ PackageSourceInfo: <text>Version 1.0 of test</text>
3434
PackageFileName: test-1.0.zip
3535
PackageSupplier: Organization:ACME
3636
PackageOriginator: Organization:ACME
37+
PackageAttributionText: <text>The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.</text>
3738
PackageChecksum: SHA1: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
3839
PackageVerificationCode: 4e3211c67a2d28fced849ee1bb76e7391b93feba (something.rdf, something.txt)
3940
PackageDescription: <text>A package.</text>
41+
PackageAttributionText: <text>The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.</text>
4042
PackageCopyrightText: <text> Copyright 2010, 2011 Acme Inc.</text>
4143
PackageLicenseDeclared: Apache-2.0
4244
PackageLicenseConcluded: (LicenseRef-2.0 and Apache-2.0)

data/SPDXTagExample.tag

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ ReviewComment: <text>Another example reviewer.</text>
2424
## Annotation Information
2525
Annotator: Person: Jim Annotator
2626
AnnotationType: REVIEW
27-
AnnotationDate: 2012-03-11T00:00:00Z
27+
AnnotationDate: 2010-01-29T18:30:22Z
2828
AnnotationComment: <text>An example annotation comment.</text>
2929
SPDXREF: SPDXRef-45
3030

31+
## Relationships
32+
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-File
33+
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package
34+
Relationship: SPDXRef-DOCUMENT COPY_OF DocumentRef-spdx-tool-1.2:SPDXRef-ToolsElement
35+
Relationship: SPDXRef-DOCUMENT CONTAINS SPDXRef-Package
36+
3137
## Package Information
3238
PackageName: SPDX Translator
3339
SPDXID: SPDXRef-Package
@@ -42,6 +48,7 @@ PackageOriginator: Organization:SPDX
4248
PackageChecksum: SHA1: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
4349
PackageVerificationCode: 4e3211c67a2d28fced849ee1bb76e7391b93feba (SpdxTranslatorSpdx.rdf, SpdxTranslatorSpdx.txt)
4450
PackageDescription: <text>This utility translates and SPDX RDF XML document to a spreadsheet, translates a spreadsheet to an SPDX RDF XML document and translates an SPDX RDFa document to an SPDX RDF XML document.</text>
51+
PackageAttributionText: <text>The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.</text>
4552
PackageComment: <text>This package includes several sub-packages.</text>
4653

4754
PackageCopyrightText: <text> Copyright 2010, 2011 Source Auditor Inc.</text>

0 commit comments

Comments
 (0)