From aa6fa90a4b88a636568a60c4258702a676d4e168 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sun, 21 Sep 2014 22:02:09 -0400 Subject: [PATCH] Allow configuration of Galaxy via environment variables. Allow overriding config defaults (those not specified in the configuration file) with GALAXY_CONFIG_ and allow overriding actual configured values with GALAXY_CONFIG_OVERRIDE_. Here config-name is the actual value in galaxy.ini but in upper case. --- lib/galaxy/config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/galaxy/config.py b/lib/galaxy/config.py index 8a2040f22c4..571bf3e8557 100644 --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -20,6 +20,9 @@ from galaxy import eggs 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'""" @@ -36,6 +39,15 @@ class Configuration( object ): 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 ] + self.config_dict = kwargs self.root = kwargs.get( 'root_dir', '.' )