Skip to content

Commit 997e981

Browse files
committed
Integrated the def get_dje_license_key() into the "pre_generation" function
1 parent 95d9c6a commit 997e981

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

about_code_tool/genabout.py

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,6 @@ def copy_license_files(self, gen_location, license_list):
208208
makedirs(license_parent_dir)
209209
shutil.copy2(license_path, output_license_path)
210210

211-
def get_dje_license_key(self, input_list):
212-
"""
213-
Get the DJE License Keys
214-
"""
215-
output_list = []
216-
for component in input_list:
217-
for line in component:
218-
try:
219-
if line['dje_license_key']:
220-
dje_license_key_list = []
221-
dje_key = line['dje_license_key']
222-
file_location = line['about_file']
223-
if file_location.endswith('/'):
224-
file_location = file_location.rpartition('/')[0]
225-
about_parent_dir = os.path.dirname(file_location)
226-
dje_license_key_list.append(about_parent_dir)
227-
dje_license_key_list.append(dje_key)
228-
output_list.append(dje_license_key_list)
229-
else:
230-
self.warnings.append(Warn('dje_license_key', '',
231-
"No 'dje_license_key' for " + line['about_file']))
232-
except Exception as e:
233-
print(repr(e))
234-
print("The input does not have the 'dje_license_key' key which is required.")
235-
sys.exit(errno.EINVAL)
236-
return output_list
237-
238211
def extract_dje_license(self, project_path, license_list, url, username, key):
239212
"""
240213
Extract license text from DJE
@@ -268,12 +241,13 @@ def get_license_text_from_api(url, username, api_key, license_key):
268241
license_text = data.get('full_text', '')
269242
return license_text
270243

271-
def pre_generation(self, gen_location, input_list, action_num, all_in_one):
244+
def pre_generation(self, gen_location, input_list, action_num, all_in_one, gen_license):
272245
"""
273246
check the existence of the output location and handle differently
274247
according to the action_num.
275248
"""
276249
output_list = []
250+
license_output_list = []
277251
# The input_list needs to be copied and be used below.
278252
# Otherwise, the value in the input_list may be changed based on the
279253
# action number below
@@ -318,7 +292,28 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
318292
component_list.append(about_file_location)
319293
component_list.append(line)
320294
output_list.append(component_list)
321-
return output_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+
316+
return output_list, license_output_list
322317

323318
@staticmethod
324319
def format_output(input_list):
@@ -594,19 +589,17 @@ def main(args, opts):
594589
license_list = gen.verify_license_files(input_list, project_path)
595590
gen.copy_license_files(gen_location, license_list)
596591

597-
components_list = gen.pre_generation(gen_location, input_list, opt_arg_num, all_in_one)
598-
formatted_output = gen.format_output(components_list)
599-
gen.write_output(formatted_output)
600-
601-
# Check do we have all the required arguments: api_url, api_username, api_key
602592
if gen_license:
603593
if not api_url or not api_username or not api_key:
604594
print("Missing argument for --extract_license")
605595
option_usage()
606596
sys.exit(errno.EINVAL)
607-
else:
608-
dje_license_list = gen.get_dje_license_key(input_list)
609-
gen.extract_dje_license(gen_location, dje_license_list, api_url, api_username, api_key)
597+
598+
components_list, dje_license_list = gen.pre_generation(gen_location, input_list, opt_arg_num, all_in_one, gen_license)
599+
formatted_output = gen.format_output(components_list)
600+
gen.write_output(formatted_output)
601+
if dje_license_list:
602+
gen.extract_dje_license(gen_location, dje_license_list, api_url, api_username, api_key)
610603

611604

612605
gen.warnings_errors_summary(gen_location, verb_arg_num)

0 commit comments

Comments
 (0)