changeset 849:b42cf723fa4c

New function for getting full release number.
author Martin Geisler <mg@daimi.au.dk>
date Sun, 27 Jul 2008 17:43:42 +0200
parents be0907a7a885
children 6d8e69b5ec1a
files viff/__init__.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/__init__.py	Thu Jul 24 22:45:06 2008 +0200
+++ b/viff/__init__.py	Sun Jul 27 17:43:42 2008 +0200
@@ -126,3 +126,33 @@
 
 __version__ = '0.6'
 __license__ = 'GNU LGPL'
+
+def release():
+    """Get the full release number.
+
+    If Mercurial is available, "hg identify" will be used to determine
+    the state of the repository and a string of the form ``x.y-hash``
+    is returned where ``hash`` is the changeset ID or tag. If the tag
+    is the same as ``__version__``, then ``__version__`` is simply
+    returned.
+    """
+    try:
+        from subprocess import Popen, PIPE
+        p = Popen(["hg", "identify"], stdout=PIPE)
+        stdout, _ = p.communicate()
+        if p.returncode != 0:
+            extra = "unknown"
+        else:
+            parts = stdout.split()
+            if len(parts) == 1 or parts[1] == "tip":
+                # No tag for this changeset or only "tip".
+                extra = parts[0]
+            else:
+                extra = parts[1]
+    except OSError:
+        extra = "unknown"
+
+    if extra == __version__:
+        return __version__
+    else:
+        return "%s-%s" % (__version__, extra)