diff --git a/buildozer/__init__.py b/buildozer/__init__.py index 2fdb8f5..8861d93 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -100,6 +100,10 @@ class Buildozer(object): self.config.read(filename) self.check_configuration_tokens() + # Check all section/tokens for env vars, and replace the + # config value if a suitable env var exists. + set_config_from_envs(self.config) + try: self.log_level = int(self.config.getdefault( 'buildozer', 'log_level', '1')) @@ -915,7 +919,7 @@ class Buildozer(object): # get a key as a list of string, seperated from the comma # if a section:token is defined, let's use the content as a list. - set_config_from_env(section, token, self.config) + set_config_token_from_env(section, token, self.config) l_section = '{}:{}'.format(section, token) if self.config.has_section(l_section): @@ -938,7 +942,7 @@ class Buildozer(object): # monkey-patch method for ConfigParser # get an appropriate env var if it exists, else # get a key in a section, or the default - set_config_from_env(section, token, self.config) + set_config_token_from_env(section, token, self.config) if not self.config.has_section(section): return default if not self.config.has_option(section, token): @@ -948,7 +952,7 @@ class Buildozer(object): def _get_config_bool(self, section, token, default=False): # monkey-patch method for ConfigParser # get a key in a section, or the default - set_config_from_env(section, token, self.config) + set_config_token_from_env(section, token, self.config) if not self.config.has_section(section): return default if not self.config.has_option(section, token): @@ -1212,7 +1216,17 @@ def run_remote(): except BuildozerException as error: Buildozer().error('%s' % error) -def set_config_from_env(section, token, config): +def set_config_from_envs(config): + '''Takes a ConfigParser, and checks every section/token for an + environment variable of the form SECTION_TOKEN, with any dots + replaced by underscores. If the variable exists, sets the config + variable to the env value. + ''' + for section in config.sections(): + for token in config.options(section): + set_config_token_from_env(section, token, config) + +def set_config_token_from_env(section, token, config): '''Given a config section and token, checks for an appropriate environment variable. If the variable exists, sets the config entry to its value.