parameters: (filename, updated)
docstring: If the file contents are different to updated then copy updated into the
      file else leave alone so Mercurial and make don't treat it as modified.
docstring_summary: If the file contents are different to updated then copy updated into the
      file else leave alone so Mercurial and make don't treat it as modified.
docstring_tokens: If the file contents are different to updated then copy updated into the file else leave alone so Mercurial and make don t treat it as modified .
function: def UpdateFile(filename, updated):
      """ If the file contents are different to updated then copy updated into the
      file else leave alone so Mercurial and make don't treat it as modified. """
      newOrChanged = "Changed"
      try:
          with open(filename, "r", encoding="utf-8", newline='') as infile:
              original = infile.read()
          if updated == original:
              # Same as before so don't write
              return
          fileLineEnd = DetectLineEnd(original)
          updated = updated.replace("\r\n", "\n").replace("\n", fileLineEnd)
          if updated == original:
              return
          os.unlink(filename)
      except IOError: # File is not there yet
          newOrChanged = "New"
      with open(filename, "w", encoding="utf-8", newline='') as outfile:
          outfile.write(updated)
      print(newOrChanged, filename)
function_tokens: def UpdateFile ( filename , updated ) : newOrChanged = "Changed" try : with open ( filename , "r" , encoding = "utf-8" , newline = '' ) as infile : original = infile . read ( ) if updated == original : # Same as before so don't write return fileLineEnd = DetectLineEnd ( original ) updated = updated . replace ( "\r\n" , "\n" ) . replace ( "\n" , fileLineEnd ) if updated == original : return os . unlink ( filename ) except IOError : # File is not there yet newOrChanged = "New" with open ( filename , "w" , encoding = "utf-8" , newline = '' ) as outfile : outfile . write ( updated ) print ( newOrChanged , filename )