# 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, }