def compile_css_(tag_name, css_config, force):
  if IS_APPSERVER:
    return
  
  def needs_update(media_info, output_path):
    if not css_config['enabled']:
      return False
    if not os.path.exists(output_path):
      return True

    last_info = media_info.get(css_config['subdir'], tag_name)
    if not last_info:
      return True
    last_config = last_info.get('config')
    if not last_config:
      return True

    if not equal_object_(last_config, css_config):
      return True

    if 'source_files' not in last_info:
      return True
    for path, mtime in last_info['source_files']:
      if mtime != os.path.getmtime(path):
        return True

  def csstidy(css_path):
    tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
    ifile = open(css_path)
    tmp_file.write(ifile.read())
    ifile.close()
    tmp_file.flush()

    output_file = tempfile.NamedTemporaryFile(mode='w+b')
  
    print_status(" %s %s %s ..." % (css_config['csstidy']['path'],
                                    css_path,
                                    css_config['csstidy']['arguments']))
    command = '%s %s %s %s' % (css_config['csstidy']['path'],
                               tmp_file.name,
                               css_config['csstidy']['arguments'],
                               output_file.name)
    command_output = os.popen(command).read()
  
    filtered_css = output_file.read()
    output_file.close()
    tmp_file.close()
    return filtered_css

  def concat(css_path):
    print_status(" concat %s" % css_path)
    ifile = open(css_path)
    css = ifile.read()
    ifile.close()
    return css

  if ('csstidy', 'concat') not in css_config['tool']:
    print_status("COMPILE_MEDIA_CSS['tool'] setting is invalid;"
                 " unknown tool `%s'" % css_config['tool'])
    sys.exit(1)

  global media_info
  if media_info is None:
    media_info = MediaInfo.load()

  output_path = make_output_path_(css_config, css_config['subdir'],
                                  css_config['output_filename'])
  if not force and not needs_update(media_info, output_path):
    print_status(' up to date.')
    return

  if css_config['tool'] == 'csstidy':
    tool_method = csstidy
  elif css_config['tool'] == 'concat':
    tool_method = concat

  source_files = []
  for path in css_config['source_files']:
    path = make_input_path_(path)
    logging.info(path)
    source_files.append((path, os.path.getmtime(path)))
  ofile = create_file_(output_path)
  try:
    for path, mtime in source_files:
      ofile.write(tool_method(path))
  finally:
    ofile.close()

  result_url = '/' + make_output_path_(css_config, css_config['subdir'],
                                       css_config['output_filename'],
                                       relative=True)
  last_info = {'config': copy.deepcopy(css_config),
               'source_files': source_files,
               'result_urls': [result_url]}
               
  media_info.set(css_config['subdir'], tag_name, last_info)
  media_info.save()

#--------------------------------------------------------------
dataset/ETHPy150Open IanLewis/kay/kay/ext/media_compressor/media_compiler.py/compile_css_/swapped operands of `not in`