Skip to content

Commit 9291978

Browse files
committed
Walk codebase again to tag summarized Resources
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent d64c886 commit 9291978

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/scancode/plugin_summary.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OriginSummary(PostScanPlugin):
4747
resource_attributes = dict(
4848
origin_summary=attr.ib(default=attr.Factory(OrderedDict)),
4949
is_summary=attr.ib(default=False, type=bool),
50-
summarized=attr.ib(default=False, type=bool)
50+
is_summarized=attr.ib(default=False, type=bool)
5151
)
5252

5353
sort_order = 8
@@ -65,7 +65,6 @@ def is_enabled(self, origin_summary, copyright, license, **kwargs):
6565

6666
def process_codebase(self, codebase, **kwargs):
6767
for resource in codebase.walk(topdown=False):
68-
# TODO: Tag directory as summary if summarization has occured
6968
# TODO: Consider facets for later
7069
# TODO: Group summarizations by copyright holders and license expressions
7170

@@ -80,7 +79,6 @@ def process_codebase(self, codebase, **kwargs):
8079
dir_holders_count = Counter()
8180

8281
for child in children:
83-
# TODO: Tag child as summarized if it's been summarized
8482
for license_expression in child.license_expressions:
8583
if child.is_file:
8684
license_expressions_count = 1
@@ -89,7 +87,6 @@ def process_codebase(self, codebase, **kwargs):
8987
license_expressions_count = child_license_expressions_count[license_expression]
9088
dir_license_expressions_count.update({license_expression: license_expressions_count})
9189

92-
# TODO: Use copyright holders
9390
for holder in child.holders:
9491
holder_value = holder['value']
9592
if child.is_file:
@@ -118,6 +115,25 @@ def process_codebase(self, codebase, **kwargs):
118115
resource.origin_summary['holders'] = dir_holders_count
119116
codebase.save_resource(resource)
120117

118+
# Pass 2: tag the Resources that have been summarized
119+
for resource in codebase.walk(topdown=True):
120+
if resource.is_file or not resource.is_summary:
121+
continue
122+
123+
children = resource.children(codebase)
124+
if not children:
125+
continue
126+
127+
# TODO: There's probably a more pleasing way to do this
128+
for child in children:
129+
for child_license_expression in child.license_expressions:
130+
for child_holder in child.holders:
131+
for resource_holder in resource.holders:
132+
if (child_license_expression in resource.license_expressions
133+
and child_holder['value'] == resource_holder['value']):
134+
child.is_summarized = True
135+
codebase.save_resource(child)
136+
121137

122138
def is_majority(count, files_count):
123139
"""

0 commit comments

Comments
 (0)