summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorNicolas Schodet2012-03-20 17:20:14 +0100
committerNicolas Schodet2012-04-11 11:15:59 +0200
commit937a91cec633a625fcc0f5c0b5e9ab5cdf782889 (patch)
treed53c3b5113bf6cf52747c2fad0e97a895e559cfa /common
parent821144a85c50ec873a788110259282e1c619b2b7 (diff)
common/doc/template: add vcs-version directive
Diffstat (limited to 'common')
-rw-r--r--common/doc/template/example/example.rst2
-rwxr-xr-xcommon/doc/template/mstar/rst2html-mstar1
-rwxr-xr-xcommon/doc/template/mstar/rst2xetex-mstar1
-rw-r--r--common/doc/template/mstar/vcs_version_directive.py25
4 files changed, 28 insertions, 1 deletions
diff --git a/common/doc/template/example/example.rst b/common/doc/template/example/example.rst
index 3bb0d2fbfa..5b84ae5b3e 100644
--- a/common/doc/template/example/example.rst
+++ b/common/doc/template/example/example.rst
@@ -3,7 +3,7 @@
===================================
.. |title| replace:: reStructuredText document example
-.. |version| replace:: B6
+.. |version| vcs-version::
.. include:: header.rst
diff --git a/common/doc/template/mstar/rst2html-mstar b/common/doc/template/mstar/rst2html-mstar
index 4684368dd6..1ce9e3b084 100755
--- a/common/doc/template/mstar/rst2html-mstar
+++ b/common/doc/template/mstar/rst2html-mstar
@@ -14,6 +14,7 @@ except:
from docutils.core import publish_cmdline, default_description
import pygments_code_block_directive
+import vcs_version_directive
description = __doc__ + default_description
overrides = {
diff --git a/common/doc/template/mstar/rst2xetex-mstar b/common/doc/template/mstar/rst2xetex-mstar
index 7550ccf3a7..86b9f5353c 100755
--- a/common/doc/template/mstar/rst2xetex-mstar
+++ b/common/doc/template/mstar/rst2xetex-mstar
@@ -14,6 +14,7 @@ except:
from docutils.core import publish_cmdline, default_description
import pygments_code_block_directive
+import vcs_version_directive
description = __doc__ + default_description
overrides = {
diff --git a/common/doc/template/mstar/vcs_version_directive.py b/common/doc/template/mstar/vcs_version_directive.py
new file mode 100644
index 0000000000..3fcc00891d
--- /dev/null
+++ b/common/doc/template/mstar/vcs_version_directive.py
@@ -0,0 +1,25 @@
+"""Define and register a vcs-version directive"""
+from docutils import nodes
+from docutils.parsers.rst import directives, Directive, states
+
+class VcsVersion(Directive):
+
+ has_content = False
+
+ def run(self):
+ if not isinstance(self.state, states.SubstitutionDef):
+ raise self.error(
+ 'Invalid context: the "%s" directive can only be used within '
+ 'a substitution definition.' % self.name)
+ return [nodes.Text(self.get_version())]
+
+ def get_version(self):
+ import subprocess
+ p = subprocess.Popen(['git', 'describe', '--always'],
+ stdout=subprocess.PIPE)
+ output = p.communicate()[0]
+ if p.returncode != 0:
+ raise self.error('%s: can not determine version' % self.name)
+ return output
+
+directives.register_directive('vcs-version', VcsVersion)