author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
Wed, 09 Dec 2015 08:28:53 +0900 | |
changeset 27289 | ee33e677f0ac |
parent 27221 | ab776610fc6d |
child 27510 | 020d93c4a727 |
permissions | -rwxr-xr-x |
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 |
27221
ab776610fc6d
check-seclevel: set module load policy to Python only
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26413
diff
changeset
|
9 |
os.environ['HGMODULEPOLICY'] = 'py' |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
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
|
14 |
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
|
15 |
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
|
16 |
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
|
17 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
18 |
level2mark = ['"', '=', '-', '.', '#'] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
19 |
reservedmarks = ['"'] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
20 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
21 |
mark2level = {} |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
31 |
def showavailables(ui, initlevel): |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
32 |
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
|
33 |
(', '.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
|
34 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 |
curlevel = initlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 |
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
|
41 |
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
|
42 |
continue |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
(mark * 4, title, name)) |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
48 |
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
|
49 |
errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
50 |
continue |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
(title, name)) |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
55 |
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
|
56 |
errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 |
continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
58 |
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
|
59 |
(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
|
60 |
curlevel = nextlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
61 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
62 |
return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
63 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
64 |
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
|
65 |
errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
(namefmt % name)) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 |
continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
72 |
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
|
73 |
namefmt % name, |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
74 |
initlevel) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
75 |
return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
76 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
77 |
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
|
78 |
errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
79 |
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
|
80 |
if callable(doc): |
26413
e0c572d4d112
help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents:
26411
diff
changeset
|
81 |
doc = doc(ui) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
82 |
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
|
83 |
'%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
|
84 |
initlevel_topic) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
85 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
86 |
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
|
87 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
continue |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
94 |
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
|
95 |
'%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
|
96 |
initlevel_ext) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
97 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
98 |
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
|
99 |
if cmdtable: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
100 |
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
|
101 |
'%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
|
102 |
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
|
103 |
return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
104 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
105 |
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
|
106 |
if filename == '-': |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
107 |
filename = 'stdin' |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
108 |
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
|
109 |
else: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
110 |
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
|
111 |
try: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
112 |
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
|
113 |
finally: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
114 |
fp.close() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
115 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
116 |
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
|
117 |
(filename, initlevel)) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
118 |
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
|
119 |
|
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
option. |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
126 |
""") |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
151 |
(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
|
152 |
|
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
153 |
ui = uimod.ui() |
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
154 |
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
|
155 |
|
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
156 |
if options.file: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
157 |
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
|
158 |
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
|
159 |
else: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
160 |
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
|
161 |
sys.exit(1) |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
162 |
|
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
163 |
if __name__ == "__main__": |
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
164 |
main() |