Skip to content

Commit

Permalink
Merge pull request #40 from klassen-software-solutions/development/v1
Browse files Browse the repository at this point in the history
Development/v1
  • Loading branch information
stevenklassen8376 authored Mar 17, 2020
2 parents 7eed43e + 031d7c8 commit 4c61799
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Dependencies/prereqs-licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"LicenseScanner"
]
}
]
],
"generated": {
"process": "license-scanner",
"project": "LicenseScanner",
"time": "2020-03-17T09:46:44.903913-06:00"
}
}
5 changes: 5 additions & 0 deletions Tests/features/steps/dependencies_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def step_impl(context):
filename = "Tests/Projects/%s/Dependencies/tmp-prereqs-licenses.json" % context.project
assert os.path.isfile(filename), "%s should exist" % filename
context.licenses = jsonreader.from_file(filename)
metadata = context.licenses.get('generated', None)
assert metadata is not None
assert metadata.get('process', None) is not None
assert metadata.get('project', None) is not None
assert metadata.get('time', None) is not None

@then(u'there should be {count:d} modules')
def step_impl(context, count):
Expand Down
22 changes: 19 additions & 3 deletions kss/license/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Scans a directory to determine the licenses of its dependancies."""

import argparse
import datetime
import json
import logging
import os
Expand Down Expand Up @@ -39,17 +40,32 @@ def _parse_command_line(args: List):
return parser.parse_args(args)


def _write_licenses(filename: str, licenses: Dict):
def _write_licenses(filename: str, licenses: Dict, metadata: Dict):
if len(licenses) > 0:
outputdir = os.path.dirname(filename)
if outputdir:
pathlib.Path(outputdir).mkdir(parents=True, exist_ok=True)
data = {'dependencies': sorted(licenses.values(), key=lambda x: x['moduleName'])}
data = {
'dependencies': sorted(licenses.values(), key=lambda x: x['moduleName']),
'generated': metadata
}
with open(filename, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True)
else:
logging.info("No dependencies found")

def _generated_metadata():
args = ""
if len(sys.argv) > 1:
args = " %s" % ' '.join(sys.argv[1:])
metadata = {
'time': datetime.datetime.now().astimezone().isoformat(),
'process': 'license-scanner%s' % args,
'project': os.path.basename(os.getcwd())
}
return metadata



def scan(args: List = None):
"""Main entry point.
Expand Down Expand Up @@ -90,7 +106,7 @@ def scan(args: List = None):
]
for scanner in scanners:
scanner.add_licenses(licenses)
_write_licenses(outputfile, licenses)
_write_licenses(outputfile, licenses, _generated_metadata())
finally:
os.chdir(cwd)

Expand Down

0 comments on commit 4c61799

Please sign in to comment.