diff --git a/BuildSystem b/BuildSystem index ad0180f..26dcb32 160000 --- a/BuildSystem +++ b/BuildSystem @@ -1 +1 @@ -Subproject commit ad0180f4956acfed9696518fb09a2ba471fd207e +Subproject commit 26dcb32d932fdc162db0ab8f7346c78877f48fc2 diff --git a/Dependencies/prereqs-licenses.json b/Dependencies/prereqs-licenses.json index a9a84f6..18b5164 100644 --- a/Dependencies/prereqs-licenses.json +++ b/Dependencies/prereqs-licenses.json @@ -11,5 +11,10 @@ "LicenseScanner" ] } - ] + ], + "generated": { + "process": "license-scanner", + "project": "LicenseScanner", + "time": "2020-03-17T09:46:44.903913-06:00" + } } \ No newline at end of file diff --git a/Tests/features/steps/dependencies_steps.py b/Tests/features/steps/dependencies_steps.py index d235d75..6125f31 100644 --- a/Tests/features/steps/dependencies_steps.py +++ b/Tests/features/steps/dependencies_steps.py @@ -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): diff --git a/kss/license/entry_point.py b/kss/license/entry_point.py index 909e966..5d24172 100755 --- a/kss/license/entry_point.py +++ b/kss/license/entry_point.py @@ -3,6 +3,7 @@ """Scans a directory to determine the licenses of its dependancies.""" import argparse +import datetime import json import logging import os @@ -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. @@ -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)