Skip to content

Commit 4d441b9

Browse files
committed
Added a function to get the dje_license name from the provided dje_license_key, and then the tool will replace/create the 'dje_license' with the dje_license name
Note that this code is ugly. This is just a temp fix and it needs to be update/modifiy.
1 parent 0155acf commit 4d441b9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

about_code_tool/genabout.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ def get_license_text_from_api(self, url, username, api_key, license_key):
295295
license_text = data.get('full_text', '')
296296
return license_text
297297

298+
# This is a temp function. This should be merged with the get_license_text_from_api
299+
def get_license_name_from_api(self, url, username, api_key, license_key):
300+
"""
301+
Returns the license_text of a given license_key using an API request.
302+
Returns an empty string if the text is not available.
303+
"""
304+
data = self.request_license_data(url, username, api_key, license_key)
305+
license_name = data.get('name', '')
306+
return license_name
307+
298308
def get_dje_license_list(self, gen_location, input_list, gen_license):
299309
license_output_list = []
300310
for line in input_list:
@@ -327,9 +337,14 @@ def get_dje_license_list(self, gen_location, input_list, gen_license):
327337
"Missing 'dje_license_key' for " + line['about_file']))
328338
return license_output_list
329339

330-
def pre_generation(self, gen_location, input_list, action_num, all_in_one):
340+
def pre_generation(self, gen_location, input_list, action_num, all_in_one, api_url, api_username, api_key):
331341
output_list = []
332342
for line in input_list:
343+
try:
344+
if api_url and line['dje_license_key']:
345+
line['dje_license'] = self.get_license_name_from_api(api_url, api_username, api_key, line['dje_license_key'])
346+
except Exception as e:
347+
pass
333348
component_list = []
334349
file_location = line['about_file']
335350
if file_location.startswith('/'):
@@ -644,7 +659,7 @@ def main(parser, options, args):
644659
sys.exit(errno.EINVAL)
645660

646661
dje_license_list = gen.get_dje_license_list(output_path, input_list, gen_license)
647-
components_list = gen.pre_generation(output_path, input_list, action_num, all_in_one)
662+
components_list = gen.pre_generation(output_path, input_list, action_num, all_in_one, api_url, api_username, api_key)
648663
formatted_output = gen.format_output(components_list)
649664
gen.write_output(formatted_output)
650665

about_code_tool/templates/default.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ <h3 class="component-name">{{ about_object.name }}
5959
<pre class="component-notice">{{ notice_texts[loop.index0] }}</pre>
6060
{% endif %}
6161
{% if about_object.dje_license in license_keys %}
62+
<p>
63+
This component is licensed under {{ about_object.dje_license }}.
64+
</p>
6265
<p>Full text of
6366
<a class="{{ about_object.dje_license }}" href="#component-license-{{ about_object.dje_license }}">
6467
{{ about_object.dje_license }}

0 commit comments

Comments
 (0)