summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/setup.py20
-rw-r--r--openstack/common/timeutils.py18
2 files changed, 35 insertions, 3 deletions
diff --git a/openstack/common/setup.py b/openstack/common/setup.py
index 81a3d20..cc8b99e 100644
--- a/openstack/common/setup.py
+++ b/openstack/common/setup.py
@@ -258,6 +258,22 @@ def get_cmdclass():
return cmdclass
+def _get_revno():
+ """Return the number of commits since the most recent tag.
+
+ We use git-describe to find this out, but if there are no
+ tags then we fall back to counting commits since the beginning
+ of time.
+ """
+ describe = _run_shell_command("git describe --always")
+ if "-" in describe:
+ return describe.rsplit("-", 2)[-2]
+
+ # no tags found
+ revlist = _run_shell_command("git rev-list --abbrev-commit HEAD")
+ return len(revlist.splitlines())
+
+
def get_version_from_git(pre_version):
"""Return a version which is equal to the tag that's on the current
revision if there is one, or tag plus number of additional revisions
@@ -271,9 +287,7 @@ def get_version_from_git(pre_version):
throw_on_error=True).replace('-', '.')
except Exception:
sha = _run_shell_command("git log -n1 --pretty=format:%h")
- describe = _run_shell_command("git describe --always")
- revno = describe.rsplit("-", 2)[-2]
- return "%s.a%s.g%s" % (pre_version, revno, sha)
+ return "%s.a%s.g%s" % (pre_version, _get_revno(), sha)
else:
return _run_shell_command(
"git describe --always").replace('-', '.')
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py
index 0f34608..5a011e8 100644
--- a/openstack/common/timeutils.py
+++ b/openstack/common/timeutils.py
@@ -98,6 +98,11 @@ def utcnow():
return datetime.datetime.utcnow()
+def iso8601_from_timestamp(timestamp):
+ """Returns a iso8601 formated date from timestamp"""
+ return isotime(datetime.datetime.utcfromtimestamp(timestamp))
+
+
utcnow.override_time = None
@@ -162,3 +167,16 @@ def delta_seconds(before, after):
except AttributeError:
return ((delta.days * 24 * 3600) + delta.seconds +
float(delta.microseconds) / (10 ** 6))
+
+
+def is_soon(dt, window):
+ """
+ Determines if time is going to happen in the next window seconds.
+
+ :params dt: the time
+ :params window: minimum seconds to remain to consider the time not soon
+
+ :return: True if expiration is within the given duration
+ """
+ soon = (utcnow() + datetime.timedelta(seconds=window))
+ return normalize_time(dt) < soon