summaryrefslogtreecommitdiff
path: root/build_manpage.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-03-25 00:50:27 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-03-25 00:50:27 +0100
commit87440084fc62f1ebb1a2ad96041740df994071f4 (patch)
treee4f5ca51ce515691564dd41dda7d80d362755956 /build_manpage.py
parent987bd61dafdbcd7e348efb4d8a6968fe35ba6799 (diff)
downloadportato-87440084fc62f1ebb1a2ad96041740df994071f4.tar.gz
portato-87440084fc62f1ebb1a2ad96041740df994071f4.tar.bz2
portato-87440084fc62f1ebb1a2ad96041740df994071f4.zip
Update manpage creation
Diffstat (limited to 'build_manpage.py')
-rw-r--r--build_manpage.py40
1 files changed, 32 insertions, 8 deletions
diff --git a/build_manpage.py b/build_manpage.py
index 8bdbf2f..ab609bf 100644
--- a/build_manpage.py
+++ b/build_manpage.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
#
-# This file is copied from http://andialbrecht.wordpress.com/2009/03/17/creating-a-man-page-with-distutils-and-optparse/
+# This file is originally from http://andialbrecht.wordpress.com/2009/03/17/creating-a-man-page-with-distutils-and-optparse/
+#
+# Modified by René Neumann
#
"""build_manpage command -- Generate man page from setup()"""
@@ -19,17 +21,22 @@ class build_manpage(Command):
user_options = [
('output=', 'O', 'output file'),
('parser=', None, 'module path to optparser (e.g. mymod:func)'),
+ ('seealso=', None, 'list of manpages to put into the SEE ALSO section (e.g. bash:1)')
]
def initialize_options(self):
self.output = None
self.parser = None
+ self.seealso = None
def finalize_options(self):
if self.output is None:
raise DistutilsOptionError('\'output\' option is required')
if self.parser is None:
raise DistutilsOptionError('\'parser\' option is required')
+
+ self.ensure_string_list('seealso')
+
mod_name, func_name = self.parser.split(':')
fromlist = mod_name.split('.')
try:
@@ -46,10 +53,11 @@ class build_manpage(Command):
return txt.replace('-', '\\-')
def _write_header(self):
+ version = self.distribution.get_version()
appname = self.distribution.get_name()
ret = []
- ret.append('.TH %s 1 %s\n' % (self._markup(appname),
- self._today.strftime('%Y\\-%m\\-%d')))
+ ret.append('.TH %s 1 %s "%s v.%s"\n' % (self._markup(appname),
+ self._today.strftime('%Y\\-%m\\-%d'), appname, version))
description = self.distribution.get_description()
if description:
name = self._markup('%s - %s' % (self._markup(appname),
@@ -72,6 +80,21 @@ class build_manpage(Command):
ret.append(self._parser.format_option_help())
return ''.join(ret)
+ def _write_seealso (self):
+ ret = []
+ if self.seealso is not None:
+ ret.append('.SH "SEE ALSO"\n')
+
+ for i in self.seealso:
+ name, sect = i.split(":")
+
+ if len(ret) > 1:
+ ret.append(',\n')
+
+ ret.append('.BR %s (%s)' % (name, sect))
+
+ return ''.join(ret)
+
def _write_footer(self):
ret = []
appname = self.distribution.get_name()
@@ -79,11 +102,11 @@ class build_manpage(Command):
self.distribution.get_author_email())
ret.append(('.SH AUTHORS\n.B %s\nwas written by %s.\n'
% (self._markup(appname), self._markup(author))))
- homepage = self.distribution.get_url()
- ret.append(('.SH DISTRIBUTION\nThe latest version of %s may '
- 'be downloaded from\n'
- '.UR %s\n.UE\n'
- % (self._markup(appname), self._markup(homepage),)))
+ # homepage = self.distribution.get_url()
+ # ret.append(('.SH DISTRIBUTION\nThe latest version of %s may '
+ # 'be downloaded from\n'
+ # '.UR %s\n.UE .\n'
+ # % (self._markup(appname), self._markup(homepage),)))
return ''.join(ret)
def run(self):
@@ -91,6 +114,7 @@ class build_manpage(Command):
manpage.append(self._write_header())
manpage.append(self._write_options())
manpage.append(self._write_footer())
+ manpage.append(self._write_seealso())
stream = open(self.output, 'w')
stream.write(''.join(manpage))
stream.close()