parameters: (env, template_filename, config_filename)
docstring: Load shell script `template_filename`, replace values in variable
      assignments of the form `CONFIG_key='default'` with corresponding
      value `env['key']`, and save the result as `config_filename`.
docstring_summary: Load shell script `template_filename`, replace values in variable
      assignments of the form `CONFIG_key='default'` with corresponding
      value `env['key']`, and save the result as `config_filename`.
docstring_tokens: Load shell script template_filename replace values in variable assignments of the form CONFIG_key = default with corresponding value env [ key ] and save the result as config_filename .
function: def write_config(env, template_filename, config_filename):
      """
      Load shell script `template_filename`, replace values in variable
      assignments of the form `CONFIG_key='default'` with corresponding
      value `env['key']`, and save the result as `config_filename`.
      """
      with open(template_filename, 'r') as template_file:
          template = template_file.read()
      with open(config_filename, 'w') as config_file:
          escape = env['ESCAPE']
          def subst(matchobj):
              key = matchobj.group(1)
              if key not in env:
                  return matchobj.group(0)
              else:
                  val = env.subst('$' + key)
                  return 'CONFIG_%s=%s' % (key, escape(val))
          config = re.sub(r'^CONFIG_(\w+)=.*', subst, template, flags=re.M)
          config_file.write(config)
      try:
          os.chmod(config_filename, 0o755)
      except: pass
function_tokens: def write_config ( env , template_filename , config_filename ) : with open ( template_filename , 'r' ) as template_file : template = template_file . read ( ) with open ( config_filename , 'w' ) as config_file : escape = env [ 'ESCAPE' ] def subst ( matchobj ) : key = matchobj . group ( 1 ) if key not in env : return matchobj . group ( 0 ) else : val = env . subst ( '$' + key ) return 'CONFIG_%s=%s' % ( key , escape ( val ) ) config = re . sub ( r'^CONFIG_(\w+)=.*' , subst , template , flags = re . M ) config_file . write ( config ) try : os . chmod ( config_filename , 0o755 ) except : pass