parameters: (srcfilename, destfilename, locale_conf)
docstring: Copies a locale.gen file from @p srcfilename to @p destfilename
      (this may be the same name), enabling those locales that can
      be found in the map @p locale_conf. Also always enables en_US.UTF-8.
docstring_summary: Copies a locale.gen file from
docstring_tokens: Copies a locale . gen file from
function: def rewrite_locale_gen(srcfilename, destfilename, locale_conf):
      """
      Copies a locale.gen file from @p srcfilename to @p destfilename
      (this may be the same name), enabling those locales that can
      be found in the map @p locale_conf. Also always enables en_US.UTF-8.
      """
      en_us_locale = 'en_US.UTF-8'
  
      # Get entire source-file contents
      text = []
      with open(srcfilename, "r") as gen:
          text = gen.readlines()
  
      # we want unique values, so locale_values should have 1 or 2 items
      locale_values = set(locale_conf.values())
      locale_values.add(en_us_locale)  # Always enable en_US as well
  
      enabled_locales = {}
      seen_locales = set()
  
      # Write source out again, enabling some
      with open(destfilename, "w") as gen:
          for line in text:
              c = is_comment(line)
              locale, uncommented = extract_locale(line)
  
              # Non-comment lines are preserved, and comment lines
              # may be enabled if they match a desired locale
              if not c:
                  seen_locales.add(locale)
              else:
                  for locale_value in locale_values:
                      if locale.startswith(locale_value):
                          enabled_locales[locale] = uncommented
              gen.write(line)
  
          gen.write("\n###\n#\n# Locales enabled by Calamares\n")
          for locale, line in enabled_locales.items():
              if locale not in seen_locales:
                  gen.write(line + "\n")
                  seen_locales.add(locale)
  
          for locale in locale_values:
              if locale not in seen_locales:
                  gen.write("# Missing: %s\n" % locale)
function_tokens: def rewrite_locale_gen ( srcfilename , destfilename , locale_conf ) : en_us_locale = 'en_US.UTF-8' # Get entire source-file contents text = [ ] with open ( srcfilename , "r" ) as gen : text = gen . readlines ( ) # we want unique values, so locale_values should have 1 or 2 items locale_values = set ( locale_conf . values ( ) ) locale_values . add ( en_us_locale ) # Always enable en_US as well enabled_locales = { } seen_locales = set ( ) # Write source out again, enabling some with open ( destfilename , "w" ) as gen : for line in text : c = is_comment ( line ) locale , uncommented = extract_locale ( line ) # Non-comment lines are preserved, and comment lines # may be enabled if they match a desired locale if not c : seen_locales . add ( locale ) else : for locale_value in locale_values : if locale . startswith ( locale_value ) : enabled_locales [ locale ] = uncommented gen . write ( line ) gen . write ( "\n###\n#\n# Locales enabled by Calamares\n" ) for locale , line in enabled_locales . items ( ) : if locale not in seen_locales : gen . write ( line + "\n" ) seen_locales . add ( locale ) for locale in locale_values : if locale not in seen_locales : gen . write ( "# Missing: %s\n" % locale )