/
create-man-index
executable file
·125 lines (113 loc) · 4.47 KB
/
create-man-index
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
from os.path import basename
import sys
def render_cmd(subcmd, page_dir, indent):
cmd_name = 'bup ' + subcmd if subcmd else 'bup'
subcmd_name = subcmd and subcmd.split()[0] or None
page_name = 'bup-' + subcmd_name if subcmd_name else 'bup'
print('%s<li><a href="%s/%s.html">%s</a></li>'
% ((' ' * indent), page_dir, page_name, cmd_name))
def render_sections(sections, other, requested_cmds, page_dir, indent=0):
rendered = set()
for section in sections:
sec_name, cmds = section
print('%s<h3>%s</h3>' % ((' ' * indent), sec_name))
print('%s<ul>' % (' ' * indent))
for cmd in cmds:
cmd_name = cmd and cmd.split()[0] or None
if cmd_name not in requested_cmds:
continue
render_cmd(cmd, page_dir, indent + 2)
rendered.add(cmd_name)
print('%s</ul>' % (' ' * indent))
remaining_cmds = requested_cmds - rendered
if remaining_cmds:
print('%s<h3>%s</h3>' % ((' ' * indent), other))
print('%s<ul>' % (' ' * indent))
for cmd in sorted(remaining_cmds):
render_cmd(cmd, page_dir, indent + 2)
print('%s</ul>' % (' ' * indent))
def cmd_from_html_path(x):
assert(x.endswith('.html'))
base = basename(x)
assert(base.startswith('bup-') or base == 'bup.html')
return base[4:-5] or None
# Usage: create-man-index DIR_CONTAINING_HTML_PAGES HTML_PAGES_TO_INCLUDE...
# e.g. create-man-index man $(git ls-files 'man/*.html')
version = sys.argv[1]
page_dir = sys.argv[2]
pages = sys.argv[3:]
print("""<!doctype html>'
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>bup man pages</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="javascripts/jquery-1.7.1.min.js"></script>
<script src="javascripts/respond.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 8]>
<link rel="stylesheet" href="stylesheets/ie.css">
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
<body>
<div id="header">
<nav>
<li class="fork"><a href="https://github.com/bup/bup">SOURCE</a></li>
<li class="downloads"><a href="https://github.com/bup/bup/zipball/%(version)s">ZIP</a></li>
<li class="downloads"><a href="https://github.com/bup/bup/tarball/%(version)s">TAR</a></li>
<li class="title">RELEASE (%(version)s)</li>
</nav>
</div><!-- end header -->
<div class="wrapper">
<section>
<div id="title">
<h1>bup</h1>
<p>Very efficient backup system based on the git packfile format, providing fast incremental saves and global deduplication (among and within files, including virtual machine images).</p>
<hr>
<span class="credits left">Contact us on the <a href="https://groups.google.com/forum/#!forum/bup-list">mailing list</a></span>
<span class="credits right">Theme by <a href="https://twitter.com/michigangraham">mattgraham</a></span>
</div>""" % {'version' : version})
known_sections = [['Common operations',
[None,
'help',
'init',
'fsck',
'tag',
'version']],
['Inspection',
['ls',
'fuse',
'web',
'ftp']],
['Save and restore',
['index',
'on [HOST index]',
'save',
'on [HOST save]',
'restore']],
['Split and join',
['split',
'join']],
['Importing data',
['import-duplicity',
'import-rdiff-backup',
'import-rsnapshot']],
['Pruning old data (destructive)',
['rm',
'gc',
'prune-older']]]
requested_cmds = frozenset((cmd_from_html_path(x) for x in pages))
render_sections(known_sections, 'Others', requested_cmds, page_dir, 8)
print("""
</section>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>
""")