Skip to content

Commit 78b9ac8

Browse files
committed
Implement the "extract_license" from DJE feature.
This will now extract the license from DJE License Library based on the 'dje_license_key' and create a <dje_license_key>.LICENSE side by side with the .ABOUT file
1 parent 641996c commit 78b9ac8

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

about_code_tool/genabout.py

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def verify_license_files(self, input_list, project_path):
194194

195195
def copy_license_files(self, gen_location, license_list):
196196
"""
197-
copy the 'license_text_file' into the gen_location
197+
Copy the 'license_text_file' into the gen_location
198198
"""
199199
for items in license_list:
200200
license_path = items[0]
@@ -206,6 +206,44 @@ def copy_license_files(self, gen_location, license_list):
206206
makedirs(license_parent_dir)
207207
shutil.copy2(license_path, output_license_path)
208208

209+
def get_dje_license_key(self, input_list):
210+
"""
211+
Get the DJE License Keys
212+
"""
213+
output_list = []
214+
for component in input_list:
215+
for line in component:
216+
try:
217+
if line['dje_license_key']:
218+
dje_license_key_list = []
219+
dje_key = line['dje_license_key']
220+
file_location = line['about_file']
221+
if file_location.endswith('/'):
222+
file_location = file_location.rpartition('/')[0]
223+
about_parent_dir = os.path.dirname(file_location)
224+
dje_license_key_list.append(about_parent_dir)
225+
dje_license_key_list.append(dje_key)
226+
output_list.append(dje_license_key_list)
227+
except Exception as e:
228+
print(repr(e))
229+
print("The input does not have the 'dje_license_key' key which is required.")
230+
sys.exit(errno.EINVAL)
231+
return output_list
232+
233+
def extract_dje_license(self, project_path, license_list, url, username, key):
234+
"""
235+
Extract license text from DJE
236+
"""
237+
for items in license_list:
238+
gen_path = items[0]
239+
license_key = items[1]
240+
if '/' in gen_path:
241+
gen_path = gen_path.partition('/')[2]
242+
gen_license_path = join(project_path, gen_path, license_key) + '.LICENSE'
243+
context = self.get_license_text_from_api(url, username, key, license_key)
244+
with open(gen_license_path, 'wb') as output:
245+
output.write(context)
246+
209247
@staticmethod
210248
def get_license_text_from_api(url, username, api_key, license_key):
211249
"""
@@ -509,13 +547,6 @@ def main(args, opts):
509547

510548
if invalid_opt:
511549
assert False, 'Unsupported option.'
512-
513-
# Check do we have all the required arguments: api_url, api_username, api_key
514-
if gen_license:
515-
if not api_url or not api_username or not api_key:
516-
print("Missing argument for --extract_license")
517-
option_usage()
518-
sys.exit(errno.EINVAL)
519550

520551
if not len(args) == 2:
521552
print('Input file and generated location parameters are mandatory.')
@@ -548,6 +579,18 @@ def main(args, opts):
548579
components_list = gen.pre_generation(gen_location, input_list, opt_arg_num, all_in_one)
549580
formatted_output = gen.format_output(components_list)
550581
gen.write_output(formatted_output)
582+
583+
# Check do we have all the required arguments: api_url, api_username, api_key
584+
if gen_license:
585+
if not api_url or not api_username or not api_key:
586+
print("Missing argument for --extract_license")
587+
option_usage()
588+
sys.exit(errno.EINVAL)
589+
else:
590+
dje_license_list = gen.get_dje_license_key(input_list)
591+
gen.extract_dje_license(gen_location, dje_license_list, api_url, api_username, api_key)
592+
593+
551594
gen.warnings_errors_summary(gen_location, verb_arg_num)
552595

553596
if __name__ == "__main__":

0 commit comments

Comments
 (0)