From 3386e7a93025e3268a5f0d80404512a8eb6e90f2 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 30 Sep 2008 09:36:49 +0000
Subject: [PATCH] Abstract the timestamp formatting into cli.py

Currently we format the timestamp inside the gnt-job info function. We
will need this more times in the future, so move it to cli.py as a
separate, exported function.

Reviewed-by: imsnah
---
 lib/cli.py      | 16 +++++++++++++++-
 scripts/gnt-job |  4 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index b97edff8f..226f45347 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -47,7 +47,7 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
            "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT", "SUBMIT_OPT",
            "ListTags", "AddTags", "RemoveTags", "TAG_SRC_OPT",
            "FormatError", "SplitNodeOption", "SubmitOrSend",
-           "JobSubmittedException",
+           "JobSubmittedException", "FormatTimestamp",
            ]
 
 
@@ -689,3 +689,17 @@ def GenerateTable(headers, fields, separator, data,
     result.append(format % tuple(args))
 
   return result
+
+
+def FormatTimestamp(ts):
+  """Formats a given timestamp.
+
+  @type ts: timestamp
+  @param ts: a timeval-type timestamp, a tuple of seconds and microseconds
+
+  @rtype: string
+  @returns: a string with the formatted timestamp
+
+  """
+  sec, usec = ts
+  return time.strftime("%F %T", time.localtime(sec)) + ".%06d" % usec
diff --git a/scripts/gnt-job b/scripts/gnt-job
index a29fa2108..7ef6c2379 100755
--- a/scripts/gnt-job
+++ b/scripts/gnt-job
@@ -178,8 +178,8 @@ def ShowJobs(opts, args):
       else:
         format(3, "Result: %s" % result)
       format(3, "Execution log:")
-      for serial, (sec, usec), log_type, log_msg in log:
-        time_txt = time.strftime("%F %T", time.localtime(sec)) + ".%06d" % usec
+      for serial, log_ts, log_type, log_msg in log:
+        time_txt = FormatTimestamp(log_ts)
         encoded = str(log_msg).encode('string_escape')
         format(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
   return 0
-- 
GitLab