Show More
@@ -1,55 +1,55 | |||||
1 | SOURCES=$(wildcard *.[0-9].txt) |
|
1 | SOURCES=$(wildcard *.[0-9].txt) | |
2 | MAN=$(SOURCES:%.txt=%) |
|
2 | MAN=$(SOURCES:%.txt=%) | |
3 | HTML=$(SOURCES:%.txt=%.html) |
|
3 | HTML=$(SOURCES:%.txt=%.html) | |
4 | GENDOC=gendoc.py ../mercurial/commands.py ../mercurial/help.py \ |
|
4 | GENDOC=gendoc.py ../mercurial/commands.py ../mercurial/help.py \ | |
5 | ../mercurial/help/*.txt ../hgext/*.py ../hgext/*/__init__.py |
|
5 | ../mercurial/help/*.txt ../hgext/*.py ../hgext/*/__init__.py | |
6 | PREFIX=/usr/local |
|
6 | PREFIX=/usr/local | |
7 | MANDIR=$(PREFIX)/share/man |
|
7 | MANDIR=$(PREFIX)/share/man | |
8 | INSTALL=install -c -m 644 |
|
8 | INSTALL=install -c -m 644 | |
9 | PYTHON=python |
|
9 | PYTHON=python | |
10 | RSTARGS= |
|
10 | RSTARGS= | |
11 |
|
11 | |||
12 | export LANGUAGE=C |
|
12 | export LANGUAGE=C | |
13 | export LC_ALL=C |
|
13 | export LC_ALL=C | |
14 |
|
14 | |||
15 | all: man html |
|
15 | all: man html | |
16 |
|
16 | |||
17 | man: $(MAN) |
|
17 | man: $(MAN) | |
18 |
|
18 | |||
19 | html: $(HTML) |
|
19 | html: $(HTML) | |
20 |
|
20 | |||
21 | hg.1.txt: hg.1.gendoc.txt |
|
21 | hg.1.txt: hg.1.gendoc.txt | |
22 | touch hg.1.txt |
|
22 | touch hg.1.txt | |
23 |
|
23 | |||
24 | hg.1.gendoc.txt: $(GENDOC) |
|
24 | hg.1.gendoc.txt: $(GENDOC) | |
25 | ${PYTHON} gendoc.py > $@.tmp |
|
25 | ${PYTHON} gendoc.py hg.1.gendoc > $@.tmp | |
26 | mv $@.tmp $@ |
|
26 | mv $@.tmp $@ | |
27 |
|
27 | |||
28 | hgrc.5: ../mercurial/help/config.txt |
|
28 | hgrc.5: ../mercurial/help/config.txt | |
29 |
|
29 | |||
30 | hgrc.5.html: ../mercurial/help/config.txt |
|
30 | hgrc.5.html: ../mercurial/help/config.txt | |
31 |
|
31 | |||
32 | %: %.txt common.txt |
|
32 | %: %.txt common.txt | |
33 | $(PYTHON) runrst hgmanpage $(RSTARGS) --halt warning \ |
|
33 | $(PYTHON) runrst hgmanpage $(RSTARGS) --halt warning \ | |
34 | --strip-elements-with-class htmlonly $*.txt $* |
|
34 | --strip-elements-with-class htmlonly $*.txt $* | |
35 |
|
35 | |||
36 | %.html: %.txt common.txt |
|
36 | %.html: %.txt common.txt | |
37 | $(PYTHON) runrst html $(RSTARGS) --halt warning \ |
|
37 | $(PYTHON) runrst html $(RSTARGS) --halt warning \ | |
38 | --link-stylesheet --stylesheet-path style.css $*.txt $*.html |
|
38 | --link-stylesheet --stylesheet-path style.css $*.txt $*.html | |
39 |
|
39 | |||
40 | MANIFEST: man html |
|
40 | MANIFEST: man html | |
41 | # tracked files are already in the main MANIFEST |
|
41 | # tracked files are already in the main MANIFEST | |
42 | $(RM) $@ |
|
42 | $(RM) $@ | |
43 | for i in $(MAN) $(HTML); do \ |
|
43 | for i in $(MAN) $(HTML); do \ | |
44 | echo "doc/$$i" >> $@ ; \ |
|
44 | echo "doc/$$i" >> $@ ; \ | |
45 | done |
|
45 | done | |
46 |
|
46 | |||
47 | install: man |
|
47 | install: man | |
48 | for i in $(MAN) ; do \ |
|
48 | for i in $(MAN) ; do \ | |
49 | subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \ |
|
49 | subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \ | |
50 | mkdir -p $(DESTDIR)$(MANDIR)/$$subdir ; \ |
|
50 | mkdir -p $(DESTDIR)$(MANDIR)/$$subdir ; \ | |
51 | $(INSTALL) $$i $(DESTDIR)$(MANDIR)/$$subdir ; \ |
|
51 | $(INSTALL) $$i $(DESTDIR)$(MANDIR)/$$subdir ; \ | |
52 | done |
|
52 | done | |
53 |
|
53 | |||
54 | clean: |
|
54 | clean: | |
55 | $(RM) $(MAN) $(HTML) hg.1.gendoc.txt MANIFEST |
|
55 | $(RM) $(MAN) $(HTML) hg.1.gendoc.txt MANIFEST |
@@ -1,171 +1,183 | |||||
|
1 | """usage: %s DOC ... | |||
|
2 | ||||
|
3 | where DOC is the name of a document | |||
|
4 | """ | |||
|
5 | ||||
1 | import os, sys, textwrap |
|
6 | import os, sys, textwrap | |
2 | # import from the live mercurial repo |
|
7 | # import from the live mercurial repo | |
3 | sys.path.insert(0, "..") |
|
8 | sys.path.insert(0, "..") | |
4 | # fall back to pure modules if required C extensions are not available |
|
9 | # fall back to pure modules if required C extensions are not available | |
5 | sys.path.append(os.path.join('..', 'mercurial', 'pure')) |
|
10 | sys.path.append(os.path.join('..', 'mercurial', 'pure')) | |
6 | from mercurial import demandimport; demandimport.enable() |
|
11 | from mercurial import demandimport; demandimport.enable() | |
7 | from mercurial import minirst |
|
12 | from mercurial import minirst | |
8 | from mercurial.commands import table, globalopts |
|
13 | from mercurial.commands import table, globalopts | |
9 | from mercurial.i18n import gettext, _ |
|
14 | from mercurial.i18n import gettext, _ | |
10 | from mercurial.help import helptable, loaddoc |
|
15 | from mercurial.help import helptable, loaddoc | |
11 | from mercurial import extensions |
|
16 | from mercurial import extensions | |
12 | from mercurial import util |
|
17 | from mercurial import util | |
13 |
|
18 | |||
14 | def get_desc(docstr): |
|
19 | def get_desc(docstr): | |
15 | if not docstr: |
|
20 | if not docstr: | |
16 | return "", "" |
|
21 | return "", "" | |
17 | # sanitize |
|
22 | # sanitize | |
18 | docstr = docstr.strip("\n") |
|
23 | docstr = docstr.strip("\n") | |
19 | docstr = docstr.rstrip() |
|
24 | docstr = docstr.rstrip() | |
20 | shortdesc = docstr.splitlines()[0].strip() |
|
25 | shortdesc = docstr.splitlines()[0].strip() | |
21 |
|
26 | |||
22 | i = docstr.find("\n") |
|
27 | i = docstr.find("\n") | |
23 | if i != -1: |
|
28 | if i != -1: | |
24 | desc = docstr[i + 2:] |
|
29 | desc = docstr[i + 2:] | |
25 | else: |
|
30 | else: | |
26 | desc = shortdesc |
|
31 | desc = shortdesc | |
27 |
|
32 | |||
28 | desc = textwrap.dedent(desc) |
|
33 | desc = textwrap.dedent(desc) | |
29 |
|
34 | |||
30 | return (shortdesc, desc) |
|
35 | return (shortdesc, desc) | |
31 |
|
36 | |||
32 | def get_opts(opts): |
|
37 | def get_opts(opts): | |
33 | for opt in opts: |
|
38 | for opt in opts: | |
34 | if len(opt) == 5: |
|
39 | if len(opt) == 5: | |
35 | shortopt, longopt, default, desc, optlabel = opt |
|
40 | shortopt, longopt, default, desc, optlabel = opt | |
36 | else: |
|
41 | else: | |
37 | shortopt, longopt, default, desc = opt |
|
42 | shortopt, longopt, default, desc = opt | |
38 | allopts = [] |
|
43 | allopts = [] | |
39 | if shortopt: |
|
44 | if shortopt: | |
40 | allopts.append("-%s" % shortopt) |
|
45 | allopts.append("-%s" % shortopt) | |
41 | if longopt: |
|
46 | if longopt: | |
42 | allopts.append("--%s" % longopt) |
|
47 | allopts.append("--%s" % longopt) | |
43 | desc += default and _(" (default: %s)") % default or "" |
|
48 | desc += default and _(" (default: %s)") % default or "" | |
44 | yield (", ".join(allopts), desc) |
|
49 | yield (", ".join(allopts), desc) | |
45 |
|
50 | |||
46 | def get_cmd(cmd, cmdtable): |
|
51 | def get_cmd(cmd, cmdtable): | |
47 | d = {} |
|
52 | d = {} | |
48 | attr = cmdtable[cmd] |
|
53 | attr = cmdtable[cmd] | |
49 | cmds = cmd.lstrip("^").split("|") |
|
54 | cmds = cmd.lstrip("^").split("|") | |
50 |
|
55 | |||
51 | d['cmd'] = cmds[0] |
|
56 | d['cmd'] = cmds[0] | |
52 | d['aliases'] = cmd.split("|")[1:] |
|
57 | d['aliases'] = cmd.split("|")[1:] | |
53 | d['desc'] = get_desc(gettext(attr[0].__doc__)) |
|
58 | d['desc'] = get_desc(gettext(attr[0].__doc__)) | |
54 | d['opts'] = list(get_opts(attr[1])) |
|
59 | d['opts'] = list(get_opts(attr[1])) | |
55 |
|
60 | |||
56 | s = 'hg ' + cmds[0] |
|
61 | s = 'hg ' + cmds[0] | |
57 | if len(attr) > 2: |
|
62 | if len(attr) > 2: | |
58 | if not attr[2].startswith('hg'): |
|
63 | if not attr[2].startswith('hg'): | |
59 | s += ' ' + attr[2] |
|
64 | s += ' ' + attr[2] | |
60 | else: |
|
65 | else: | |
61 | s = attr[2] |
|
66 | s = attr[2] | |
62 | d['synopsis'] = s.strip() |
|
67 | d['synopsis'] = s.strip() | |
63 |
|
68 | |||
64 | return d |
|
69 | return d | |
65 |
|
70 | |||
66 | def showdoc(ui): |
|
71 | def showdoc(ui): | |
67 | # print options |
|
72 | # print options | |
68 | ui.write(minirst.section(_("Options"))) |
|
73 | ui.write(minirst.section(_("Options"))) | |
69 | for optstr, desc in get_opts(globalopts): |
|
74 | for optstr, desc in get_opts(globalopts): | |
70 | ui.write("%s\n %s\n\n" % (optstr, desc)) |
|
75 | ui.write("%s\n %s\n\n" % (optstr, desc)) | |
71 |
|
76 | |||
72 | # print cmds |
|
77 | # print cmds | |
73 | ui.write(minirst.section(_("Commands"))) |
|
78 | ui.write(minirst.section(_("Commands"))) | |
74 | commandprinter(ui, table, minirst.subsection) |
|
79 | commandprinter(ui, table, minirst.subsection) | |
75 |
|
80 | |||
76 | # print help topics |
|
81 | # print help topics | |
77 | # The config help topic is included in the hgrc.5 man page. |
|
82 | # The config help topic is included in the hgrc.5 man page. | |
78 | helpprinter(ui, helptable, minirst.section, exclude=['config']) |
|
83 | helpprinter(ui, helptable, minirst.section, exclude=['config']) | |
79 |
|
84 | |||
80 | ui.write(minirst.section(_("Extensions"))) |
|
85 | ui.write(minirst.section(_("Extensions"))) | |
81 | ui.write(_("This section contains help for extensions that are " |
|
86 | ui.write(_("This section contains help for extensions that are " | |
82 | "distributed together with Mercurial. Help for other " |
|
87 | "distributed together with Mercurial. Help for other " | |
83 | "extensions is available in the help system.")) |
|
88 | "extensions is available in the help system.")) | |
84 | ui.write("\n\n" |
|
89 | ui.write("\n\n" | |
85 | ".. contents::\n" |
|
90 | ".. contents::\n" | |
86 | " :class: htmlonly\n" |
|
91 | " :class: htmlonly\n" | |
87 | " :local:\n" |
|
92 | " :local:\n" | |
88 | " :depth: 1\n\n") |
|
93 | " :depth: 1\n\n") | |
89 |
|
94 | |||
90 | for extensionname in sorted(allextensionnames()): |
|
95 | for extensionname in sorted(allextensionnames()): | |
91 | mod = extensions.load(None, extensionname, None) |
|
96 | mod = extensions.load(None, extensionname, None) | |
92 | ui.write(minirst.subsection(extensionname)) |
|
97 | ui.write(minirst.subsection(extensionname)) | |
93 | ui.write("%s\n\n" % gettext(mod.__doc__)) |
|
98 | ui.write("%s\n\n" % gettext(mod.__doc__)) | |
94 | cmdtable = getattr(mod, 'cmdtable', None) |
|
99 | cmdtable = getattr(mod, 'cmdtable', None) | |
95 | if cmdtable: |
|
100 | if cmdtable: | |
96 | ui.write(minirst.subsubsection(_('Commands'))) |
|
101 | ui.write(minirst.subsubsection(_('Commands'))) | |
97 | commandprinter(ui, cmdtable, minirst.subsubsubsection) |
|
102 | commandprinter(ui, cmdtable, minirst.subsubsubsection) | |
98 |
|
103 | |||
99 | def showtopic(ui, topic): |
|
104 | def showtopic(ui, topic): | |
100 | extrahelptable = [ |
|
105 | extrahelptable = [ | |
101 | (["common"], '', loaddoc('common')), |
|
106 | (["common"], '', loaddoc('common')), | |
102 | (["hg.1"], '', loaddoc('hg.1')), |
|
107 | (["hg.1"], '', loaddoc('hg.1')), | |
103 | (["hgignore.5"], '', loaddoc('hgignore.5')), |
|
108 | (["hgignore.5"], '', loaddoc('hgignore.5')), | |
104 | (["hgrc.5"], '', loaddoc('hgrc.5')), |
|
109 | (["hgrc.5"], '', loaddoc('hgrc.5')), | |
105 | (["hgignore.5.gendoc"], '', loaddoc('hgignore')), |
|
110 | (["hgignore.5.gendoc"], '', loaddoc('hgignore')), | |
106 | (["hgrc.5.gendoc"], '', loaddoc('config')), |
|
111 | (["hgrc.5.gendoc"], '', loaddoc('config')), | |
107 | ] |
|
112 | ] | |
108 | helpprinter(ui, helptable + extrahelptable, None, include=[topic]) |
|
113 | helpprinter(ui, helptable + extrahelptable, None, include=[topic]) | |
109 |
|
114 | |||
110 | def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): |
|
115 | def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): | |
111 | for names, sec, doc in helptable: |
|
116 | for names, sec, doc in helptable: | |
112 | if exclude and names[0] in exclude: |
|
117 | if exclude and names[0] in exclude: | |
113 | continue |
|
118 | continue | |
114 | if include and names[0] not in include: |
|
119 | if include and names[0] not in include: | |
115 | continue |
|
120 | continue | |
116 | for name in names: |
|
121 | for name in names: | |
117 | ui.write(".. _%s:\n" % name) |
|
122 | ui.write(".. _%s:\n" % name) | |
118 | ui.write("\n") |
|
123 | ui.write("\n") | |
119 | if sectionfunc: |
|
124 | if sectionfunc: | |
120 | ui.write(sectionfunc(sec)) |
|
125 | ui.write(sectionfunc(sec)) | |
121 | if util.safehasattr(doc, '__call__'): |
|
126 | if util.safehasattr(doc, '__call__'): | |
122 | doc = doc() |
|
127 | doc = doc() | |
123 | ui.write(doc) |
|
128 | ui.write(doc) | |
124 | ui.write("\n") |
|
129 | ui.write("\n") | |
125 |
|
130 | |||
126 | def commandprinter(ui, cmdtable, sectionfunc): |
|
131 | def commandprinter(ui, cmdtable, sectionfunc): | |
127 | h = {} |
|
132 | h = {} | |
128 | for c, attr in cmdtable.items(): |
|
133 | for c, attr in cmdtable.items(): | |
129 | f = c.split("|")[0] |
|
134 | f = c.split("|")[0] | |
130 | f = f.lstrip("^") |
|
135 | f = f.lstrip("^") | |
131 | h[f] = c |
|
136 | h[f] = c | |
132 | cmds = h.keys() |
|
137 | cmds = h.keys() | |
133 | cmds.sort() |
|
138 | cmds.sort() | |
134 |
|
139 | |||
135 | for f in cmds: |
|
140 | for f in cmds: | |
136 | if f.startswith("debug"): |
|
141 | if f.startswith("debug"): | |
137 | continue |
|
142 | continue | |
138 | d = get_cmd(h[f], cmdtable) |
|
143 | d = get_cmd(h[f], cmdtable) | |
139 | ui.write(sectionfunc(d['cmd'])) |
|
144 | ui.write(sectionfunc(d['cmd'])) | |
140 | # synopsis |
|
145 | # synopsis | |
141 | ui.write("::\n\n") |
|
146 | ui.write("::\n\n") | |
142 | synopsislines = d['synopsis'].splitlines() |
|
147 | synopsislines = d['synopsis'].splitlines() | |
143 | for line in synopsislines: |
|
148 | for line in synopsislines: | |
144 | # some commands (such as rebase) have a multi-line |
|
149 | # some commands (such as rebase) have a multi-line | |
145 | # synopsis |
|
150 | # synopsis | |
146 | ui.write(" %s\n" % line) |
|
151 | ui.write(" %s\n" % line) | |
147 | ui.write('\n') |
|
152 | ui.write('\n') | |
148 | # description |
|
153 | # description | |
149 | ui.write("%s\n\n" % d['desc'][1]) |
|
154 | ui.write("%s\n\n" % d['desc'][1]) | |
150 | # options |
|
155 | # options | |
151 | opt_output = list(d['opts']) |
|
156 | opt_output = list(d['opts']) | |
152 | if opt_output: |
|
157 | if opt_output: | |
153 | opts_len = max([len(line[0]) for line in opt_output]) |
|
158 | opts_len = max([len(line[0]) for line in opt_output]) | |
154 | ui.write(_("Options:\n\n")) |
|
159 | ui.write(_("Options:\n\n")) | |
155 | for optstr, desc in opt_output: |
|
160 | for optstr, desc in opt_output: | |
156 | if desc: |
|
161 | if desc: | |
157 | s = "%-*s %s" % (opts_len, optstr, desc) |
|
162 | s = "%-*s %s" % (opts_len, optstr, desc) | |
158 | else: |
|
163 | else: | |
159 | s = optstr |
|
164 | s = optstr | |
160 | ui.write("%s\n" % s) |
|
165 | ui.write("%s\n" % s) | |
161 | ui.write("\n") |
|
166 | ui.write("\n") | |
162 | # aliases |
|
167 | # aliases | |
163 | if d['aliases']: |
|
168 | if d['aliases']: | |
164 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) |
|
169 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) | |
165 |
|
170 | |||
166 |
|
171 | |||
167 | def allextensionnames(): |
|
172 | def allextensionnames(): | |
168 | return extensions.enabled().keys() + extensions.disabled().keys() |
|
173 | return extensions.enabled().keys() + extensions.disabled().keys() | |
169 |
|
174 | |||
170 | if __name__ == "__main__": |
|
175 | if __name__ == "__main__": | |
171 | showdoc(sys.stdout) |
|
176 | doc = 'hg.1.gendoc' | |
|
177 | if len(sys.argv) > 1: | |||
|
178 | doc = sys.argv[1] | |||
|
179 | ||||
|
180 | if doc == 'hg.1.gendoc': | |||
|
181 | showdoc(sys.stdout) | |||
|
182 | else: | |||
|
183 | showtopic(sys.stdout, sys.argv[1]) |
General Comments 0
You need to be logged in to leave comments.
Login now