Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[colic] Add copyright flag for extraction of copyright information #50

Merged
merged 2 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions graal/backends/core/analyzers/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,26 @@ def __init__(self, exec_path, cli=False):
_ = subprocess.check_output([exec_path]).decode("utf-8")

def __analyze_scancode(self, file_path):
"""Add information about license using scancode
"""Add information about license and copyright using scancode

:param file_path: file path (in case of scancode)
"""
result = {'licenses': []}
result = {
'licenses': [],
'copyrights': [],
}
try:
msg = subprocess.check_output([self.exec_path, '--json-pp', '-', '--license', file_path]).decode("utf-8")
msg = subprocess.check_output(
[self.exec_path, '--json-pp', '-', '--license', '--copyright', file_path]).decode("utf-8")
except subprocess.CalledProcessError as e:
raise GraalError(cause="Scancode failed at %s, %s" % (file_path, e.output.decode("utf-8")))
finally:
subprocess._cleanup()

licenses_raw = json.loads(msg)
if 'files' in licenses_raw:
result['licenses'] = licenses_raw['files'][0]['licenses']
scancode_raw = json.loads(msg)
if 'files' in scancode_raw:
result['licenses'] = scancode_raw['files'][0]['licenses']
result['copyrights'] = scancode_raw['files'][0]['copyrights']

return result

Expand Down
3 changes: 2 additions & 1 deletion graal/backends/core/colic.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def analyze(self, file_path):

:returns a dict containing the results of the analysis, like the one below
{
'licenses': [..]
'licenses': [..],
'copyrights': [..]
}
"""
if self.kind == SCANCODE_CLI:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_colic.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,14 @@ def test_analyze(self):
analysis = license_analyzer.analyze(file_path)

self.assertIn('licenses', analysis)
self.assertIn('copyrights', analysis)

file_paths = [os.path.join(self.tmp_data_path, ANALYZER_TEST_FILE)]
license_analyzer = LicenseAnalyzer(SCANCODE_CLI_PATH, kind=SCANCODE_CLI)
analysis = license_analyzer.analyze(file_paths)

self.assertIn('licenses', analysis[0])
self.assertIn('copyrights', analysis[0])


class TestCoLicCommand(unittest.TestCase):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_analyze_scancode(self):
result = scancode.analyze(**kwargs)

self.assertIn('licenses', result)
self.assertIn('copyrights', result)

@unittest.mock.patch('subprocess.check_output')
def test_analyze_error(self, check_output_mock):
Expand Down Expand Up @@ -86,6 +87,7 @@ def test_analyze_scancode_cli(self):
result = scancode_cli.analyze(**kwargs)

self.assertIn('licenses', result[0])
self.assertIn('copyrights', result[0])

def test_analyze_error(self):
"""Test whether an exception is thrown in case of error"""
Expand Down