Skip to content

Commit 0746878

Browse files
committed
Fixed #64
Update the 'Location of License Text' value based on the generated .LICENSE location from the '--extract_license' in the ABOUT file if none is set. Otherwise, it'll keep the original value. In addition, if the provided csv doesn't have the key 'Location of License Text', it will now be created.
1 parent 997e981 commit 0746878

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

about_code_tool/genabout.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,33 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one, gen_l
254254
copied_list = copy.deepcopy(input_list)
255255
for component in copied_list:
256256
for line in component:
257+
if gen_license:
258+
try:
259+
if line['dje_license_key']:
260+
dje_license_key_list = []
261+
dje_key = line['dje_license_key']
262+
file_location = line['about_file']
263+
if file_location.endswith('/'):
264+
file_location = file_location.rpartition('/')[0]
265+
about_parent_dir = os.path.dirname(file_location)
266+
dje_license_key_list.append(about_parent_dir)
267+
dje_license_key_list.append(dje_key)
268+
license_output_list.append(dje_license_key_list)
269+
# Update the Location of License Text is there is none
270+
try:
271+
if not line['Location of License Text']:
272+
line['Location of License Text'] = dje_key +'.LICENSE'
273+
except Exception as e:
274+
# Force to create the "Location of License Text field"
275+
line['Location of License Text'] = dje_key +'.LICENSE'
276+
else:
277+
self.warnings.append(Warn('dje_license_key', '',
278+
"Missing 'dje_license_key' for " + line['about_file']))
279+
except Exception as e:
280+
print(repr(e))
281+
print("The input does not have the 'dje_license_key' key which is required.")
282+
sys.exit(errno.EINVAL)
283+
257284
component_list = []
258285
file_location = line['about_file']
259286
if file_location.startswith('/'):
@@ -292,27 +319,6 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one, gen_l
292319
component_list.append(about_file_location)
293320
component_list.append(line)
294321
output_list.append(component_list)
295-
296-
if gen_license:
297-
try:
298-
if line['dje_license_key']:
299-
dje_license_key_list = []
300-
dje_key = line['dje_license_key']
301-
file_location = line['about_file']
302-
if file_location.endswith('/'):
303-
file_location = file_location.rpartition('/')[0]
304-
about_parent_dir = os.path.dirname(file_location)
305-
dje_license_key_list.append(about_parent_dir)
306-
dje_license_key_list.append(dje_key)
307-
license_output_list.append(dje_license_key_list)
308-
else:
309-
self.warnings.append(Warn('dje_license_key', '',
310-
"Missing 'dje_license_key' for " + line['about_file']))
311-
except Exception as e:
312-
print(repr(e))
313-
print("The input does not have the 'dje_license_key' key which is required.")
314-
sys.exit(errno.EINVAL)
315-
316322
return output_list, license_output_list
317323

318324
@staticmethod
@@ -598,10 +604,10 @@ def main(args, opts):
598604
components_list, dje_license_list = gen.pre_generation(gen_location, input_list, opt_arg_num, all_in_one, gen_license)
599605
formatted_output = gen.format_output(components_list)
600606
gen.write_output(formatted_output)
607+
601608
if dje_license_list:
602609
gen.extract_dje_license(gen_location, dje_license_list, api_url, api_username, api_key)
603610

604-
605611
gen.warnings_errors_summary(gen_location, verb_arg_num)
606612

607613
if __name__ == "__main__":

0 commit comments

Comments
 (0)