TimeStamp moved to utils module
Change-Id: Ibed7bb178f602203cb71f1a9fe206a3894ec3c96
diff --git a/utils.py b/utils.py
index 8872c47..d95165a 100644
--- a/utils.py
+++ b/utils.py
@@ -9,6 +9,7 @@
def singleton(class_):
instances = {}
+
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
@@ -49,6 +50,27 @@
return wrap
+@singleton
+class TimeStamp(object):
+ def __init__(self, now=None):
+ # now='2015-06-18-104259'
+ self.snapshot_stamp_format = r'%Y-%m-%d-%H%M%S'
+ self.snapshot_stamp_regexp = r'[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}'
+
+ if now is None:
+ self.now = datetime.datetime.utcnow()
+ else:
+ self.now = datetime.datetime.strptime(now,
+ self.snapshot_stamp_format)
+ self.snapshot_stamp = self.now.strftime(self.snapshot_stamp_format)
+
+ def __str__(self):
+ return self.snapshot_stamp
+
+ def reinit(self, *args, **kwagrs):
+ self.__init__(*args, **kwagrs)
+
+
class ResultNotProduced(Exception):
def __init__(self, value):
self.value = value