annotate doc/check-seclevel.py @ 35850:079b27b5a869

patch: avoid repeated binary checks if all files in a patch are text Differential Revision: https://phab.mercurial-scm.org/D1940
author Joerg Sonnenberger <joerg@bec.de>
date Thu, 25 Jan 2018 22:40:19 +0100
parents e9f456183402
children 9c6473d2038b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
28965
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
5 from __future__ import absolute_import
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
6
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
7 import optparse
28965
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
8 import os
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
9 import sys
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
10
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
11 # 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
12 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
13 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
14 from mercurial import demandimport; demandimport.enable()
28965
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
15 from mercurial import (
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
16 commands,
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
17 extensions,
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
18 help,
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
19 minirst,
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
20 ui as uimod,
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
21 )
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
22
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
23 table = commands.table
98153441c8cc py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27770
diff changeset
24 helptable = help.helptable
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
25
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
26 level2mark = [b'"', b'=', b'-', b'.', b'#']
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
27 reservedmarks = [b'"']
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
28
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
29 mark2level = {}
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
30 for m, l in zip(level2mark, range(len(level2mark))):
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
31 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
32 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
33
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
34 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
35 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
36 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
37 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
38
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
39 def showavailables(ui, initlevel):
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
40 avail = (' available marks and order of them in this help: %s\n') % (
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
41 ', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]]))
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
42 ui.warn(avail.encode('utf-8'))
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
43
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
44 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
45 ui.note(('checking "%s"\n') % name)
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
46 if not isinstance(doc, bytes):
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
47 doc = doc.encode('utf-8')
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
48 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
49 errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
50 curlevel = initlevel
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
51 for block in blocks:
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
52 if block[b'type'] != b'section':
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
53 continue
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
54 mark = block[b'underline']
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
55 title = block[b'lines'][0]
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
56 if (mark not in mark2level) or (mark2level[mark] <= initlevel):
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
57 ui.warn((('invalid section mark %r for "%s" of %s\n') %
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
58 (mark * 4, title, name)).encode('utf-8'))
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
59 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
60 errorcnt += 1
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
61 continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
62 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
63 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
64 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
65 (title, name))
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
66 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
67 errorcnt += 1
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
68 continue
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
69 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
70 (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
71 curlevel = nextlevel
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
72
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
73 return errorcnt
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
74
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
75 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
76 errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
77 for k, entry in cmdtable.items():
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
78 name = k.split(b"|")[0].lstrip(b"^")
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
79 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
80 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
81 (namefmt % name))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
82 continue
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, 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
84 namefmt % name,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
85 initlevel)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
86 return errorcnt
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
87
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
88 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
89 errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
90 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
91 if callable(doc):
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26411
diff changeset
92 doc = doc(ui)
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
93 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
94 '%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
95 initlevel_topic)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
96
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
97 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
98
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
99 for name in sorted(list(extensions.enabled()) +
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
100 list(extensions.disabled())):
27511
44a596a8bed1 check-seclevel: pass a ui to the extension loader
Bryan O'Sullivan <bos@serpentine.com>
parents: 27510
diff changeset
101 mod = extensions.load(ui, name, None)
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
102 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
103 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
104 continue
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
105 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
106 '%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
107 initlevel_ext)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
108
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
109 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
110 if cmdtable:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
111 errorcnt += checkcmdtable(ui, cmdtable,
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
112 '%%s command of %s extension' % name,
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
113 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
114 return errorcnt
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 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
117 if filename == '-':
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
118 filename = 'stdin'
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
119 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
120 else:
27770
1b8c7d59be43 check-seclevel: use a context manager for file I/O
Bryan O'Sullivan <bryano@fb.com>
parents: 27511
diff changeset
121 with open(filename) as fp:
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
122 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
123
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
124 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
125 (filename, initlevel))
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
126 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
127
26398
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
128 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
129 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
130
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
131 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
132 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
133 option.
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("-v", "--verbose",
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
136 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
137 action="store_true")
27510
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
138 optparser.add_option("-d", "--debug",
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
139 help="debug mode",
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
140 action="store_true")
17648
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("-f", "--file",
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
142 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
143 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
144
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
158 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
159 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
160 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
161
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
162 (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
163
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28965
diff changeset
164 ui = uimod.ui.load()
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
165 ui.setconfig('ui', 'verbose', options.verbose, '--verbose')
27510
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
166 ui.setconfig('ui', 'debug', options.debug, '--debug')
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
167
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
168 if options.file:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
169 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
170 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
171 else:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
172 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
173 sys.exit(1)
26398
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
174
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
175 if __name__ == "__main__":
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
176 main()