Show More
@@ -14,15 +14,7 b' from mercurial.commands import table' | |||
|
14 | 14 | from mercurial.help import helptable |
|
15 | 15 | from mercurial import extensions |
|
16 | 16 | from mercurial import minirst |
|
17 | ||
|
18 | _verbose = False | |
|
19 | ||
|
20 | def verbose(msg): | |
|
21 | if _verbose: | |
|
22 | print msg | |
|
23 | ||
|
24 | def error(msg): | |
|
25 | sys.stderr.write('%s\n' % msg) | |
|
17 | from mercurial import ui as uimod | |
|
26 | 18 | |
|
27 | 19 | level2mark = ['"', '=', '-', '.', '#'] |
|
28 | 20 | reservedmarks = ['"'] |
@@ -37,12 +29,12 b' initlevel_cmd = 1' | |||
|
37 | 29 | initlevel_ext = 1 |
|
38 | 30 | initlevel_ext_cmd = 3 |
|
39 | 31 | |
|
40 | def showavailables(initlevel): | |
|
41 |
|
|
|
42 | (', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]]))) | |
|
32 | def showavailables(ui, initlevel): | |
|
33 | ui.warn((' available marks and order of them in this help: %s\n') % | |
|
34 | (', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]]))) | |
|
43 | 35 | |
|
44 | def checkseclevel(doc, name, initlevel): | |
|
45 |
|
|
|
36 | def checkseclevel(ui, doc, name, initlevel): | |
|
37 | ui.note(('checking "%s"\n') % name) | |
|
46 | 38 | blocks, pruned = minirst.parse(doc, 0, ['verbose']) |
|
47 | 39 | errorcnt = 0 |
|
48 | 40 | curlevel = initlevel |
@@ -52,66 +44,66 b' def checkseclevel(doc, name, initlevel):' | |||
|
52 | 44 | mark = block['underline'] |
|
53 | 45 | title = block['lines'][0] |
|
54 | 46 | if (mark not in mark2level) or (mark2level[mark] <= initlevel): |
|
55 |
|
|
|
56 | (mark * 4, title, name)) | |
|
57 | showavailables(initlevel) | |
|
47 | ui.warn(('invalid section mark %r for "%s" of %s\n') % | |
|
48 | (mark * 4, title, name)) | |
|
49 | showavailables(ui, initlevel) | |
|
58 | 50 | errorcnt += 1 |
|
59 | 51 | continue |
|
60 | 52 | nextlevel = mark2level[mark] |
|
61 | 53 | if curlevel < nextlevel and curlevel + 1 != nextlevel: |
|
62 |
|
|
|
63 | (title, name)) | |
|
64 | showavailables(initlevel) | |
|
54 | ui.warn(('gap of section level at "%s" of %s\n') % | |
|
55 | (title, name)) | |
|
56 | showavailables(ui, initlevel) | |
|
65 | 57 | errorcnt += 1 |
|
66 | 58 | continue |
|
67 |
|
|
|
59 | ui.note(('appropriate section level for "%s %s"\n') % | |
|
68 | 60 | (mark * (nextlevel * 2), title)) |
|
69 | 61 | curlevel = nextlevel |
|
70 | 62 | |
|
71 | 63 | return errorcnt |
|
72 | 64 | |
|
73 | def checkcmdtable(cmdtable, namefmt, initlevel): | |
|
65 | def checkcmdtable(ui, cmdtable, namefmt, initlevel): | |
|
74 | 66 | errorcnt = 0 |
|
75 | 67 | for k, entry in cmdtable.items(): |
|
76 | 68 | name = k.split("|")[0].lstrip("^") |
|
77 | 69 | if not entry[0].__doc__: |
|
78 |
|
|
|
70 | ui.note(('skip checking %s: no help document\n') % | |
|
79 | 71 | (namefmt % name)) |
|
80 | 72 | continue |
|
81 | errorcnt += checkseclevel(entry[0].__doc__, | |
|
73 | errorcnt += checkseclevel(ui, entry[0].__doc__, | |
|
82 | 74 | namefmt % name, |
|
83 | 75 | initlevel) |
|
84 | 76 | return errorcnt |
|
85 | 77 | |
|
86 | def checkhghelps(): | |
|
78 | def checkhghelps(ui): | |
|
87 | 79 | errorcnt = 0 |
|
88 | 80 | for names, sec, doc in helptable: |
|
89 | 81 | if callable(doc): |
|
90 | 82 | doc = doc() |
|
91 | errorcnt += checkseclevel(doc, | |
|
83 | errorcnt += checkseclevel(ui, doc, | |
|
92 | 84 | '%s help topic' % names[0], |
|
93 | 85 | initlevel_topic) |
|
94 | 86 | |
|
95 | errorcnt += checkcmdtable(table, '%s command', initlevel_cmd) | |
|
87 | errorcnt += checkcmdtable(ui, table, '%s command', initlevel_cmd) | |
|
96 | 88 | |
|
97 | 89 | for name in sorted(extensions.enabled().keys() + |
|
98 | 90 | extensions.disabled().keys()): |
|
99 | 91 | mod = extensions.load(None, name, None) |
|
100 | 92 | if not mod.__doc__: |
|
101 |
|
|
|
93 | ui.note(('skip checking %s extension: no help document\n') % name) | |
|
102 | 94 | continue |
|
103 | errorcnt += checkseclevel(mod.__doc__, | |
|
95 | errorcnt += checkseclevel(ui, mod.__doc__, | |
|
104 | 96 | '%s extension' % name, |
|
105 | 97 | initlevel_ext) |
|
106 | 98 | |
|
107 | 99 | cmdtable = getattr(mod, 'cmdtable', None) |
|
108 | 100 | if cmdtable: |
|
109 | errorcnt += checkcmdtable(cmdtable, | |
|
101 | errorcnt += checkcmdtable(ui, cmdtable, | |
|
110 | 102 | '%s command of ' + name + ' extension', |
|
111 | 103 | initlevel_ext_cmd) |
|
112 | 104 | return errorcnt |
|
113 | 105 | |
|
114 | def checkfile(filename, initlevel): | |
|
106 | def checkfile(ui, filename, initlevel): | |
|
115 | 107 | if filename == '-': |
|
116 | 108 | filename = 'stdin' |
|
117 | 109 | doc = sys.stdin.read() |
@@ -122,9 +114,9 b' def checkfile(filename, initlevel):' | |||
|
122 | 114 | finally: |
|
123 | 115 | fp.close() |
|
124 | 116 | |
|
125 |
|
|
|
117 | ui.note(('checking input from %s with initlevel %d\n') % | |
|
126 | 118 | (filename, initlevel)) |
|
127 | return checkseclevel(doc, 'input from %s' % filename, initlevel) | |
|
119 | return checkseclevel(ui, doc, 'input from %s' % filename, initlevel) | |
|
128 | 120 | |
|
129 | 121 | def main(): |
|
130 | 122 | optparser = optparse.OptionParser("""%prog [options] |
@@ -159,14 +151,14 b' option.' | |||
|
159 | 151 | |
|
160 | 152 | (options, args) = optparser.parse_args() |
|
161 | 153 | |
|
162 | global _verbose | |
|
163 | _verbose = options.verbose | |
|
154 | ui = uimod.ui() | |
|
155 | ui.setconfig('ui', 'verbose', options.verbose, '--verbose') | |
|
164 | 156 | |
|
165 | 157 | if options.file: |
|
166 | if checkfile(options.file, options.initlevel): | |
|
158 | if checkfile(ui, options.file, options.initlevel): | |
|
167 | 159 | sys.exit(1) |
|
168 | 160 | else: |
|
169 | if checkhghelps(): | |
|
161 | if checkhghelps(ui): | |
|
170 | 162 | sys.exit(1) |
|
171 | 163 | |
|
172 | 164 | if __name__ == "__main__": |
General Comments 0
You need to be logged in to leave comments.
Login now