code: def format_theme(selection):
      
      global themefile
  
      text = open(THEMEDIR + '/' + selection).read()
      if '!dotcolors' in text[:10]:
          themefile = text
          return
  
      lines = ['!dotcolors auto formatted\n']
      for line in text.split('\n'):
          lline = line.lower()
          background = 'background' in lline
          foreground = 'foreground' in lline
          color = 'color' in lline
  
          if background:
              if 'rgb' in line:
                  # rbga: 0000/0000/0000/dddd
                  rgb = line.split(':')[2].replace(' ', '')
                  rgb = rgb_to_hex(rgb)
                  lines.append('*background:\t%s' % rgb)
              else:
                  lines.append('\t#'.join(line \
                                          .replace(' ', '') \
                                          .replace('\t', '') \
                                          .split('#')))
  
          if foreground:
              if 'rgb' in line:
                  # rbga: 0000/0000/0000/dddd
                  rgb = line.split(':')[2].replace(' ', '')
                  rgb = rgb_to_hex(rgb)
                  lines.append('*foreground:\t%s' % rgb)
              else:
                  lines.append('\t#'.join(line \
                                          .replace(' ', '') \
                                          .replace('\t', '') \
                                          .split('#')))
  
          if color:
              if lline[0] != '!':
                  lines.append('\t#'.join(line \
                                          .replace(' ', '') \
                                          .replace('\t', '') \
                                          .split('#')))
      
      themefile = '\n'.join(lines) + '\n'
      fd, tmpfile = tempfile.mkstemp()
      if exists( THEMEDIR + '/' + selection ):
          old = open( THEMEDIR + '/' + selection )
          new = os.fdopen(fd, 'w')
          os.write(fd, themefile)
          old.close()
          new.close()
          move( tmpfile, THEMEDIR + '/' + selection )
docs: removes any non-color related lines from theme file