import string


def format_output(rc, time):
  """
  Formats the output that is used in sending the message to the client,
  depending on the return code of the command.
  """

  template = string.Template("""
${greeting}!\n
I have finished executing your job. Its return code is `$rc`, which
$comment.\n
Your command took `$time` to run. I am attaching its output to this
message. If the command created any files, you will have to inspect
them manually.
  """)

  return template.substitute( {
    "greeting" : "Hello",
    "rc"       : rc,
    "comment"  : "looks good to me" if rc == 0 else "may indicate an error",
    "time"     : time
  } )