add version string 0.1.0-rc1
authorTero Marttila <terom@fixme.fi>
Thu, 12 Feb 2009 22:34:54 +0200
changeset 119 df859bfdd3be
parent 118 f530c158aa07
child 120 b5f746e9c3c2
child 121 86aebc9cb60b
add version string
config.py
templates/layout.tmpl
version.py
--- a/config.py	Thu Feb 12 01:53:52 2009 +0200
+++ b/config.py	Thu Feb 12 22:34:54 2009 +0200
@@ -8,6 +8,7 @@
 from log_source import LogSourceDecoder, LogDirectory
 from log_formatter import IrssiFormatter, DebugFormatter
 from channels import ChannelList
+import version
 import log_formatter
 
 # build relative paths
@@ -51,6 +52,13 @@
     )
 ])
 
+# version stuff
+HGWEB_URL                       = "http://hg.qmsk.net/irclogs2"
+VERSION_LINK                    = version.version_link_hg(HGWEB_URL)
+
+# Footer text to display
+HTML_FOOTER_TEXT                = '<a href="http://projects.qmsk.net/irclogs2">irclogs2</a> version %s' % (VERSION_LINK)
+
 # how to handle decode() errors for logfile lines
 LOG_SOURCE_DECODE_ERRORS        = 'replace'
 
--- a/templates/layout.tmpl	Thu Feb 12 01:53:52 2009 +0200
+++ b/templates/layout.tmpl	Thu Feb 12 22:34:54 2009 +0200
@@ -41,7 +41,7 @@
             </div>
 
             <div id="footer-left">
-
+                ${config.HTML_FOOTER_TEXT}
             </div>
 
             <div id="footer-center">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/version.py	Thu Feb 12 22:34:54 2009 +0200
@@ -0,0 +1,91 @@
+"""
+    Figuring out the project version
+
+    Currently this only supports mercurial
+"""
+
+def version_mercurial (path) :
+    """
+        Returns a (branch, tags, parents, modified) tuple for the given repo's working copy
+    """
+
+    # code adapted from mercurial.commands.identify
+    from mercurial import ui, hg, util
+    from mercurial.node import short
+    
+    # open the repo
+    repo = hg.repository(ui.ui(), path)
+
+    # the working copy change context
+    ctx = repo.workingctx()
+
+    # branch
+    branch = util.tolocal(ctx.branch())
+    
+    # map default -> None
+    if branch == 'default' :
+        branch = None
+    
+    # list of tags, without 'tip' tag
+    tags = [tag for tag in ctx.tags() if tag != 'tip']
+
+    # ctx's parents
+    parents = [short(p.node()) for p in ctx.parents()]
+
+    # local modifications?
+    modified = bool(ctx.files() + ctx.deleted())
+
+    # done
+    return (branch, tags, parents, modified)
+
+def version_string (path='.') :
+    """
+        Return a version string representing the version of the software at the given path.
+
+        Currently, this assumes that the given path points to a local Mercurial repo.
+    """
+    
+    # get info
+    branch, tags, parents, modified = version_mercurial(path)
+
+    # tags: <tag> [ "-" <tag> [ ... ]]
+    if tags :
+        return '-'.join(tags)
+
+    # revision: <parent> [ "+" <parent> [ ... ]] [ "+" ]
+    revision = '+'.join(p for p in parents) + ('+' if modified else '')
+    
+    if branch :
+        # branch: "(" <branch> ")" <revision>
+        return '(%s)%s' % (branch, revision)
+
+    else :
+        # plain: <revision>
+        return revision
+
+def version_link_hg (hgweb_url, path='.') :
+    """
+        Returns a link to a hgweb page for this version
+    """
+
+    # URL for revision ID
+    rev_url = lambda rev: '<a href="%(url)s/rev/%(rev)s">%(rev)s</a>' % dict(url=hgweb_url, rev=rev)
+
+     # get info
+    branch, tags, parents, modified = version_mercurial(path)
+
+    # tags: <tag> [ "-" <tag> [ ... ]] [ "+" ]
+    if tags :
+        return '-'.join(rev_url(tag) for tag in tags) + ('+' if modified else '')
+
+    # revision: <parent> [ "+" <parent> [ ... ]] [ "+" ]
+    revision = '+'.join(rev_url(p) for p in parents) + ('+' if modified else '')
+    
+    if branch :
+        # branch: "(" <branch> ")" <revision> [ "+" ]
+        return '(%s)%s' % (rev_url(branch), revision) + ('+' if modified else '')
+
+    else :
+        # plain: <revision>
+        return revision
+