Skip to content

Commit 1e6875f

Browse files
committed
Update code to remove the requirement of having the 3rd argument
(component_list) in the genattrib.py if users want to generate the output for ALL the ABOUT files in the input.
1 parent f94fe7a commit 1e6875f

File tree

2 files changed

+90
-46
lines changed

2 files changed

+90
-46
lines changed

about_code_tool/about.py

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,49 +1270,81 @@ def generate_attribution(self, template_path=None, limit_to=None):
12701270
not_process_components = list(limit_to)
12711271
component_exist = False
12721272

1273-
for component in not_process_components:
1273+
# Following code contains duplication and perhaps needs to do some
1274+
# refactoring
1275+
if limit_to:
1276+
for component in not_process_components:
1277+
for about_object in self:
1278+
# The about_object.location is the absolute path of the ABOUT
1279+
# file. The purpose of the following partition is to match
1280+
# the about_file's location with the input list.
1281+
about_relative_path = about_object.location.partition(
1282+
normpath(self.location))[2]
1283+
1284+
if component == about_relative_path:
1285+
component_exist = True
1286+
about_content = about_object.validated_fields
1287+
if '\n' in about_object.get_dje_license_name():
1288+
msg = ('Multiple licenses is not supported. '
1289+
'Skipping License generation.')
1290+
err = Error(GENATTRIB, 'dje_license',
1291+
about_object.get_dje_license_name(), msg)
1292+
self.genattrib_errors.append(err)
1293+
1294+
lic_text = unicode(about_object.license_text(),
1295+
errors='replace')
1296+
notice_text = unicode(about_object.notice_text(),
1297+
errors='replace')
1298+
about_content['license_text'] = lic_text
1299+
about_content['notice_text'] = notice_text
1300+
1301+
license_dict[about_object.get_dje_license_name()] = about_content['license_text']
1302+
1303+
# report error if no license_text is found
1304+
if not about_content.get('license_text')\
1305+
and not about_content.get('notice_text')\
1306+
and not '\n' in about_object.get_dje_license_name():
1307+
msg = ('No license_text found. '
1308+
'Skipping License generation.')
1309+
err = Error(GENATTRIB, 'name',
1310+
about_object.get_about_name(), msg)
1311+
self.genattrib_errors.append(err)
1312+
about_object_fields.append(about_content)
1313+
break
1314+
if not component_exist:
1315+
msg = ('The requested ABOUT file: %r does not exist. '
1316+
'No attribution generated for this file.' % component)
1317+
err = Error(GENATTRIB, 'about_file', component, msg)
1318+
self.genattrib_errors.append(err)
1319+
else:
12741320
for about_object in self:
1275-
# The about_object.location is the absolute path of the ABOUT
1276-
# file. The purpose of the following partition is to match
1277-
# the about_file's location with the input list.
1278-
about_relative_path = about_object.location.partition(
1279-
normpath(self.location))[2]
1280-
1281-
if component == about_relative_path:
1282-
component_exist = True
1283-
about_content = about_object.validated_fields
1284-
if '\n' in about_object.get_dje_license_name():
1285-
msg = ('Multiple licenses is not supported. '
1286-
'Skipping License generation.')
1287-
err = Error(GENATTRIB, 'dje_license',
1288-
about_object.get_dje_license_name(), msg)
1289-
self.genattrib_errors.append(err)
1290-
1291-
lic_text = unicode(about_object.license_text(),
1292-
errors='replace')
1293-
notice_text = unicode(about_object.notice_text(),
1294-
errors='replace')
1295-
about_content['license_text'] = lic_text
1296-
about_content['notice_text'] = notice_text
1297-
1298-
license_dict[about_object.get_dje_license_name()] = about_content['license_text']
1299-
1300-
# report error if no license_text is found
1301-
if not about_content.get('license_text')\
1302-
and not about_content.get('notice_text')\
1303-
and not '\n' in about_object.get_dje_license_name():
1304-
msg = ('No license_text found. '
1305-
'Skipping License generation.')
1306-
err = Error(GENATTRIB, 'name',
1307-
about_object.get_about_name(), msg)
1308-
self.genattrib_errors.append(err)
1309-
about_object_fields.append(about_content)
1310-
break
1311-
if not component_exist:
1312-
msg = ('The requested ABOUT file: %r does not exist. '
1313-
'No attribution generated for this file.' % component)
1314-
err = Error(GENATTRIB, 'about_file', component, msg)
1315-
self.genattrib_errors.append(err)
1321+
about_content = about_object.validated_fields
1322+
if '\n' in about_object.get_dje_license_name():
1323+
msg = ('Multiple licenses is not supported. '
1324+
'Skipping License generation.')
1325+
err = Error(GENATTRIB, 'dje_license',
1326+
about_object.get_dje_license_name(), msg)
1327+
self.genattrib_errors.append(err)
1328+
1329+
lic_text = unicode(about_object.license_text(),
1330+
errors='replace')
1331+
notice_text = unicode(about_object.notice_text(),
1332+
errors='replace')
1333+
about_content['license_text'] = lic_text
1334+
about_content['notice_text'] = notice_text
1335+
1336+
license_dict[about_object.get_dje_license_name()] = about_content['license_text']
1337+
1338+
# report error if no license_text is found
1339+
if not about_content.get('license_text')\
1340+
and not about_content.get('notice_text')\
1341+
and not '\n' in about_object.get_dje_license_name():
1342+
msg = ('No license_text found. '
1343+
'Skipping License generation.')
1344+
err = Error(GENATTRIB, 'name',
1345+
about_object.get_about_name(), msg)
1346+
self.genattrib_errors.append(err)
1347+
about_object_fields.append(about_content)
13161348

13171349
# We want to display common_licenses in alphabetical order
13181350
license_key = []

about_code_tool/genattrib.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ def main(parser, options, args):
149149
print("The file 'MAPPING.CONFIG' does not exist.")
150150
sys.exit(errno.EINVAL)
151151

152-
if not len(args) == 3:
153-
print('Path for input, output and component list are required.\n')
152+
if not len(args) >= 2 and not len(args) < 4:
153+
print('Path for input and output are required.\n')
154154
parser.print_help()
155155
sys.exit(errno.EEXIST)
156156

157-
input_path, output_path, component_subset_path = args
157+
input_path = args[0]
158+
output_path = args[1]
159+
if len(args) == 3:
160+
component_subset_path = args[2]
161+
else:
162+
component_subset_path = ""
158163

159164
# TODO: need more path normalization (normpath, expanduser)
160165
input_path = expanduser(normpath(input_path))
@@ -172,10 +177,16 @@ def main(parser, options, args):
172177
sys.exit(errno.EEXIST)
173178

174179
if isdir(output_path):
175-
print('Output must be a file, not a directory.')
180+
print('Output must be a HTML file.')
176181
parser.print_help()
177182
sys.exit(errno.EISDIR)
178183

184+
# We only support HTML currently
185+
if not output_path.endswith('.html'):
186+
print('Output must be a HTML file.')
187+
parser.print_help()
188+
sys.exit(errno.EINVAL)
189+
179190
if exists(output_path) and not overwrite:
180191
print('Output file already exists. Select a different file name '
181192
'or use the --overwrite option.')
@@ -196,6 +207,7 @@ def main(parser, options, args):
196207

197208
if not exists(output_path) or (exists(output_path) and overwrite):
198209
collector = Collector(input_path)
210+
outlist = None
199211
if not component_subset_path:
200212
sublist = None
201213
else:

0 commit comments

Comments
 (0)