Making the register_themes() tool also return the current theme
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 13 Jul 2012 17:33:52 +0000 (12:33 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sat, 14 Jul 2012 17:55:14 +0000 (12:55 -0500)
This will reduce the amount of work reproducing this behavior when
pulling together the theme registry elsewhere.

mediagoblin/app.py
mediagoblin/tools/theme.py

index a10edfaabcf1a45886ddbbc552d52c65950d82fc..dfc715b9d49e96549ca5f332d85b16b24c1c04b0 100644 (file)
@@ -75,13 +75,7 @@ class MediaGoblinApp(object):
         self.connection, self.db = setup_database()
 
         # Register themes
-        self.theme_registry = register_themes(app_config)
-        self.current_theme_name = app_config.get('theme')
-        if self.current_theme_name \
-                and self.theme_registry.has_key(self.current_theme_name):
-            self.current_theme = self.theme_registry[self.current_theme_name]
-        else:
-            self.current_theme = None
+        self.theme_registry, self.current_theme = register_themes(app_config)
 
         # Get the template environment
         self.template_loader = get_jinja_loader(
index dc83e0ff657720e60af127b5018d0c1aa8e1b622..b19b16df2679d911e08270f4ce61e027412ce654 100644 (file)
@@ -69,11 +69,20 @@ def register_themes(app_config, builtin_dir=BUILTIN_THEME_DIR):
             registry[themedir] = themedata
         
     # Built-in themes
-    _install_themes_in_dir(builtin_dir)
+    if os.path.exists(builtin_dir):
+        _install_themes_in_dir(builtin_dir)
 
     # Installed themes
     theme_install_dir = app_config.get('theme_install_dir')
     if theme_install_dir and os.path.exists(theme_install_dir):
         _install_themes_in_dir(theme_install_dir)
 
-    return registry
+    current_theme_name = app_config.get('theme')
+    if current_theme_name \
+            and registry.has_key(current_theme_name):
+        current_theme = registry[current_theme_name]
+    else:
+        current_theme = None
+
+    return registry, current_theme
+