Compare commits
2 commits
2bb1ad1f5f
...
c50fa4f36a
| Author | SHA1 | Date | |
|---|---|---|---|
| c50fa4f36a | |||
|
|
a9289c8e14 |
1 changed files with 53 additions and 0 deletions
53
custom-plugins/licenses_ext/__init__.py
Normal file
53
custom-plugins/licenses_ext/__init__.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
# mediagoblin/plugins/licenses_ext/__init__.py
|
||||||
|
|
||||||
|
# Luis Guzman <ark@switnet.org>
|
||||||
|
# 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,
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue