From a8b5923026a0d3ebdae0949b00663e13a48684bd Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 30 Jan 2015 15:54:02 -0500 Subject: [PATCH] Reduce config duplication related to setting up webapps. And apply some fixes/improvements for galaxy back into tool shed and reports. --- config/reports_wsgi.ini.sample | 14 +++++++------- lib/galaxy/web/framework/webapp.py | 23 +++++++++++++++++++++++ lib/galaxy/webapps/galaxy/buildapp.py | 20 +------------------- lib/galaxy/webapps/reports/buildapp.py | 22 ++-------------------- lib/galaxy/webapps/tool_shed/buildapp.py | 23 ++--------------------- 5 files changed, 35 insertions(+), 67 deletions(-) diff --git a/config/reports_wsgi.ini.sample b/config/reports_wsgi.ini.sample index eac6682d04b..2190353b1cc 100644 --- a/config/reports_wsgi.ini.sample +++ b/config/reports_wsgi.ini.sample @@ -64,10 +64,10 @@ mailing_join_addr = galaxy-user-join@bx.psu.edu use_new_layout = true # Serving static files (needed if running standalone) -static_enabled = True -static_cache_time = 360 -static_dir = %(here)s/static/ -static_images_dir = %(here)s/static/images -static_favicon_dir = %(here)s/static/favicon.ico -static_scripts_dir = %(here)s/static/scripts/ -static_style_dir = %(here)s/static/june_2007_style/blue +# static_enabled = True +# static_cache_time = 360 +# static_dir = %(here)s/static/ +# static_images_dir = %(here)s/static/images +# static_favicon_dir = %(here)s/static/favicon.ico +# static_scripts_dir = %(here)s/static/scripts/ +# static_style_dir = %(here)s/static/june_2007_style/blue diff --git a/lib/galaxy/web/framework/webapp.py b/lib/galaxy/web/framework/webapp.py index 8d96f344ae2..1688f09ab40 100644 --- a/lib/galaxy/web/framework/webapp.py +++ b/lib/galaxy/web/framework/webapp.py @@ -814,3 +814,26 @@ class GalaxyWebTransaction( base.DefaultWebTransaction, template = Template( source=template_string, searchList=[context or kwargs, dict(caller=self)] ) return str(template) + + +def build_url_map( app, global_conf, local_conf ): + from paste.urlmap import URLMap + from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static + urlmap = URLMap() + # Merge the global and local configurations + conf = global_conf.copy() + conf.update(local_conf) + # Get cache time in seconds + cache_time = conf.get( "static_cache_time", None ) + if cache_time is not None: + cache_time = int( cache_time ) + # Send to dynamic app by default + urlmap["/"] = app + # Define static mappings from config + urlmap["/static"] = Static( conf.get( "static_dir", "./static/" ), cache_time ) + urlmap["/images"] = Static( conf.get( "static_images_dir", "./static/images" ), cache_time ) + urlmap["/static/scripts"] = Static( conf.get( "static_scripts_dir", "./static/scripts/" ), cache_time ) + urlmap["/static/style"] = Static( conf.get( "static_style_dir", "./static/style/blue" ), cache_time ) + urlmap["/favicon.ico"] = Static( conf.get( "static_favicon_dir", "./static/favicon.ico" ), cache_time ) + urlmap["/robots.txt"] = Static( conf.get( "static_robots_txt", "./static/robots.txt" ), cache_time ) + return urlmap, cache_time diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index f286cbd69b7..b7fd25ee859 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -610,26 +610,8 @@ def wrap_in_middleware( app, global_conf, **local_conf ): return app def wrap_in_static( app, global_conf, plugin_frameworks=None, **local_conf ): - from paste.urlmap import URLMap from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static - urlmap = URLMap() - # Merge the global and local configurations - conf = global_conf.copy() - conf.update(local_conf) - # Get cache time in seconds - cache_time = conf.get( "static_cache_time", None ) - if cache_time is not None: - cache_time = int( cache_time ) - # Send to dynamic app by default - urlmap["/"] = app - # Define static mappings from config - urlmap["/static"] = Static( conf.get( "static_dir", "./static/" ), cache_time ) - urlmap["/images"] = Static( conf.get( "static_images_dir", "./static/images" ), cache_time ) - urlmap["/static/scripts"] = Static( conf.get( "static_scripts_dir", "./static/scripts/" ), cache_time ) - urlmap["/static/style"] = Static( conf.get( "static_style_dir", "./static/style/blue" ), cache_time ) - urlmap["/favicon.ico"] = Static( conf.get( "static_favicon_dir", "./static/favicon.ico" ), cache_time ) - urlmap["/robots.txt"] = Static( conf.get( "static_robots_txt", "./static/robots.txt" ), cache_time ) - + urlmap, cache_time = galaxy.web.framework.webapp.build_url_map( app, global_conf, local_conf ) # wrap any static dirs for plugins plugin_frameworks = plugin_frameworks or [] for framework in plugin_frameworks: diff --git a/lib/galaxy/webapps/reports/buildapp.py b/lib/galaxy/webapps/reports/buildapp.py index 9fac2c778a2..b681090098e 100644 --- a/lib/galaxy/webapps/reports/buildapp.py +++ b/lib/galaxy/webapps/reports/buildapp.py @@ -62,7 +62,7 @@ def app_factory( global_conf, **kwargs ): # Wrap the webapp in some useful middleware if kwargs.get( 'middleware', True ): webapp = wrap_in_middleware( webapp, global_conf, **kwargs ) - if kwargs.get( 'static_enabled', True ): + if asbool( kwargs.get( 'static_enabled', True ) ): webapp = wrap_in_static( webapp, global_conf, **kwargs ) # Close any pooled database connections before forking try: @@ -135,25 +135,7 @@ def wrap_in_middleware( app, global_conf, **local_conf ): return app def wrap_in_static( app, global_conf, **local_conf ): - from paste.urlmap import URLMap - from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static - urlmap = URLMap() - # Merge the global and local configurations - conf = global_conf.copy() - conf.update(local_conf) - # Get cache time in seconds - cache_time = conf.get( "static_cache_time", None ) - if cache_time is not None: - cache_time = int( cache_time ) - # Send to dynamic app by default - urlmap["/"] = app - # Define static mappings from config - urlmap["/static"] = Static( conf.get( "static_dir" ), cache_time ) - urlmap["/images"] = Static( conf.get( "static_images_dir" ), cache_time ) - urlmap["/static/scripts"] = Static( conf.get( "static_scripts_dir" ), cache_time ) - urlmap["/static/style"] = Static( conf.get( "static_style_dir" ), cache_time ) - urlmap["/favicon.ico"] = Static( conf.get( "static_favicon_dir" ), cache_time ) - # URL mapper becomes the root webapp + urlmap, _ = galaxy.web.framework.webapp.build_url_map( app, global_conf, local_conf ) return urlmap def build_template_error_formatters(): diff --git a/lib/galaxy/webapps/tool_shed/buildapp.py b/lib/galaxy/webapps/tool_shed/buildapp.py index 2ea1aee8f56..67b68cb1d09 100644 --- a/lib/galaxy/webapps/tool_shed/buildapp.py +++ b/lib/galaxy/webapps/tool_shed/buildapp.py @@ -134,7 +134,7 @@ def app_factory( global_conf, **kwargs ): # Wrap the webapp in some useful middleware if kwargs.get( 'middleware', True ): webapp = wrap_in_middleware( webapp, global_conf, **kwargs ) - if kwargs.get( 'static_enabled', True ): + if asbool( kwargs.get( 'static_enabled', True ) ): webapp = wrap_in_static( webapp, global_conf, **kwargs ) # Close any pooled database connections before forking try: @@ -219,26 +219,7 @@ def wrap_in_middleware( app, global_conf, **local_conf ): return app def wrap_in_static( app, global_conf, **local_conf ): - from paste.urlmap import URLMap - from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static - urlmap = URLMap() - # Merge the global and local configurations - conf = global_conf.copy() - conf.update(local_conf) - # Get cache time in seconds - cache_time = conf.get( "static_cache_time", None ) - if cache_time is not None: - cache_time = int( cache_time ) - # Send to dynamic app by default - urlmap["/"] = app - # Define static mappings from config - urlmap["/static"] = Static( conf.get( "static_dir", "./static/" ), cache_time ) - urlmap["/images"] = Static( conf.get( "static_images_dir", "./static/images" ), cache_time ) - urlmap["/static/scripts"] = Static( conf.get( "static_scripts_dir", "./static/scripts/" ), cache_time ) - urlmap["/static/style"] = Static( conf.get( "static_style_dir", "./static/style/blue" ), cache_time ) - urlmap["/favicon.ico"] = Static( conf.get( "static_favicon_dir", "./static/favicon.ico" ), cache_time ) - urlmap["/robots.txt"] = Static( conf.get( "static_robots_txt", "./static/robots.txt" ), cache_time ) - # URL mapper becomes the root webapp + urlmap, _ = galaxy.web.framework.webapp.build_url_map( app, global_conf, local_conf ) return urlmap def build_template_error_formatters():