From 1de22dbff43a3b08f704e4782b8321308b5e723d Mon Sep 17 00:00:00 2001 From: Keshav Agarwal <64908981+MasterK0927@users.noreply.github.com> Date: Sun, 7 Apr 2024 04:12:46 +0530 Subject: [PATCH] Update generate_licenses.py --- script/generate_licenses.py | 60 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/script/generate_licenses.py b/script/generate_licenses.py index 68c9d0cf50e2..c28e717aec19 100755 --- a/script/generate_licenses.py +++ b/script/generate_licenses.py @@ -161,36 +161,36 @@ def validated_data_field(data, field_name): return field_value -# def generate_backgrounds_license(preamble, backgrounds): -# notices = '' - -# for background in backgrounds: -# if notices: -# notices += '\n' - -# filename = validated_data_field(background, 'wallpaperImageUrl') -# author_name = validated_data_field(background, 'author') -# # Don't validate link. it can be empty. -# author_link = background['link'] -# original_url = validated_data_field(background, 'originalUrl') -# license_text = validated_data_field(background, 'license') -# if license_text != 'used with permission' \ -# and license_text[0:8] != 'https://' \ -# and license_text[0:7] != 'http://': -# print('Invalid license for background image ' \ -# f"{background['name']}. It needs to be a URL or the " \ -# 'string "used with permission".') -# sys.exit(1) - -# if author_link != '': -# notices += f'File: {filename}\nAuthor: {author_name} ' \ -# f'({author_link})\nURL: {original_url}\n' \ -# f'License: {license_text}\n' -# else: -# notices += f'File: {filename}\nAuthor: {author_name}\n' \ -# f'URL: {original_url}\nLicense: {license_text}\n' - -# return f'{preamble}\n\n{notices}' +def generate_backgrounds_license(preamble, backgrounds): + notices = '' + + for background in backgrounds: + if notices: + notices += '\n' + + filename = validated_data_field(background, 'wallpaperImageUrl') + author_name = validated_data_field(background, 'author') + # Don't validate link. it can be empty. + author_link = background['link'] + original_url = validated_data_field(background, 'originalUrl') + license_text = validated_data_field(background, 'license') + if license_text != 'used with permission' \ + and license_text[0:8] != 'https://' \ + and license_text[0:7] != 'http://': + print('Invalid license for background image ' \ + f"{background['name']}. It needs to be a URL or the " \ + 'string "used with permission".') + sys.exit(1) + + if author_link != '': + notices += f'File: {filename}\nAuthor: {author_name} ' \ + f'({author_link})\nURL: {original_url}\n' \ + f'License: {license_text}\n' + else: + notices += f'File: {filename}\nAuthor: {author_name}\n' \ + f'URL: {original_url}\nLicense: {license_text}\n' + + return f'{preamble}\n\n{notices}' def main():