Skip to content

Commit ae03fdc

Browse files
committed
Update DeltaCode to hand new+old scancode data #55
* Alert user that file counts are off because of old scancode algoritm * Stop logging Redundant Scan Error * Update test cases for new error message string * Remove Scan Errors tests * Update test data to match new scancode file_count algorithm Signed-off-by: Steven Esser <sesser@nexb.com>
1 parent 768738d commit ae03fdc

10 files changed

Lines changed: 3669 additions & 1033 deletions

src/deltacode/__init__.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, new_path, old_path, options):
6060
# Sort deltas by score, descending, i.e., high > low.
6161
self.deltas.sort(key=lambda Delta: Delta.score, reverse=True)
6262

63-
def align_scan(self):
63+
def align_scans(self):
6464
"""
6565
Seek to align the paths of a pair of files (File objects) in the pair
6666
of incoming scans so that the attributes and other characteristics of
@@ -77,26 +77,26 @@ def align_scan(self):
7777

7878
def determine_delta(self):
7979
"""
80-
Given new and old scans, return an list of Delta objects that can be
81-
sorted by their attributes, e.g., by Delta.score. Return None if no
82-
File objects can be loaded from either scan.
80+
Add to a list of Delta objects that can be sorted by their attributes,
81+
e.g., by Delta.score. Return None if no File objects can be loaded
82+
from either scan.
8383
"""
8484
# align scan and create our index
85-
self.align_scan()
85+
self.align_scans()
8686
new_index = self.new.index_files()
8787
old_index = self.old.index_files()
8888

8989
# gathering counts to ensure no files lost or missing from our 'deltas' set
90-
new_files_visited = 0
91-
old_files_visited = 0
90+
new_visited, old_visited = 0, 0
9291

9392
# perform the deltas
9493
for path, new_files in new_index.items():
9594
for new_file in new_files:
96-
new_files_visited += 1
9795

9896
if new_file.type != 'file':
9997
continue
98+
99+
new_visited += 1
100100

101101
try:
102102
delta_old_files = old_index[path]
@@ -119,23 +119,28 @@ def determine_delta(self):
119119
# now time to find the added.
120120
for path, old_files in old_index.items():
121121
for old_file in old_files:
122-
old_files_visited += 1
123-
124122
if old_file.type != 'file':
125123
continue
124+
125+
old_visited += 1
126126

127127
try:
128-
# This file already classified as 'modified' or 'unmodified' so do nothing
128+
# This file already classified so do nothing
129129
new_index[path]
130130
except KeyError:
131131
self.deltas.append(Delta(None, old_file, 'removed'))
132132
continue
133133

134134
# make sure everything is accounted for
135-
if new_files_visited != self.new.files_count:
136-
self.errors.append("Deltacode Error: Number of visited files({}) does not match total_files({}) in the new scan".format(new_files_visited, self.new.files_count))
137-
if old_files_visited != self.old.files_count:
138-
self.errors.append("Deltacode Error: Number of visited files({}) does not match total_files({}) in the old scan".format(old_files_visited, self.old.files_count))
135+
if new_visited != self.new.files_count:
136+
self.errors.append(
137+
'DeltaCode Warning: new_visited({}) != new_total({}). Assuming old scancode format.'.format(new_visited, self.new.files_count)
138+
)
139+
140+
if old_visited != self.old.files_count:
141+
self.errors.append(
142+
'DeltaCode Warning: old_visited({}) != old_total({}). Assuming old scancode format.'.format(old_visited, self.old.files_count)
143+
)
139144

140145
def determine_moved(self):
141146
"""

src/deltacode/models.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ def load_files(self, path):
126126
with open(path) as jsonf:
127127
scan = jsonf.read()
128128

129-
files = [File(f) for f in json.loads(scan).get('files')]
130-
131-
# make sure we have same number of File objects as in the scan.
132-
if len(files) != self.files_count:
133-
self.errors.append('Scan Error: The number of files calculated with \'len(files)\' does not equal the ScanCode \'files_count\' value for the scan with path = ' + path + '.')
134-
135-
return files
129+
return [File(f) for f in json.loads(scan).get('files')]
136130

137131
def index_files(self, index_key='path'):
138132
"""

tests/data/cli/scan_1_file_moved_new.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"--license-score": 0,
1010
"--format": "json-pp"
1111
},
12-
"files_count": 10,
12+
"files_count": 8,
1313
"files": [
1414
{
1515
"path": "1_file_moved_new/a",

tests/data/cli/scan_1_file_moved_old.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"--license-score": 0,
1010
"--format": "json-pp"
1111
},
12-
"files_count": 10,
12+
"files_count": 8,
1313
"files": [
1414
{
1515
"path": "1_file_moved_old/a",

0 commit comments

Comments
 (0)