Skip to content

Commit 833c138

Browse files
authored
Merge pull request #823 from nexB/275-streamline-package-manifests-models
Streamline package manifests models
2 parents 031d63d + 24e9026 commit 833c138

File tree

1,249 files changed

+51517
-189928
lines changed

Some content is hidden

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

1,249 files changed

+51517
-189928
lines changed

etc/scripts/json2csv.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2
1+
#!/usr/bin/python
22
#
33
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
44
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
@@ -65,7 +65,7 @@ def load_scan(json_input):
6565
return scan_results
6666

6767

68-
def json_scan_to_csv(json_input, csv_output, prefix_path=False):
68+
def json_scan_to_csv(json_input, csv_output, prefix_path=False, include_text=False):
6969
"""
7070
Convert a scancode JSON output file to a nexb-toolkit-like CSV.
7171
csv_output is an open file descriptor.
@@ -81,7 +81,7 @@ def json_scan_to_csv(json_input, csv_output, prefix_path=False):
8181
])
8282

8383
# note: FIXME: headers are collected as a side effect and this is not great
84-
rows = list(flatten_scan(scan_results, headers, prefix_path))
84+
rows = list(flatten_scan(scan_results, headers, prefix_path, include_text=include_text))
8585

8686
ordered_headers = []
8787
for key_group in headers.values():
@@ -94,7 +94,7 @@ def json_scan_to_csv(json_input, csv_output, prefix_path=False):
9494
w.writerow(r)
9595

9696

97-
def flatten_scan(scan, headers, prefix_path=False):
97+
def flatten_scan(scan, headers, prefix_path=False, include_text=False):
9898
"""
9999
Yield ordered dictionaries of key/values flattening the sequence
100100
data in a single line-separated value and keying always by path,
@@ -139,8 +139,11 @@ def collect_keys(mapping, key_group):
139139
for k, val in licensing.items():
140140
# do not include matched text for now.
141141
if k == 'matched_text':
142-
continue
143-
if k == 'matched_rule':
142+
if include_text:
143+
val = val[:100]
144+
else:
145+
continue
146+
elif k == 'matched_rule':
144147
for mrk, mrv in val.items():
145148
mrk = 'matched_rule__' + mrk
146149
if mrk == 'license_choice':
@@ -197,12 +200,7 @@ def collect_keys(mapping, key_group):
197200

198201
# exclude some columns from the packages for now
199202
excluded_package_columns = {
200-
'packaging',
201-
'payload_type',
202-
'keywords_doc_url',
203-
'download_sha1',
204-
'download_sha256',
205-
'download_md5',
203+
'download_checksums',
206204
'code_view_url',
207205
'vcs_tool',
208206
'vcs_revision',
@@ -226,13 +224,13 @@ def collect_keys(mapping, key_group):
226224
val = 'v ' + val
227225
pack[nk] = val
228226

229-
# FIXME: we only keep for now some of the value collections
230-
elif not val or k not in ('authors', 'download_urls', 'copyrights', 'asserted_licenses'):
227+
# FIXME: we only keep for now some of the collected values
228+
elif not val or k not in ('parties',):
231229
continue
232230

233231
pack[nk] = ''
234-
if k == 'authors':
235-
# FIXME: we only keep the first author name for now
232+
if k == 'parties':
233+
# FIXME: we only keep the first party name for now
236234
pack[nk] = val[0]['name']
237235

238236
elif k == 'download_urls':
@@ -243,13 +241,6 @@ def collect_keys(mapping, key_group):
243241
# All copyright statements are joined in a single multiline value
244242
pack[nk] = '\n'.join(val)
245243

246-
elif k == 'asserted_licenses':
247-
# FIXME: we only keep some license data for now
248-
# All licenses are joined in a single multi-line value
249-
licenses = [license_info.get('license') for license_info in val]
250-
licenses = [lic for lic in licenses if lic]
251-
pack[nk] = '\n'.join(licenses)
252-
253244
collect_keys(pack, 'package')
254245
yield pack
255246

@@ -259,7 +250,8 @@ def collect_keys(mapping, key_group):
259250
@click.argument('csv_output', type=click.File('wb', lazy=False))
260251
@click.help_option('-h', '--help')
261252
@click.option('--prefix_path', is_flag=True, default=False, help='Add a "/code" directory prefix to all paths.')
262-
def cli(json_input, csv_output, prefix_path=False):
253+
@click.option('--include-text', is_flag=True, default=False, help='Add the first 100 chars of a license text if available.')
254+
def cli(json_input, csv_output, prefix_path=False, include_text=False):
263255
"""
264256
!!! LEGACY: use the new --format csv option in the scancode command line instead
265257
@@ -270,7 +262,7 @@ def cli(json_input, csv_output, prefix_path=False):
270262
Paths will be prefixed with '/code/' to provide a common base directory for scanned resources.
271263
"""
272264
json_input = os.path.abspath(os.path.expanduser(json_input))
273-
json_scan_to_csv(json_input, csv_output, prefix_path)
265+
json_scan_to_csv(json_input, csv_output, prefix_path, include_text)
274266

275267

276268
if __name__ == '__main__':

etc/scripts/sch2js/doc/AssertedLicense-json-schema.json

Lines changed: 0 additions & 57 deletions
This file was deleted.

etc/scripts/sch2js/doc/Dependency-json-schema.json

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"id": "",
4+
"type": "object",
5+
"title": "dependent package",
6+
"description": "An identifiable dependent package package object.",
7+
"properties": {
8+
"purl": {
9+
"oneOf": [
10+
{
11+
"type": "string",
12+
"title": "Dependent package URL",
13+
"description": "A compact purl package URL"
14+
},
15+
{
16+
"type": "null"
17+
}
18+
]
19+
},
20+
"requirement": {
21+
"oneOf": [
22+
{
23+
"type": "string",
24+
"title": "dependent package version requirement",
25+
"description": "A string defining version(s)requirements. Package-type specific."
26+
},
27+
{
28+
"type": "null"
29+
}
30+
]
31+
},
32+
"scope": {
33+
"oneOf": [
34+
{
35+
"type": "string",
36+
"title": "dependency scope",
37+
"description": "The scope of this dependency, such as runtime, install, etc. This is package-type specific and is the original scope string."
38+
},
39+
{
40+
"type": "null"
41+
}
42+
]
43+
},
44+
"is_runtime": {
45+
"oneOf": [
46+
{
47+
"type": "boolean",
48+
"title": "is optional flag",
49+
"description": "True if this dependency is an optional dependency"
50+
},
51+
{
52+
"type": "null"
53+
}
54+
]
55+
},
56+
"is_optional": {
57+
"oneOf": [
58+
{
59+
"type": "boolean"
60+
},
61+
{
62+
"type": "null"
63+
}
64+
]
65+
},
66+
"is_resolved": {
67+
"oneOf": [
68+
{
69+
"type": "boolean",
70+
"title": "is resolved flag",
71+
"description": "True if this dependency version requirement has been resolved and this dependency url points to an exact version."
72+
},
73+
{
74+
"type": "null"
75+
}
76+
]
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)