Mercurial > hg-stable
annotate doc/check-seclevel.py @ 26896:5e46123e6c35
error: add structured exception for EOF at prompt
We'll catch this exception for promptchoice queries to provide better error
handling.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 10 Nov 2015 00:46:45 -0800 |
parents | e0c572d4d112 |
children | ab776610fc6d |
rev | line source |
---|---|
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 # |
26192
67e6e55360d2
check-seclevel: fix file description grammar
timeless@mozdev.org
parents:
21792
diff
changeset
|
3 # checkseclevel - checking section title levels in each online help document |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
5 import sys, os |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 import optparse |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 # import from the live mercurial repo |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 sys.path.insert(0, "..") |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 # fall back to pure modules if required C extensions are not available |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
11 sys.path.append(os.path.join('..', 'mercurial', 'pure')) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
12 from mercurial import demandimport; demandimport.enable() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
13 from mercurial.commands import table |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
14 from mercurial.help import helptable |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
15 from mercurial import extensions |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
16 from mercurial import minirst |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
17 from mercurial import ui as uimod |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
18 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
19 level2mark = ['"', '=', '-', '.', '#'] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
20 reservedmarks = ['"'] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
21 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
22 mark2level = {} |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
23 for m, l in zip(level2mark, xrange(len(level2mark))): |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
24 if m not in reservedmarks: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
25 mark2level[m] = l |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
27 initlevel_topic = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
28 initlevel_cmd = 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 initlevel_ext = 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
30 initlevel_ext_cmd = 3 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
31 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
32 def showavailables(ui, initlevel): |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
33 ui.warn((' available marks and order of them in this help: %s\n') % |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
34 (', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]]))) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
36 def checkseclevel(ui, doc, name, initlevel): |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
37 ui.note(('checking "%s"\n') % name) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 blocks, pruned = minirst.parse(doc, 0, ['verbose']) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 curlevel = initlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
41 for block in blocks: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
42 if block['type'] != 'section': |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
43 continue |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
44 mark = block['underline'] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
45 title = block['lines'][0] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
46 if (mark not in mark2level) or (mark2level[mark] <= initlevel): |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
47 ui.warn(('invalid section mark %r for "%s" of %s\n') % |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
48 (mark * 4, title, name)) |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
49 showavailables(ui, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
50 errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
51 continue |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
52 nextlevel = mark2level[mark] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
53 if curlevel < nextlevel and curlevel + 1 != nextlevel: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
54 ui.warn(('gap of section level at "%s" of %s\n') % |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
55 (title, name)) |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
56 showavailables(ui, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
58 continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
59 ui.note(('appropriate section level for "%s %s"\n') % |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
60 (mark * (nextlevel * 2), title)) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
61 curlevel = nextlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
62 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
63 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
64 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
65 def checkcmdtable(ui, cmdtable, namefmt, initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
66 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
67 for k, entry in cmdtable.items(): |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
68 name = k.split("|")[0].lstrip("^") |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 if not entry[0].__doc__: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
70 ui.note(('skip checking %s: no help document\n') % |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 (namefmt % name)) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
72 continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
73 errorcnt += checkseclevel(ui, entry[0].__doc__, |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
74 namefmt % name, |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
75 initlevel) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
76 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
77 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
78 def checkhghelps(ui): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
79 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
80 for names, sec, doc in helptable: |
21792
e15c991fe2ec
check-seclevel: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
17648
diff
changeset
|
81 if callable(doc): |
26413
e0c572d4d112
help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents:
26411
diff
changeset
|
82 doc = doc(ui) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
83 errorcnt += checkseclevel(ui, doc, |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
84 '%s help topic' % names[0], |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
85 initlevel_topic) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
86 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
87 errorcnt += checkcmdtable(ui, table, '%s command', initlevel_cmd) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
88 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
89 for name in sorted(extensions.enabled().keys() + |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
90 extensions.disabled().keys()): |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
91 mod = extensions.load(None, name, None) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
92 if not mod.__doc__: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
93 ui.note(('skip checking %s extension: no help document\n') % name) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
94 continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
95 errorcnt += checkseclevel(ui, mod.__doc__, |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
96 '%s extension' % name, |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
97 initlevel_ext) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
98 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
99 cmdtable = getattr(mod, 'cmdtable', None) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
100 if cmdtable: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
101 errorcnt += checkcmdtable(ui, cmdtable, |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
102 '%s command of ' + name + ' extension', |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
103 initlevel_ext_cmd) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
104 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
105 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
106 def checkfile(ui, filename, initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
107 if filename == '-': |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
108 filename = 'stdin' |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
109 doc = sys.stdin.read() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
110 else: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
111 fp = open(filename) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
112 try: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
113 doc = fp.read() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
114 finally: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
115 fp.close() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
116 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
117 ui.note(('checking input from %s with initlevel %d\n') % |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
118 (filename, initlevel)) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
119 return checkseclevel(ui, doc, 'input from %s' % filename, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
120 |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
121 def main(): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
122 optparser = optparse.OptionParser("""%prog [options] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
123 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
124 This checks all help documents of Mercurial (topics, commands, |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
125 extensions and commands of them), if no file is specified by --file |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
126 option. |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
127 """) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
128 optparser.add_option("-v", "--verbose", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
129 help="enable additional output", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
130 action="store_true") |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
131 optparser.add_option("-f", "--file", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
132 help="filename to read in (or '-' for stdin)", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
133 action="store", default="") |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
134 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
135 optparser.add_option("-t", "--topic", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
136 help="parse file as help topic", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
137 action="store_const", dest="initlevel", const=0) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
138 optparser.add_option("-c", "--command", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
139 help="parse file as help of core command", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
140 action="store_const", dest="initlevel", const=1) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
141 optparser.add_option("-e", "--extension", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
142 help="parse file as help of extension", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
143 action="store_const", dest="initlevel", const=1) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
144 optparser.add_option("-C", "--extension-command", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
145 help="parse file as help of extension command", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
146 action="store_const", dest="initlevel", const=3) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
147 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
148 optparser.add_option("-l", "--initlevel", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
149 help="set initial section level manually", |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
150 action="store", type="int", default=0) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
151 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
152 (options, args) = optparser.parse_args() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
153 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
154 ui = uimod.ui() |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
155 ui.setconfig('ui', 'verbose', options.verbose, '--verbose') |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
156 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
157 if options.file: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
158 if checkfile(ui, options.file, options.initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
159 sys.exit(1) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
160 else: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
161 if checkhghelps(ui): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
162 sys.exit(1) |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
163 |
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
164 if __name__ == "__main__": |
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
165 main() |