viff

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 diff
     1.1 --- a/viff/__init__.py	Thu Jul 24 22:45:06 2008 +0200
     1.2 +++ b/viff/__init__.py	Sun Jul 27 17:43:42 2008 +0200
     1.3 @@ -126,3 +126,33 @@
     1.4  
     1.5  __version__ = '0.6'
     1.6  __license__ = 'GNU LGPL'
     1.7 +
     1.8 +def release():
     1.9 +    """Get the full release number.
    1.10 +
    1.11 +    If Mercurial is available, "hg identify" will be used to determine
    1.12 +    the state of the repository and a string of the form ``x.y-hash``
    1.13 +    is returned where ``hash`` is the changeset ID or tag. If the tag
    1.14 +    is the same as ``__version__``, then ``__version__`` is simply
    1.15 +    returned.
    1.16 +    """
    1.17 +    try:
    1.18 +        from subprocess import Popen, PIPE
    1.19 +        p = Popen(["hg", "identify"], stdout=PIPE)
    1.20 +        stdout, _ = p.communicate()
    1.21 +        if p.returncode != 0:
    1.22 +            extra = "unknown"
    1.23 +        else:
    1.24 +            parts = stdout.split()
    1.25 +            if len(parts) == 1 or parts[1] == "tip":
    1.26 +                # No tag for this changeset or only "tip".
    1.27 +                extra = parts[0]
    1.28 +            else:
    1.29 +                extra = parts[1]
    1.30 +    except OSError:
    1.31 +        extra = "unknown"
    1.32 +
    1.33 +    if extra == __version__:
    1.34 +        return __version__
    1.35 +    else:
    1.36 +        return "%s-%s" % (__version__, extra)