##// END OF EJS Templates
gendoc: fall back to pure modules if C extensions are not available (issue1711)
Cédric Duval -
r9130:335f749c default
parent child Browse files
Show More
@@ -1,112 +1,114 b''
1 import sys, textwrap
1 import os, sys, textwrap
2 2 # import from the live mercurial repo
3 3 sys.path.insert(0, "..")
4 # fall back to pure modules if required C extensions are not available
5 sys.path.append(os.path.join('..', 'mercurial', 'pure'))
4 6 from mercurial import demandimport; demandimport.enable()
5 7 from mercurial.commands import table, globalopts
6 8 from mercurial.i18n import gettext, _
7 9 from mercurial.help import helptable
8 10
9 11 def get_desc(docstr):
10 12 if not docstr:
11 13 return "", ""
12 14 # sanitize
13 15 docstr = docstr.strip("\n")
14 16 docstr = docstr.rstrip()
15 17 shortdesc = docstr.splitlines()[0].strip()
16 18
17 19 i = docstr.find("\n")
18 20 if i != -1:
19 21 desc = docstr[i+2:]
20 22 else:
21 23 desc = " %s" % shortdesc
22 24 return (shortdesc, desc)
23 25
24 26 def get_opts(opts):
25 27 for shortopt, longopt, default, desc in opts:
26 28 allopts = []
27 29 if shortopt:
28 30 allopts.append("-%s" % shortopt)
29 31 if longopt:
30 32 allopts.append("--%s" % longopt)
31 33 desc += default and _(" (default: %s)") % default or ""
32 34 yield(", ".join(allopts), desc)
33 35
34 36 def get_cmd(cmd):
35 37 d = {}
36 38 attr = table[cmd]
37 39 cmds = cmd.lstrip("^").split("|")
38 40
39 41 d['cmd'] = cmds[0]
40 42 d['aliases'] = cmd.split("|")[1:]
41 43 d['desc'] = get_desc(attr[0].__doc__)
42 44 d['opts'] = list(get_opts(attr[1]))
43 45
44 46 s = 'hg ' + cmds[0]
45 47 if len(attr) > 2:
46 48 if not attr[2].startswith('hg'):
47 49 s += ' ' + attr[2]
48 50 else:
49 51 s = attr[2]
50 52 d['synopsis'] = s
51 53
52 54 return d
53 55
54 56 def show_doc(ui):
55 57 def bold(s, text=""):
56 58 ui.write("%s\n%s\n%s\n" % (s, "="*len(s), text))
57 59 def underlined(s, text=""):
58 60 ui.write("%s\n%s\n%s\n" % (s, "-"*len(s), text))
59 61
60 62 # print options
61 63 underlined(_("OPTIONS"))
62 64 for optstr, desc in get_opts(globalopts):
63 65 ui.write("%s::\n %s\n\n" % (optstr, desc))
64 66
65 67 # print cmds
66 68 underlined(_("COMMANDS"))
67 69 h = {}
68 70 for c, attr in table.items():
69 71 f = c.split("|")[0]
70 72 f = f.lstrip("^")
71 73 h[f] = c
72 74 cmds = h.keys()
73 75 cmds.sort()
74 76
75 77 for f in cmds:
76 78 if f.startswith("debug"): continue
77 79 d = get_cmd(h[f])
78 80 # synopsis
79 81 ui.write("[[%s]]\n" % d['cmd'])
80 82 ui.write("%s::\n" % d['synopsis'].replace("hg ","", 1))
81 83 # description
82 84 ui.write("%s\n\n" % d['desc'][1])
83 85 # options
84 86 opt_output = list(d['opts'])
85 87 if opt_output:
86 88 opts_len = max([len(line[0]) for line in opt_output])
87 89 ui.write(_(" options:\n"))
88 90 for optstr, desc in opt_output:
89 91 if desc:
90 92 s = "%-*s %s" % (opts_len, optstr, desc)
91 93 else:
92 94 s = optstr
93 95 s = textwrap.fill(s, initial_indent=4 * " ",
94 96 subsequent_indent=(6 + opts_len) * " ")
95 97 ui.write("%s\n" % s)
96 98 ui.write("\n")
97 99 # aliases
98 100 if d['aliases']:
99 101 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
100 102
101 103 # print topics
102 104 for names, section, doc in helptable:
103 105 underlined(gettext(section).upper())
104 106 if callable(doc):
105 107 doc = doc()
106 108 else:
107 109 doc = gettext(doc)
108 110 ui.write(doc)
109 111 ui.write("\n")
110 112
111 113 if __name__ == "__main__":
112 114 show_doc(sys.stdout)
General Comments 0
You need to be logged in to leave comments. Login now