Skip to content

Commit 2cff1ee

Browse files
committed
genattrib.py
- Add '--mapping' option for genattrib.py - Use the about file's path as the sublist filter instead of the component name about.py - Change the 'about_resource_path' to 'about_resource' as it is not a path value
1 parent 7cdfa97 commit 2cff1ee

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

about_code_tool/about.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class AboutFile(object):
445445
Represent an ABOUT file and functions to parse and validate a file.
446446
"""
447447
def __init__(self, location=None):
448-
self.about_resource_path = None
448+
self.about_resource = None
449449
self.location = location
450450

451451
self.parsed = None
@@ -684,14 +684,14 @@ def validate_about_resource_exist(self):
684684
# in validate_mandatory_fields_are_present(self)
685685
if about_resource in self.validated_fields \
686686
and self.validated_fields[about_resource]:
687-
self.about_resource_path = self.validated_fields[about_resource]
687+
self.about_resource = self.validated_fields[about_resource]
688688

689-
if not self._exists(self.about_resource_path):
689+
if not self._exists(self.about_resource):
690690
self.errors.append(Error(FILE, about_resource,
691-
self.about_resource_path,
691+
self.about_resource,
692692
'File does not exist.'))
693693

694-
self._save_location(about_resource, self.about_resource_path)
694+
self._save_location(about_resource, self.about_resource)
695695

696696
def validate_file_field_exists(self, field_name, file_path):
697697
"""
@@ -1098,7 +1098,8 @@ def generate_attribution(self, template_path='templates/default.html',
10981098
license_text = []
10991099
license_dict = {}
11001100
for about_object in self:
1101-
if not limit_to or about_object.about_resource_path in limit_to:
1101+
about_relative_path = '/'+ about_object.location.partition(self.user_provided_path)[2]
1102+
if not limit_to or about_relative_path in limit_to:
11021103
validated_fields.append(about_object.validated_fields)
11031104
notice_text.append(about_object.notice_text())
11041105
dje_license_name = about_object.get_dje_license_name()
@@ -1110,7 +1111,7 @@ def generate_attribution(self, template_path='templates/default.html',
11101111
else:
11111112
msg = 'About resource: %s - license_text does not exist.'\
11121113
' License generation is skipped.'\
1113-
% about_object.about_resource_path
1114+
% about_object.about_resource
11141115
self.genattrib_errors.append(Error(GENATTRIB,\
11151116
'dje_license',\
11161117
dje_license_name, msg))
@@ -1121,14 +1122,14 @@ def generate_attribution(self, template_path='templates/default.html',
11211122
else:
11221123
msg = 'About resource: %s - license_text does not exist.'\
11231124
' License generation is skipped.'\
1124-
% about_object.about_resource_path
1125+
% about_object.about_resource
11251126
self.genattrib_errors.append(Error(GENATTRIB,\
11261127
'license_text',\
11271128
about_object.get_license_text_file_name(), msg))
11281129
else:
11291130
msg = 'No dje_license or license_text is found. License generation is skipped.'
11301131
self.genattrib_errors.append(Error(GENATTRIB, 'about_resource',\
1131-
about_object.about_resource_path,\
1132+
about_object.about_resource,\
11321133
msg))
11331134

11341135
# We want the license generation in alphabetical order

about_code_tool/genattrib.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from __future__ import print_function
1111
from __future__ import with_statement
1212
from about import AboutCollector
13+
import genabout
1314

1415
import codecs
1516
import csv
@@ -61,15 +62,20 @@
6162
limitations under the License.
6263
"""
6364

64-
def component_subset_to_sublist(input_path):
65+
def component_subset_to_sublist(input_list):
6566
sublist = []
66-
with open(input_path, "rU") as f:
67-
csv_dict = csv.DictReader(f)
68-
sublist = [row["about_resource"] for row in csv_dict
69-
if "about_resource" in row.keys()]
70-
67+
sublist = [row["about_file"] for row in input_list
68+
if "about_file" in row.keys()]
7169
return sublist
7270

71+
def update_path_to_about(input_list):
72+
output_list = []
73+
for row in input_list:
74+
if row.endswith('/'):
75+
row = row.rpartition('/')[0]
76+
output_list.append(row + '.ABOUT')
77+
return output_list
78+
7379
USAGE_SYNTAX = """\
7480
Input can be a file or directory.
7581
Output of rendered template must be a file (e.g. .html).
@@ -83,10 +89,14 @@ def component_subset_to_sublist(input_path):
8389
2 - Print error and warning messages
8490
"""
8591

92+
MAPPING_HELP = """\
93+
Configure the mapping key from the MAPPING.CONFIG
94+
"""
8695

8796
def main(parser, options, args):
8897
overwrite = options.overwrite
8998
verbosity = options.verbosity
99+
mapping_config = options.mapping
90100

91101
if options.version:
92102
print('ABOUT tool {0}\n{1}'.format(__version__, __copyright__))
@@ -97,6 +107,11 @@ def main(parser, options, args):
97107
elif verbosity >= 2:
98108
handler.setLevel(logging.WARNING)
99109

110+
if mapping_config:
111+
if not exists('MAPPING.CONFIG'):
112+
print("The file 'MAPPING.CONFIG' doesn't exist.")
113+
sys.exit(errno.EINVAL)
114+
100115
if not len(args) == 3:
101116
print('Path for input, output and component list are required.\n')
102117
parser.print_help()
@@ -136,8 +151,21 @@ def main(parser, options, args):
136151

137152
if not exists(output_path) or (exists(output_path) and overwrite):
138153
collector = AboutCollector(input_path)
139-
sublist = None if not component_subset_path else component_subset_to_sublist(component_subset_path)
140-
attrib_str = collector.generate_attribution( limit_to = sublist )
154+
input_list = []
155+
if not component_subset_path:
156+
sublist = None
157+
else:
158+
with open(component_subset_path, "rU") as f:
159+
input_dict = csv.DictReader(f)
160+
for row in input_dict:
161+
input_list.append(row)
162+
if mapping_config:
163+
mapping_list = genabout.GenAbout().get_mapping_list()
164+
input_list = genabout.GenAbout().convert_input_list(input_list, mapping_list)
165+
sublist = component_subset_to_sublist(input_list)
166+
outlist = update_path_to_about(sublist)
167+
168+
attrib_str = collector.generate_attribution( limit_to = outlist )
141169
with open(output_path, "w") as f:
142170
f.write(attrib_str)
143171
errors = collector.get_genattrib_errors()
@@ -201,6 +229,7 @@ def format_option(self, option):
201229
parser.add_option('--overwrite', action='store_true',
202230
help='Overwrites the output file if it exists')
203231
parser.add_option('--verbosity', type=int, help=VERBOSITY_HELP)
232+
parser.add_option('--mapping', action='store_true', help=MAPPING_HELP)
204233
return parser
205234

206235

about_code_tool/tests/test_about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_normalize_lowercase(self):
320320

321321
def test_validate_about_ref_testing_the_about_resource_field_is_present(self):
322322
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_resource_field_present.ABOUT'))
323-
self.assertEquals(about_file.about_resource_path, 'about_resource.c', 'the about_resource was not detected')
323+
self.assertEquals(about_file.about_resource, 'about_resource.c', 'the about_resource was not detected')
324324

325325
def test_validate_about_ref_no_about_ref_key(self):
326326
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/.ABOUT'))

0 commit comments

Comments
 (0)