mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Update galaxy.util.properties to allow YAML.
This commit is contained in:
@@ -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' ) )
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" )
|
||||
|
||||
@@ -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 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user