1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/d8fc0bf14dfe/ Changeset: d8fc0bf14dfe Branch: next-stable User: jmchilton Date: 2014-09-22 23:14:12+00:00 Summary: Fix ORM scripts for 42f677bab2e4880b62758614fcb2c7dc27013788. Updating common Python module used by ORM scripts (create_db.sh/migrate_db.sh/db_shell.py) to allow the same configuration via enviornment variables as well. Thanks to Bjoern for the bug report/feature request. Affected #: 3 files diff -r fa3bb4ad3b09d41cddc20cf0158f228c97866c0e -r d8fc0bf14dfeb6f59cef39e92984a46f2fafc4dc lib/galaxy/config.py --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -13,6 +13,7 @@ import ConfigParser from datetime import timedelta from galaxy.web.formatting import expand_pretty_datetime_format +from galaxy.util.properties import load_app_properties from galaxy.util import string_as_bool from galaxy.util import listify from galaxy.util.dbkeys import GenomeBuilds @@ -20,9 +21,6 @@ log = logging.getLogger( __name__ ) -CONFIG_DEFAULT_PREFIX = "GALAXY_CONFIG_" -CONFIG_OVERRIDE_PREFIX = "GALAXY_CONFIG_OVERRIDE_" - def resolve_path( path, root ): """If 'path' is relative make absolute by prepending 'root'""" @@ -39,15 +37,9 @@ deprecated_options = ( 'database_file', ) def __init__( self, **kwargs ): - for key in os.environ: - if key.startswith( CONFIG_OVERRIDE_PREFIX ): - config_key = key[ len( CONFIG_OVERRIDE_PREFIX ): ].lower() - kwargs[ config_key ] = os.environ[ key ] - elif key.startswith( CONFIG_DEFAULT_PREFIX ): - config_key = key[ len( CONFIG_DEFAULT_PREFIX ): ].lower() - if config_key not in kwargs: - kwargs[ config_key ] = os.environ[ key ] - + kwargs = load_app_properties( + kwds=kwargs + ) self.config_dict = kwargs self.root = kwargs.get( 'root_dir', '.' ) diff -r fa3bb4ad3b09d41cddc20cf0158f228c97866c0e -r d8fc0bf14dfeb6f59cef39e92984a46f2fafc4dc lib/galaxy/model/orm/scripts.py --- a/lib/galaxy/model/orm/scripts.py +++ b/lib/galaxy/model/orm/scripts.py @@ -3,7 +3,6 @@ """ import logging import os.path -from ConfigParser import SafeConfigParser from galaxy import eggs @@ -12,6 +11,7 @@ eggs.require( "SQLAlchemy" ) eggs.require( "sqlalchemy_migrate" ) +from galaxy.util.properties import load_app_properties from galaxy.model.orm import dialect_to_egg import pkg_resources @@ -112,13 +112,13 @@ if cwd: config_file = os.path.join( cwd, config_file ) - cp = SafeConfigParser() - cp.read( config_file ) + properties = load_app_properties( ini_file=config_file ) - if cp.has_option( "app:main", "%sdatabase_connection" % config_prefix): - db_url = cp.get( "app:main", "%sdatabase_connection" % config_prefix ) - elif cp.has_option( "app:main", "%sdatabase_file" % config_prefix ): - db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % cp.get( "app:main", "database_file" ) + if ("%sdatabase_connection" % config_prefix) in properties: + db_url = properties[ "%sdatabase_connection" % config_prefix ] + elif ("%sdatabase_file" % config_prefix) in properties: + database_file = properties[ "%sdatabase_file" % config_prefix ] + db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % database_file else: db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % default_sqlite_file diff -r fa3bb4ad3b09d41cddc20cf0158f228c97866c0e -r d8fc0bf14dfeb6f59cef39e92984a46f2fafc4dc lib/galaxy/util/properties.py --- /dev/null +++ b/lib/galaxy/util/properties.py @@ -0,0 +1,41 @@ +""" Module used to blend ini, environment, and explicit dictionary properties +to determine application configuration. Some hard coded defaults for Galaxy but +this should be reusable by tool shed and pulsar as well. +""" +import os +import os.path + + +def load_app_properties( + kwds={}, + ini_file=None, + ini_section="app:main", + 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) + } + # Mimic the way loadwsgi loads configuration files - needed for + # correctness given the very specific ways interpolation is handled. + from galaxy.util.pastescript.loadwsgi import NicerConfigParser + parser = NicerConfigParser(ini_file, defaults=defaults) + parser.optionxform = str # Don't lower-case keys + with open(ini_file) as f: + parser.read_file(f) + + properties.update( dict( parser.items( ini_section ) ) ) + + override_prefix = "%sOVERRIDE_" % config_prefix + for key in os.environ: + if key.startswith( override_prefix ): + config_key = key[ len( override_prefix ): ].lower() + properties[ config_key ] = os.environ[ key ] + elif key.startswith( config_prefix ): + config_key = key[ len( config_prefix ): ].lower() + if config_key not in properties: + properties[ config_key ] = os.environ[ key ] + + return properties Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.