From a9289c8e14847aeccc6590a95fde54f668659b9a Mon Sep 17 00:00:00 2001 From: Ark74 Date: Sat, 21 Jun 2025 18:26:24 -0600 Subject: [PATCH] custom-plugins: add simple license extension to list custom licenses. --- custom-plugins/licenses_ext/__init__.py | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 custom-plugins/licenses_ext/__init__.py diff --git a/custom-plugins/licenses_ext/__init__.py b/custom-plugins/licenses_ext/__init__.py new file mode 100644 index 0000000..ee010d6 --- /dev/null +++ b/custom-plugins/licenses_ext/__init__.py @@ -0,0 +1,53 @@ +# mediagoblin/plugins/licenses_ext/__init__.py + +# Luis Guzman +# GNU AGPLv3 or later + +""" +MediaGoblin plugin: licenses_ext +Adds licenses defined on the configuration file. +""" + +from mediagoblin import mg_globals +from mediagoblin.tools import licenses +from mediagoblin.tools.licenses import License + +def setup_plugin(plugin_config=None): + # If plugin_config is empty, it is retrieved from mg_globals.global_config + if not plugin_config: + plugin_config = ( + mg_globals.global_config + .get('plugins', {}) + .get('mediagoblin.plugins.licenses_ext', {}) + ) + + for key, value in plugin_config.items(): + if not key.startswith("license_"): + continue + # If the value is a list (as in the global configuration) + if isinstance(value, list): + try: + abbrev, name, url = value + except Exception as e: + print("Error parsing (string) in", key, e) + continue + # If it happens to be a string, we split it + elif isinstance(value, str): + try: + abbrev, name, url = [x.strip() for x in value.split(",", 2)] + except Exception as e: + print("Error parsing (string) in", key, e) + continue + else: + print("Unknown type for", key, ":", type(value)) + continue + + new_license = License(abbrev, name, url) + licenses.SORTED_LICENSES.append(new_license) + licenses.SUPPORTED_LICENSES[new_license.uri] = new_license + +# Register the hook so that MediaGoblin calls setup_plugin() during the +# setup phase. +hooks = { + 'setup': setup_plugin, +}