From 937a91cec633a625fcc0f5c0b5e9ab5cdf782889 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 20 Mar 2012 17:20:14 +0100 Subject: common/doc/template: add vcs-version directive --- common/doc/template/example/example.rst | 2 +- common/doc/template/mstar/rst2html-mstar | 1 + common/doc/template/mstar/rst2xetex-mstar | 1 + common/doc/template/mstar/vcs_version_directive.py | 25 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 common/doc/template/mstar/vcs_version_directive.py (limited to 'common') 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) -- cgit v1.2.3