def _update_pot_file(target, source, env):
  import re
  import os
  import SCons.Action
  nop = lambda target, source, env : 0

  # Save scons cwd and os cwd (NOTE: they may be different. After the job, we
  # revert ech one to its original state).
  save_cwd = env.fs.getcwd()
  save_os_cwd = os.getcwd()
  chdir = target[0].dir
  chdir_str = repr(chdir.get_abspath())
  # Print chdir message (employ SCons.Action.Action for that. It knows better
  # than me how to to this correctly).
  env.Execute(SCons.Action.Action(nop, "Entering " + chdir_str))
  # Go to target's directory and do our job
  env.fs.chdir(chdir, 1) # Go into target's directory
  try:
    cmd = _CmdRunner('$XGETTEXTCOM', '$XGETTEXTCOMSTR')
    action = SCons.Action.Action(cmd, strfunction=cmd.strfunction)
    status = action([ target[0] ], source, env)
  except:
    # Something went wrong.
    env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str))
    # Revert working dirs to previous state and re-throw exception.
    env.fs.chdir(save_cwd, 0)
    os.chdir(save_os_cwd)
    raise
  # Print chdir message.
  env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str))
  # Revert working dirs to previous state.
  env.fs.chdir(save_cwd, 0)
  os.chdir(save_os_cwd)
  # If the command was not successfull, return error code.
  if status: return status

  new_content = cmd.out

  if not new_content:
    # When xgettext finds no internationalized messages, no *.pot is created
    # (because we don't want to bother translators with empty POT files).
    needs_update = False
    explain = "no internationalized messages encountered"
  else:
    if target[0].exists():
      # If the file already exists, it's left unaltered unless its messages
      # are outdated (w.r.t. to these recovered by xgettext from sources).
      old_content = target[0].get_text_contents()
      re_cdate = re.compile(r'^"POT-Creation-Date: .*"$[\r\n]?', re.M)
      old_content_nocdate = re.sub(re_cdate,"",old_content)
      new_content_nocdate = re.sub(re_cdate,"",new_content)
      if(old_content_nocdate == new_content_nocdate):
        # Messages are up-to-date
        needs_update = False
        explain = "messages in file found to be up-to-date"
      else:
        # Messages are outdated
        needs_update = True
        explain = "messages in file were outdated"
    else:
      # No POT file found, create new one
      needs_update = True
      explain = "new file"
  if needs_update:
    # Print message employing SCons.Action.Action for that.
    msg = "Writting " + repr(str(target[0])) + " (" + explain + ")"
    env.Execute(SCons.Action.Action(nop, msg))
    f = open(str(target[0]),"w")
    f.write(new_content)
    f.close()
    return 0
  else:
    # Print message employing SCons.Action.Action for that.
    msg = "Not writting " + repr(str(target[0])) + " (" + explain + ")"
    env.Execute(SCons.Action.Action(nop, msg))
    return 0
#############################################################################

#############################################################################
Action function for `POTUpdate` builder
dataset/ETHPy150Open kayhayen/Nuitka/nuitka/build/inline_copy/lib/scons-2.3.2/SCons/Tool/xgettext.py/_update_pot_file