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 def get_static_from_config(option_name, default_path): config_val = conf.get(option_name, default_url_path(default_path)) per_host_config_option = f"{option_name}_by_host" per_host_config = conf.get(per_host_config_option) return Static(config_val, cache_time, directory_per_host=per_host_config) # Define static mappings from config urlmap["/static"] = get_static_from_config("static_dir", "static/") urlmap["/images"] = get_static_from_config("static_images_dir", "static/images") urlmap["/static/scripts"] = get_static_from_config("static_scripts_dir", "static/scripts/") urlmap["/static/welcome.html"] = get_static_from_config("static_welcome_html", "static/welcome.html") urlmap["/favicon.ico"] = get_static_from_config("static_favicon_dir", "static/favicon.ico") urlmap["/robots.txt"] = get_static_from_config("static_robots_txt", "static/robots.txt") if 'static_local_dir' in conf: urlmap["/static_local"] = Static(conf["static_local_dir"], cache_time) return urlmap, cache_time
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 return urlmap
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
def wrap_in_static( app, global_conf, plugin_frameworks=None, **local_conf ): from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static 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: if framework and framework.serves_static: # invert control to each plugin for finding their own static dirs for plugin_url, plugin_static_path in framework.get_static_urls_and_paths(): plugin_url = '/plugins/' + plugin_url urlmap[( plugin_url )] = Static( plugin_static_path, cache_time ) log.debug( 'added url, path to static middleware: %s, %s', plugin_url, plugin_static_path ) # URL mapper becomes the root webapp return urlmap
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) # wrap any static dirs for plugins plugin_frameworks = plugin_frameworks or [] for framework in plugin_frameworks: if framework and framework.serves_static: # invert control to each plugin for finding their own static dirs for plugin_url, plugin_static_path in framework.get_static_urls_and_paths( ): plugin_url = '/plugins/' + plugin_url urlmap[(plugin_url)] = Static(plugin_static_path, cache_time) log.debug('added url, path to static middleware: %s, %s', plugin_url, plugin_static_path) # URL mapper becomes the root webapp return urlmap
def get_static_from_config(option_name, default_path): config_val = conf.get(option_name, default_url_path(default_path)) per_host_config_option = f"{option_name}_by_host" per_host_config = conf.get(per_host_config_option) return Static(config_val, cache_time, directory_per_host=per_host_config)