b19b16df2679d911e08270f4ce61e027412ce654
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/>.
24 from configobj
import ConfigObj
27 BUILTIN_THEME_DIR
= pkg_resources
.resource_filename('mediagoblin', 'themes')
30 def themedata_for_theme_dir(name
, theme_dir
):
32 Given a theme directory, extract important theme information.
35 config
= ConfigObj(os
.path
.join(theme_dir
, 'theme.ini'))
37 templates_dir
= os
.path
.join(theme_dir
, 'templates')
38 if not os
.path
.exists(templates_dir
):
41 assets_dir
= os
.path
.join(theme_dir
, 'assets')
42 if not os
.path
.exists(assets_dir
):
46 'name': config
.get('name', name
),
47 'description': config
.get('description'),
49 'templates_dir': templates_dir
,
50 'assets_dir': assets_dir
,
56 def register_themes(app_config
, builtin_dir
=BUILTIN_THEME_DIR
):
58 Register all themes relevant to this application.
62 def _install_themes_in_dir(directory
):
63 for themedir
in os
.listdir(directory
):
64 abs_themedir
= os
.path
.join(directory
, themedir
)
65 if not os
.path
.isdir(abs_themedir
):
68 themedata
= themedata_for_theme_dir(themedir
, abs_themedir
)
69 registry
[themedir
] = themedata
72 if os
.path
.exists(builtin_dir
):
73 _install_themes_in_dir(builtin_dir
)
76 theme_install_dir
= app_config
.get('theme_install_dir')
77 if theme_install_dir
and os
.path
.exists(theme_install_dir
):
78 _install_themes_in_dir(theme_install_dir
)
80 current_theme_name
= app_config
.get('theme')
81 if current_theme_name \
82 and registry
.has_key(current_theme_name
):
83 current_theme
= registry
[current_theme_name
]
87 return registry
, current_theme