From 30bc0d041227bb87ce1dbc66f2076faa07d8e1fc Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Mon, 16 Feb 2015 19:03:58 +0100 Subject: [PATCH] start work on issue #59 --- buildtimetrend/build.py | 22 ++++++++++++++++++++-- buildtimetrend/stages.py | 4 ++-- buildtimetrend/tools.py | 23 +++++++++++++++++++++-- buildtimetrend/travis.py | 2 +- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/buildtimetrend/build.py b/buildtimetrend/build.py index e41207d..dbcc903 100644 --- a/buildtimetrend/build.py +++ b/buildtimetrend/build.py @@ -96,11 +96,17 @@ def get_properties(self): if self.stages.started_at is not None and "started_at" not in data: data["started_at"] = self.stages.started_at + if "started_at" in data: + data["started_at"] = split_isotimestamp(data["started_at"]) + # add finished_at of last stage if it is defined # and if it is not set in properties if self.stages.finished_at is not None and "finished_at" not in data: data["finished_at"] = self.stages.finished_at + if "finished_at" in data: + data["finished_at"] = split_isotimestamp(data["finished_at"]) + return data def set_started_at(self, isotimestamp): @@ -110,7 +116,13 @@ def set_started_at(self, isotimestamp): Parameters : - isotimestamp : timestamp in iso format when build started """ - self.add_property("started_at", split_isotimestamp(isotimestamp)) + self.add_property("started_at", isotimestamp) + + def get_started_at(self): + """ + Return timestamp when build started. + """ + return split_isotimestamp(self.get_property("started_at")) def set_finished_at(self, isotimestamp): """ @@ -119,7 +131,13 @@ def set_finished_at(self, isotimestamp): Parameters : - isotimestamp : timestamp in iso format when build started """ - self.add_property("finished_at", split_isotimestamp(isotimestamp)) + self.add_property("finished_at", isotimestamp) + + def get_finished_at(self): + """ + Return timestamp when build finished. + """ + return split_isotimestamp(self.get_property("finished_at")) def load_properties_from_settings(self): """ Load build properties from settings. """ diff --git a/buildtimetrend/stages.py b/buildtimetrend/stages.py index cce8312..5a9f66c 100644 --- a/buildtimetrend/stages.py +++ b/buildtimetrend/stages.py @@ -26,7 +26,7 @@ import csv from buildtimetrend.tools import get_logger -from buildtimetrend.tools import split_timestamp +from buildtimetrend.tools import timestamp2iso from buildtimetrend.tools import check_file from buildtimetrend.tools import nano2sec from lxml import etree @@ -247,7 +247,7 @@ def set_timestamp(self, name, timestamp): """ if timestamp is not None and name is not None: try: - self.data[name] = split_timestamp(timestamp) + self.data[name] = timestamp2iso(timestamp) return True except TypeError: return False diff --git a/buildtimetrend/tools.py b/buildtimetrend/tools.py index 62f9dab..de785cd 100644 --- a/buildtimetrend/tools.py +++ b/buildtimetrend/tools.py @@ -52,8 +52,27 @@ def split_timestamp(timestamp): Parameters : - timestamp : timestamp, seconds since epoch """ - dt_utc = datetime.utcfromtimestamp(timestamp).replace(tzinfo=tzutc()) - return split_datetime(dt_utc) + return split_datetime(timestamp2datetime(timestamp)) + + +def timestamp2datetime(timestamp): + """ + Convert epoch timestamp into a datetime object. + + Parameters : + - timestamp : timestamp in seconds since epoch + """ + return datetime.utcfromtimestamp(timestamp).replace(tzinfo=tzutc()) + + +def timestamp2iso(timestamp): + """ + Convert epoch timestamp into an ISO timestamp formatted string. + + Parameters : + - timestamp : timestamp in seconds since epoch + """ + return timestamp2datetime(timestamp).isoformat() def split_isotimestamp(isotimestamp): diff --git a/buildtimetrend/travis.py b/buildtimetrend/travis.py index 212fc7c..3aaebc8 100644 --- a/buildtimetrend/travis.py +++ b/buildtimetrend/travis.py @@ -469,7 +469,7 @@ def has_timing_tags(self): Timing tags were introduced on Travis CI starting 2014-08-07, check if started_at is more recent. """ - started_at = self.current_job.get_property("started_at") + started_at = self.current_job.get_started_at() if started_at is None or "timestamp_seconds" not in started_at: return False