File: makeman.py

package info (click to toggle)
zim 0.65-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,816 kB
  • ctags: 6,779
  • sloc: python: 54,978; xml: 1,137; makefile: 45; sh: 35
file content (73 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python

# -*- coding: utf-8 -*-

# Copyright 2009 Jaap Karssenberg <jaap.karssenberg@gmail.com>

import os

from time import strftime, gmtime, time
from locale import setlocale, LC_TIME

from zim import __version__, __url__, \
	__author__, __copyright__, __license__
from zim.main import HelpCommand


def get_about():
	'''Get the tagline and short description from the README'''
	readme = open('README.txt')
	lines = []
	for line in readme:
		if line.startswith('===') and 'ABOUT' in line:
			for line in readme:
				if line.startswith('==='):
					break
				else:
					lines.append(line)
			break

	lines = ''.join(lines).strip().splitlines(True)
	assert lines and lines[0].startswith('Zim - ')
	tagline = lines[0][6:].strip()
	about = ''.join(lines[1:]).strip()

	return tagline, about


def make():
	'''Generate man page for zim'''

	tagline, about = get_about()
	try:
		os.mkdir('man')
	except OSError:
		pass # dir already exists
	setlocale(LC_TIME, "C")
	manpage = open('man/zim.1', 'w')
	manpage.write('.TH ZIM "1" "%s" "zim %s" "User Commands"\n' % (strftime('%B %Y', gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time())))), __version__))
	manpage.write('.SH NAME\nzim \\- %s\n\n' % tagline)
	manpage.write('.SH SYNOPSIS\n%s\n' % HelpCommand.usagehelp.replace('-', r'\-'))
	manpage.write('.SH DESCRIPTION\n%s\n' % about)
	manpage.write('.SH OPTIONS\n%s\n' % HelpCommand.optionhelp.replace('-', r'\-'))
	manpage.write('.SH AUTHOR\n%s\n\n' % __author__)
	manpage.write( '''\
.SH "SEE ALSO"
The full documentation for
.B zim
is maintained as a zim notebook. The command
.IP
.B zim --manual
.PP
should give you access to the complete manual.

The website for
.B zim
can be found at
.I %s
''' % __url__)
	manpage.close()


if __name__ == '__main__':
	make()