Override YAML settings with values from the environment variables.

        - The letter '_' is delimit the hierarchy of the YAML settings such
          that the value of 'config.databases.local' will be overridden
          by CONFIG_DATABASES_LOCAL.
430615
def update_from_env(yaml_dict, prefix=None):
    '''
    
    '''
    prefix = prefix or ""

    def _set_env_var(path, node):
        env_path = "{0}{1}{2}".format(
            prefix.upper(),
            '_' if prefix else '',
            '_'.join([str(key).upper() for key in path])
        )
        env_val = os.environ.get(env_path, None)
        if env_val is not None:
            # convert the value to a YAML-defined type
            env_dict = yamldict.load('val: {0}'.format(env_val))
            return env_dict.val
        else:
            return None

    # traverse yaml_dict with the callback function
    yaml_dict.traverse(_set_env_var)
1172032
def database_configuration
       require 'erb'
       YAML::load(ERB.new(IO.read(database_configuration_file)).result) if File.exists?(database_configuration_file)
     end
231098
def main(arguments=None):
    

    # setup the command-line util settings
    su = tools(
        arguments=arguments,
        docString=__doc__,
        logLevel="WARNING",
        options_first=False,
        projectName=False
    )
    arguments, settings, log, dbConn = su.setup()

    # unpack remaining cl arguments using `exec` to setup the variable names
    # automatically
    for arg, val in arguments.iteritems():
        if arg[0] == "-":
            varname = arg.replace("-", "") + "Flag"
        else:
            varname = arg.replace("<", "").replace(">", "")
        if isinstance(val, str) or isinstance(val, unicode):
            exec(varname + " = '%s'" % (val,))
        else:
            exec(varname + " = %s" % (val,))
        if arg == "--dbConn":
            dbConn = val
        log.debug('%s = %s' % (varname, val,))

    if os.path.isfile(pathToYaml):
        from fundamentals.mysql import yaml_to_database
        # PARSE YAML FILE CONTENTS AND ADD TO DATABASE
        yaml2db = yaml_to_database(
            log=log,
            settings=settings,
            dbConn=dbConn
        )
        yaml2db.add_yaml_file_content_to_database(
            filepath=pathToYaml,
            deleteFile=deleteFlag
        )
        basename = os.path.basename(pathToYaml)
        print "Content of %(basename)s added to database" % locals()

    else:
        from fundamentals.mysql import yaml_to_database
        yaml2db = yaml_to_database(
            log=log,
            settings=settings,
            dbConn=dbConn,
            pathToInputDir=pathToYaml,
            deleteFiles=deleteFlag
        )
        yaml2db.ingest()
        print "Content of %(pathToYaml)s directory added to database" % locals()

    return
882965
def db_config
      @db_config ||= begin 
        raise "ENV['#{env_prefix}_DATABASE_URL'] expected but not found!" unless ENV["#{env_prefix}_DATABASE_URL"]
        config = parse_db_uri(ENV["#{env_prefix}_DATABASE_URL"])
    
        if ENV["#{env_prefix}_DATABASE_CA"]
          config.merge!(db_configuration({
            :sslca => ENV["#{env_prefix}_DATABASE_CA"],
            :sslcert => ENV["#{env_prefix}_DATABASE_CERT"],
            :sslkey => ENV["#{env_prefix}_DATABASE_KEY"],
          }))
        end
      
        config
      end
    end
550704
protected function overrideEnvironmentVariables()
    {
        if (!isset($this->options->filtered['configuration'])) {
            return;
        }

        $variables = $this->options->filtered['configuration']->getEnvironmentVariables();

        foreach ($variables as $key => $value) {
            putenv(sprintf('%s=%s', $key, $value));

            $_ENV[$key] = $value;
        }
    }
15229
function overrideConfig() {
    _.merge(Elixir.config, require(path.join(process.cwd(), 'elixirConfig.js')));
}
238563
def load config_file
      config_file ||= @config_file
      newsets = YAML::load_file(config_file)
      raise 'Config file was not valid YAML' if newsets == false
      newsets.deep_symbolize.each_pair do |key, value|
        varname = "@#{key.to_s}".to_sym
        unless self.instance_variables.include? varname
          raise SettingsError.new "Key #{key.to_s} in settings file is not valid"
        end
        self.instance_variable_set(varname, value)
      end
    end
703165
def config(key, value, local=True):
    
    option = local and '--local' or ''
    run('config %s "%s" "%s"' % (option, key, value))
1081420
def environment_variables
      vars = @process.environment_variables.merge({
        'PROC_NAME' => self.description,
        'PID_FILE' => self.pid_file_path,
        'APP_ROOT' => @process.config.root
      })
      vars['PORT'] = @port.to_s if @port
      vars
    end
1223199
def setOverrideValue(self, attributes, hostName):
        
        self['override'] = True
        attrType = type(attributes)
        if attrType is dict:
            self['parameter_type'] = 'hash'
        elif attrType is list:
            self['parameter_type'] = 'array'
        else:
            self['parameter_type'] = 'string'
        orv = self.getOverrideValueForHost(hostName)
        if orv:
            orv['value'] = attributes
            return True
        else:
            return self.api.create('{}/{}/{}'.format(self.objName,
                                                     self.key,
                                                     'override_values'),
                                   {"override_value":
                                       {"match": "fqdn={}".format(hostName),
                                        "value": attributes}})
536446
def _load_yaml_config(self):
        
        try:
            config = self._read_config()
        except OSError as error:
            raise ValueError('Could not read configuration file: %s' % error)
        try:
            return yaml.safe_load(config)
        except yaml.YAMLError as error:
            message = '\n'.join(['    > %s' % line
                                 for line in str(error).split('\n')])
            sys.stderr.write('\n\n  Error in the configuration file:\n\n'
                             '{}\n\n'.format(message))
            sys.stderr.write('  Configuration should be a valid YAML file.\n')
            sys.stderr.write('  YAML format validation available at '
                             'http://yamllint.com\n')
            raise ValueError(error)
807234
def set_as_environment_variables(self, override=False):
        
        for k, v in self.dict().items():
            if k in os.environ and not override:
                continue
            # With Python2 on Windows, force environment variables to str to avoid
            # "TypeError: environment can only contain strings" in Python's subprocess.py.
            if PY2 and WIN:
                if isinstance(k, text_type) or isinstance(v, text_type):
                    k = k.encode('ascii')
                    v = v.encode('ascii')
            os.environ[k] = v

        return True
1004037
def override_level_names(self, mapping):
        
        if not isinstance(mapping, dict):
            return
        for key, val in mapping.items():
            if key in self._level_names:
                self._level_names[key] = val
265110
def override_stage_config_setting(self, key, val):
        
        self._stage_config_overrides = getattr(self, '_stage_config_overrides', {})
        self._stage_config_overrides.setdefault(self.api_stage, {})[key] = val
661237
def set_os_environ(variables_mapping):
    
    for variable in variables_mapping:
        os.environ[variable] = variables_mapping[variable]
        logger.log_debug("Set OS environment variable: {}".format(variable))
1303683
def parse_config(config, env, as_dict=True):
  

  if config is None:
    return None
  stripped = config.strip()
  if len(stripped) == 0:
    config = {}
  elif stripped[0] == '{':
    config = json.loads(config)
  else:
    config = yaml.load(config)
  if as_dict:
    config = dict(config)

  # Now we need to walk the config dictionary recursively replacing any '$name' vars.
  replace_vars(config, env)
  return config
604087
def environment(name)
      yaml_path = yaml_path_if_exists(name)
      rb_path = rb_path_if_exists(name)

      raise "found multiple env files for same env #{name}." if !yaml_path.nil? && !rb_path.nil?
      raise "TODO: implement Ruby environments." unless rb_path.nil?

      env = Environments::Environment.load_yaml_file(yaml_path) unless yaml_path.nil?

      raise "no env found for '#{name}'." if env.nil?

      IceNine.deep_freeze(env)
      env
    end