diff --git a/lib/galaxy/dependencies/__init__.py b/lib/galaxy/dependencies/__init__.py index 5d950c3fa16..e7a5869eb16 100644 --- a/lib/galaxy/dependencies/__init__.py +++ b/lib/galaxy/dependencies/__init__.py @@ -22,7 +22,7 @@ class ConditionalDependencies( object ): self.get_conditional_requirements() def parse_configs( self ): - self.config = load_app_properties( ini_file=self.config_file ) + self.config = load_app_properties( config_file=self.config_file ) job_conf_xml = self.config.get( "job_config_file", join( dirname( self.config_file ), 'job_conf.xml' ) ) diff --git a/lib/galaxy/util/properties.py b/lib/galaxy/util/properties.py index b5743dc0ef2..26ba8489108 100644 --- a/lib/galaxy/util/properties.py +++ b/lib/galaxy/util/properties.py @@ -6,6 +6,8 @@ import os import os.path import sys +import yaml + from six import iteritems from six.moves.configparser import ConfigParser @@ -35,21 +37,29 @@ def find_config_file(default, old_default, explicit, cwd=None): def load_app_properties( kwds={}, ini_file=None, - ini_section="app:main", + ini_section=None, + config_file=None, + config_section=None, config_prefix="GALAXY_CONFIG_" ): properties = kwds.copy() if kwds else {} - if ini_file: - defaults = { - 'here': os.path.dirname(os.path.abspath(ini_file)), - '__file__': os.path.abspath(ini_file) - } - parser = NicerConfigParser(ini_file, defaults=defaults) - parser.optionxform = str # Don't lower-case keys - with open(ini_file) as f: - parser.read_file(f) + if config_file is None: + config_file = ini_file + config_section = ini_section - properties.update( dict( parser.items( ini_section ) ) ) + if config_file: + if not config_file.endswith(".yml") and not config_file.endswith(".yml.sample"): + if config_section is None: + config_section = "app:main" + parser = nice_config_parser(config_file) + properties.update( dict( parser.items( config_section ) ) ) + else: + if config_section is None: + config_section = "galaxy" + + with open(config_file, "r") as f: + raw_properties = yaml.load(f) + properties = raw_properties[config_section] or {} override_prefix = "%sOVERRIDE_" % config_prefix for key in os.environ: @@ -64,6 +74,18 @@ def load_app_properties( return properties +def nice_config_parser(path): + defaults = { + 'here': os.path.dirname(os.path.abspath(path)), + '__file__': os.path.abspath(path) + } + parser = NicerConfigParser(path, defaults=defaults) + parser.optionxform = str # Don't lower-case keys + with open(path) as f: + parser.read_file(f) + return parser + + class NicerConfigParser(ConfigParser): def __init__(self, filename, *args, **kw): diff --git a/lib/galaxy/web/framework/webapp.py b/lib/galaxy/web/framework/webapp.py index 6e13934c0e6..28bb34ab485 100644 --- a/lib/galaxy/web/framework/webapp.py +++ b/lib/galaxy/web/framework/webapp.py @@ -27,6 +27,7 @@ from galaxy.exceptions import MessageException from galaxy import util from galaxy.util import asbool from galaxy.util import safe_str_cmp +from galaxy.util.postfork import process_is_uwsgi from galaxy.util.sanitize_html import sanitize_html from galaxy.managers import context @@ -954,6 +955,27 @@ class GalaxyWebTransaction( base.DefaultWebTransaction, return str(template) +def build_native_uwsgi_app( paste_factory, config_section ): + """uwsgi can load paste factories with --ini-paste, but this builds non-paste uwsgi apps. + + In particular these are useful with --yaml or --json for config.""" + if not process_is_uwsgi: + return None + else: + import uwsgi + uwsgi_opt = uwsgi.opt + config_file = uwsgi_opt.get("yaml") or uwsgi_opt.get("json") + if not config_file: + # Probably loaded via --ini-paste - expect paste app. + return None + + uwsgi_app = paste_factory(uwsgi.opt, load_app_kwds={ + "config_file": config_file, + "config_section": config_section, + }) + return uwsgi_app + + def build_url_map( app, global_conf, local_conf ): from paste.urlmap import URLMap from galaxy.web.framework.middleware.static import CacheableStaticURLParser as Static diff --git a/lib/galaxy/webapps/tool_shed/buildapp.py b/lib/galaxy/webapps/tool_shed/buildapp.py index 7090bc4c066..03e71335ad5 100644 --- a/lib/galaxy/webapps/tool_shed/buildapp.py +++ b/lib/galaxy/webapps/tool_shed/buildapp.py @@ -309,3 +309,7 @@ def _map_redirects( mapper ): mapper.redirect( "/repository/status_for_installed_repository", "/api/repositories/updates/", _redirect_code="301 Moved Permanently", conditions=dict( function=forward_qs ) ) return mapper + + +def uwsgi_app(): + return galaxy.web.framework.webapp.build_native_uwsgi_app( app_factory, "tool_shed" ) diff --git a/scripts/manage_tools.py b/scripts/manage_tools.py index 5d17e41347f..66d13f80da9 100644 --- a/scripts/manage_tools.py +++ b/scripts/manage_tools.py @@ -18,7 +18,7 @@ if not os.path.exists( config_file ): sys.exit( 1 ) repo = 'lib/tool_shed/galaxy_install/migrate' -properties = load_app_properties( ini_file=config_file ) +properties = load_app_properties( config_file=config_file ) cp = SafeConfigParser() cp.read( config_file )