Set license link from name

merge-requests/30/head
Bob Mottram 2022-12-27 21:30:20 +00:00
parent 800712134a
commit 1ea83254c5
3 changed files with 45 additions and 31 deletions

View File

@ -274,6 +274,7 @@ from languages import set_actor_languages
from languages import get_understood_languages
from like import update_likes_collection
from reaction import update_reaction_collection
from utils import license_link_from_name
from utils import acct_handle_dir
from utils import load_reverse_timeline
from utils import save_reverse_timeline
@ -6454,11 +6455,14 @@ class PubServer(BaseHTTPRequestHandler):
set_config_param(base_dir,
'libretranslateApiKey', '')
# change instance short description
# change instance content license
if fields.get('contentLicenseUrl'):
if fields['contentLicenseUrl'] != \
self.server.content_license_url:
license_str = fields['contentLicenseUrl']
if '://' not in license_str:
license_str = \
license_link_from_name(license_str)
set_config_param(base_dir,
'contentLicenseUrl',
license_str)

View File

@ -4172,3 +4172,41 @@ def is_quote_toot(post_json_object: str) -> bool:
continue
return True
return False
def license_link_from_name(license: str) -> str:
"""Returns the license link from its name
"""
if '://' in license:
return license
value_upper = license.upper()
if 'CC-BY-SA-NC' in value_upper or \
'CC-BY-NC-SA' in value_upper or \
'CC BY SA NC' in value_upper or \
'CC BY NC SA' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc-sa/4.0'
elif 'CC-BY-SA' in value_upper or 'CC-SA-BY' in value_upper or \
'CC BY SA' in value_upper or 'CC SA BY' in value_upper:
value = 'https://creativecommons.org/licenses/by-sa/4.0'
elif 'CC-BY-NC' in value_upper or 'CC BY NC' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc/4.0'
elif 'CC-BY-ND' in value_upper or 'CC BY ND' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc-nd/4.0'
elif 'CC-BY' in value_upper or 'CC BY' in value_upper:
value = 'https://creativecommons.org/licenses/by/4.0'
elif 'GFDL' in value_upper or 'GNU FREE DOC' in value_upper:
value = 'https://www.gnu.org/licenses/fdl-1.3.html'
elif 'OPL' in value_upper or 'OPEN PUBLICATION LIC' in value_upper:
value = 'https://opencontent.org/openpub'
elif 'PDL' in value_upper or \
'PUBLIC DOCUMENTATION LIC' in value_upper:
value = 'http://www.openoffice.org/licenses/PDL.html'
elif 'FREEBSD' in value_upper:
value = 'https://www.freebsd.org/copyright/freebsd-doc-license'
elif 'WTF' in value_upper:
value = 'http://www.wtfpl.net/txt/copying'
elif 'UNLICENSE' in value_upper:
value = 'https://unlicense.org'
else:
value = 'https://creativecommons.org/publicdomain/zero/1.0'
return value

View File

@ -26,6 +26,7 @@ from posts import post_is_muted
from posts import get_person_box
from posts import download_announce
from posts import populate_replies_json
from utils import license_link_from_name
from utils import dont_speak_hashtags
from utils import remove_eol
from utils import disallow_announce
@ -1725,36 +1726,7 @@ def _get_content_license(post_json_object: {}) -> str:
continue
value = item['value']
if '://' not in value:
value_upper = value.upper()
if 'CC-BY-SA-NC' in value_upper or \
'CC-BY-NC-SA' in value_upper or \
'CC BY SA NC' in value_upper or \
'CC BY NC SA' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc-sa/4.0'
elif 'CC-BY-SA' in value_upper or 'CC-SA-BY' in value_upper or \
'CC BY SA' in value_upper or 'CC SA BY' in value_upper:
value = 'https://creativecommons.org/licenses/by-sa/4.0'
elif 'CC-BY-NC' in value_upper or 'CC BY NC' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc/4.0'
elif 'CC-BY-ND' in value_upper or 'CC BY ND' in value_upper:
value = 'https://creativecommons.org/licenses/by-nc-nd/4.0'
elif 'CC-BY' in value_upper or 'CC BY' in value_upper:
value = 'https://creativecommons.org/licenses/by/4.0'
elif 'GFDL' in value_upper or 'GNU FREE DOC' in value_upper:
value = 'https://www.gnu.org/licenses/fdl-1.3.html'
elif 'OPL' in value_upper or 'OPEN PUBLICATION LIC' in value_upper:
value = 'https://opencontent.org/openpub'
elif 'PDL' in value_upper or \
'PUBLIC DOCUMENTATION LIC' in value_upper:
value = 'http://www.openoffice.org/licenses/PDL.html'
elif 'FREEBSD' in value_upper:
value = 'https://www.freebsd.org/copyright/freebsd-doc-license'
elif 'WTF' in value_upper:
value = 'http://www.wtfpl.net/txt/copying'
elif 'UNLICENSE' in value_upper:
value = 'https://unlicense.org'
else:
value = 'https://creativecommons.org/publicdomain/zero/1.0'
value = license_link_from_name(value)
return value
return None