Skip to content

Commit 9aba333

Browse files
authored
Merge pull request #430 from sschuberth/spdx-tv
Add basic SPDX tag/value (and also RDF) output for #338
2 parents 31b1b0b + 3ab4da1 commit 9aba333

36 files changed

+562
-23
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def read(*names, **kwargs):
100100
'MarkupSafe >= 0.23',
101101
'colorama',
102102
'simplejson',
103+
'spdx-tools',
103104

104105
# packagedcode
105106
'requests >= 2.7.0, < 3.0.0',

src/scancode/cli.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def wrap(self, timeout=None):
6262

6363
import click
6464
from click.termui import style
65-
import simplejson as json
6665

6766
from commoncode import filetype
6867
from commoncode import fileutils
@@ -132,8 +131,6 @@ def wrap(self, timeout=None):
132131
Visit https://github.com/nexB/scancode-toolkit/ for support and download.
133132
'''
134133

135-
acknowledgment_text_json = acknowledgment_text.strip().replace(' ', '')
136-
137134

138135
extra_notice_text = '''
139136
@@ -248,7 +245,7 @@ class ScanCommand(utils.BaseCommand):
248245
Try 'scancode --help' for help on options and arguments.'''
249246

250247

251-
formats = ('json', 'html', 'html-app',)
248+
formats = ('json', 'html', 'html-app', 'spdx-tv', 'spdx-rdf')
252249

253250
def validate_formats(ctx, param, value):
254251
value_lower = value.lower()
@@ -640,13 +637,64 @@ def save_results(files_count, scanned_files, format, input, output_file):
640637
echo_stderr('\nFailed to create HTML app.', fg='red')
641638

642639
elif format == 'json':
640+
import simplejson as json
641+
643642
meta = OrderedDict()
644-
meta['scancode_notice'] = acknowledgment_text_json
643+
meta['scancode_notice'] = acknowledgment_text.strip().replace(' ', '')
645644
meta['scancode_version'] = version
646645
meta['files_count'] = files_count
647646
# TODO: add scanning options to meta
648647
meta['files'] = scanned_files
649648
output_file.write(unicode(json.dumps(meta, indent=2 * ' ', iterable_as_array=True, encoding='utf-8')))
650649
output_file.write('\n')
650+
651+
elif format == 'spdx-tv' or format == 'spdx-rdf':
652+
from spdx.checksum import Algorithm
653+
from spdx.creationinfo import Tool
654+
from spdx.document import Document, License
655+
from spdx.file import File
656+
from spdx.package import Package
657+
from spdx.utils import NoAssert
658+
from spdx.version import Version
659+
660+
doc = Document(Version(2, 1), License.from_identifier('CC0-1.0'))
661+
662+
doc.creation_info.add_creator(Tool('ScanCode ' + version))
663+
doc.creation_info.set_created_now()
664+
665+
doc.package = Package(input, NoAssert())
666+
667+
for file_data in scanned_files:
668+
file_entry = File(file_data['path'])
669+
# FIXME: should we really compue the checcksum here rather than get it from the scan?
670+
file_entry.chk_sum = Algorithm('SHA1', file_entry.calc_chksum())
671+
for file_license in file_data['licenses']:
672+
spdx_id = file_license.get('spdx_license_key')
673+
# TODO: we should create a "LicenseRef:xxx" identifier
674+
# if the license is not known to SPDX
675+
if spdx_id:
676+
spdx_license = License.from_identifier(spdx_id)
677+
file_entry.add_lics(spdx_license)
678+
doc.package.add_lics_from_file(spdx_license)
679+
680+
file_entry.conc_lics = NoAssert()
681+
file_entry.copyright = NoAssert()
682+
doc.package.add_file(file_entry)
683+
684+
# Remove duplicate licenses from the list.
685+
doc.package.licenses_from_files = list(set(doc.package.licenses_from_files))
686+
687+
doc.package.verif_code = doc.package.calc_verif_code()
688+
doc.package.cr_text = NoAssert()
689+
doc.package.license_declared = NoAssert()
690+
doc.package.conc_lics = NoAssert()
691+
692+
if format == 'spdx-tv':
693+
from spdx.writers.tagvalue import write_document
694+
write_document(doc, output_file)
695+
else:
696+
from spdx.writers.rdf import write_document
697+
write_document(doc, output_file)
698+
651699
else:
652700
raise Exception('Unknown format')

tests/textcode/data/markup_expected/Label.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
//-->
7373

7474

75-
<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
75+
All Classes
7676

7777

7878

@@ -622,7 +622,7 @@
622622
//-->
623623

624624

625-
<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
625+
All Classes
626626

627627

628628

@@ -639,4 +639,6 @@
639639

640640

641641

642-
Submit a bug or featureFor further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
642+
Submit a bug or featureFor further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
643+
644+

tests/textcode/data/markup_expected/chinese.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
var dmtrack_c='{-}'; var dmtrack_pageid='bc69c0cd0a93681e1429438175';
3131
(function(d){var t=d.createElement('script');t.type='text/javascript';t.async=true;t.src='http://style.c.aliimg.com/sys/js/beacon/cnb.js';d.getElementsByTagName('head')[0].appendChild(t);}(document));
32-
<img src="http://dmtracking.1688.com/b.jpg?cD0yJnU9e3d3dy4xNjg4LmNvbVwvfSZtPXtHRVR9JnM9ezIwMH0mcj17LX0mYT17LX0mYj0tJmM9ey19Cg==&ver=40&pageid=bc69c0cd0a93681e1429438175&time=1429438175" width="1" height="1" style="display:none">
32+
3333
var _SPM_a='{-}'; var _SPM_b='{-}';var _SPM_app_name='{-}';var _SPM_template_path='{-}';
3434

3535
with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","category=&userid=&aplus&&asid=AADffjNVzesW9Lwhfic=&aat=&abi=141%2e62%2e60%2e13%2e1427127568230%2e412828%2e7&abb=&",id="tb-beacon-aplus",src=(location>"https"?"//g":"//g")+".alicdn.com/alilog/mlog/aplus_b2b.js")

tests/textcode/data/markup_expected/services.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919

20-
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-TWT88B" height="0" width="0" style="display:none;visibility:hidden"></iframe>
20+
2121

2222

2323

thirdparty/base/setuptools-25.2.0-py2.py3-none-any.whl renamed to thirdparty/base/setuptools-32.3.1-py2.py3-none-any.whl

432 KB
Binary file not shown.

thirdparty/base/setuptools.ABOUT

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
about_resource: setuptools-25.2.0-py2.py3-none-any.whl
1+
about_resource: setuptools-32.3.1-py2.py3-none-any.whl
22
name: setuptools
3-
version: 25.2.0
3+
version: 32.3.1
44

5-
download_url: setuptools-25.2.0-py2.py3-none-any.whl
5+
download_url: https://pypi.python.org/packages/69/19/b1dff551058ce79d88b1e3688f1c735590d7ddf44d10681512133b35019f/setuptools-32.3.1-py2.py3-none-any.whl#md5=9fe4e32f20a9b13c206c1bdc4c9feaf4
66

77
home_url: https://pypi.python.org/pypi/setuptools
88
owner: Python Packaging Authority

thirdparty/base/setuptools.LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2016 Jason R Coombs <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
21.6 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
about_resource: SPARQLWrapper-1.8.0-cp27-none-any.whl
2+
name: SPARQLWrapper
3+
version: 1.8.0
4+
home_url: http://rdflib.github.io/sparqlwrapper/
5+
download_url: https://pypi.python.org/packages/03/69/3a625d5315a85174c4a0ab9b9afc0018c21a618117de141dc53e14d5de97/SPARQLWrapper-1.8.0.tar.gz#md5=9541c7d6f01ed2a98efb4b86bbc982e8
6+
authors: Ivan Herman, Sergio Fernández, Carlos Tejo Alonso, Alexey Zakhlestin
7+
owner: World Wide Web Consortium <http://www.w3.org> Foundation CTIC <http://www.fundacionctic.org/>
8+
copyright: Copyright (c) 2002-2015, RDFLib Team
9+
10+
vcs_tool: git
11+
vcs_repository: https://github.com/rdflib/sparqlwrapper.git
12+
13+
dje_license: w3c
14+
license_text_file: SPARQLWrapper.LICENSE

0 commit comments

Comments
 (0)