diff --git a/about_code_tool/attrib.py b/about_code_tool/attrib.py index 891d4afc..c48c089e 100644 --- a/about_code_tool/attrib.py +++ b/about_code_tool/attrib.py @@ -25,6 +25,7 @@ from about_code_tool import ERROR from about_code_tool import Error from licenses import COMMON_LICENSES +from util import get_mappings def generate(abouts, template_string=None): @@ -91,7 +92,7 @@ def generate_from_file(abouts, template_loc=None): return generate(abouts, template_string=tpls) -def generate_and_save(abouts, output_location, template_loc=None, +def generate_and_save(abouts, output_location, mapping, template_loc=None, inventory_location=None): """ Generate attribution using template and save at output_location. @@ -107,8 +108,22 @@ def generate_and_save(abouts, output_location, template_loc=None, with open(inventory_location, 'rU') as inp: reader = csv.DictReader(inp) about_data = [data for data in reader] + map_key = 'about_file_path' + + if mapping: + mapping = get_mappings() + if 'about_file_path' in mapping: + map_key = mapping['about_file_path'] + for data in about_data: - afp = data['about_file_path'] + try: + afp = data[map_key] + except Exception, e: + # 'about_file_path' key/column doesn't exist + msg = (u'The required key: \'about_file_path\' does not exist. Generation halted.') + errors.append(Error(ERROR, msg)) + return errors + if afp.startswith('/'): afp = afp.partition('/')[2] filter_afp.append(afp) diff --git a/about_code_tool/cmd.py b/about_code_tool/cmd.py index 235850f5..d051221a 100644 --- a/about_code_tool/cmd.py +++ b/about_code_tool/cmd.py @@ -237,7 +237,8 @@ def fetch(location): dir_okay=False, resolve_path=True)) @click.option('--template', type=click.Path(exists=True), nargs=1, help='Use the custom template for the Attribution Generation') -def attrib(location, output, template, inventory_location=None,): +@click.option('--mapping', is_flag=True, help='Configure the mapping key from the MAPPING.CONFIG') +def attrib(location, output, template, mapping, inventory_location=None,): """ Generate attribution document at output using the directory of ABOUT files at location, the template file (or a default) and an @@ -252,8 +253,8 @@ def attrib(location, output, template, inventory_location=None,): location = extract_zip(location) errors, abouts = about_code_tool.model.collect_inventory(location) - no_match_errors = about_code_tool.attrib.generate_and_save(abouts, output, - template_loc=template, + no_match_errors = about_code_tool.attrib.generate_and_save(abouts, output, mapping, + template_loc=template, inventory_location=inventory_location) log_errors(no_match_errors, os.path.dirname(output))