Skip to content

Commit 31dc82f

Browse files
authored
Merge pull request #123 from nexB/113-handle-updated-format
Handle updated ScanCode headers
2 parents 14bbc68 + eb8bc12 commit 31dc82f

3 files changed

Lines changed: 1122 additions & 14 deletions

File tree

src/deltacode/models.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def get_options(self, path):
6767
scan = json.loads(open(path).read())
6868

6969
options = scan.get('scancode_options')
70+
if not options:
71+
# Handle new(er) scancode options
72+
headers = scan.get('headers')
73+
if headers:
74+
options = headers[0].get('options')
7075

7176
return options
7277

@@ -77,25 +82,34 @@ def is_valid_scan(self, location):
7782
requirements to be run in DeltaCode (e.g., ScanCode version, proper
7883
ScanCode options etc.).
7984
"""
80-
# TODO: handle this exception during #171
8185
try:
8286
scan = json.loads(open(location).read())
8387
except IOError:
8488
return
8589

8690
scan = json.loads(open(location).read())
8791

88-
if not scan.get('scancode_version'):
89-
msg = ('JSON file \'' + location + '\' is missing the \'scancode_version\' attribute.')
90-
raise ScanException(msg)
92+
version = scan.get('scancode_version')
93+
if not version:
94+
# handle new(er) scancode version location
95+
headers = scan.get('headers')
96+
if headers:
97+
version = headers[0].get('tool_version')
98+
99+
options = scan.get('scancode_options')
100+
if not options:
101+
headers = scan.get('headers')
102+
if headers:
103+
options = headers[0].get('options')
104+
105+
if not version:
106+
raise ScanException('JSON file: {} is missing the ScanCode version.'.format(location))
91107

92-
if int(scan.get('scancode_version').split('.').pop(0)) < 2:
93-
msg = ('JSON file \'' + location + '\' was created with an old version of ScanCode.')
94-
raise ScanException(msg)
108+
if int(version.split('.').pop(0)) < 2:
109+
raise ScanException('JSON file: {} was created with an old version of ScanCode.'.format(location))
95110

96-
if not scan.get('scancode_options').get('--info'):
97-
msg = ('JSON file \'' + location + '\' is missing the \'scancode_options/--info\' attribute.')
98-
raise ScanException(msg)
111+
if not options.get('--info'):
112+
raise ScanException('JSON file: {} is missing the ScanCode --info attribute.'.format(location))
99113

100114
return True
101115

@@ -112,7 +126,13 @@ def get_files_count(self, path):
112126

113127
scan = json.loads(scan)
114128

115-
return scan.get('files_count')
129+
files_count = scan.get('files_count')
130+
if not files_count:
131+
headers = scan.get('headers')
132+
if headers:
133+
files_count = headers[0].get('extra_data', {}).get('files_count')
134+
135+
return files_count
116136

117137
def load_files(self, path):
118138
"""

0 commit comments

Comments
 (0)