1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 from __future__
import unicode_literals
19 from mediagoblin
.tools
.pluginapi
import get_config
20 from mediagoblin
.tools
import licenses
22 __VERSION__
= '0.1.2' # releases get numbers, post release a "+" appended
23 _log
= logging
.getLogger(__name__
)
25 SORTED_PLUGIN_LICENSES
= []
26 """This is the equivalent of MG.tools.licenses.SORTED_LICENSES
27 that we want to replace"""
30 class CustomLicenses(object):
31 _setup_plugin_called
= 0
34 def setup_plugin(cls
):
35 if cls
._setup
_plugin
_called
:
36 return # Only set up once
37 cls
._setup
_plugin
_called
+= 1
38 _log
.info('Configurable license plugin setting up!')
39 # Get configured licenses
40 config
= get_config(cls
.__module
__)
42 _log
.warn('There are no licenses configured at all.')
43 return # Nothing configured, nothing to do...
45 for k
,v
in config
.iteritems():
46 if not k
.lower().startswith('license_'):
48 (abbrev
, name
, url
) = config
.as_list(k
)
49 _log
.info("Adding license: {0}".format(abbrev
))
50 SORTED_PLUGIN_LICENSES
.append(licenses
.License(abbrev
, name
, url
))
52 # Set the regular license list to our custom ones:
53 licenses
.SORTED_LICENSES
= SORTED_PLUGIN_LICENSES
54 # create dict {url: License,...} to enable fast license lookup by url.
56 # The data structure in
57 # mediagoblin.tools.licenses.SUPPORTED_LICENSES and SORTED_LICENSES
58 # is really not optimal. What we want there is a "OrderedDict" that
59 # can give us order AND quick lookup by key at the same time. But as
60 # that is python >=2.7 and we have to deal with python 2.6, we'll
61 # live with the data duplication in 2 structures for now. It's not
62 # like we are going to have hundreds of licenses, fortunately.
63 licenses
.SUPPORTED_LICENSES
= dict(((l
.uri
, l
) for l
in \
64 SORTED_PLUGIN_LICENSES
))
68 'setup': CustomLicenses
.setup_plugin