doc/check-seclevel.py
author Matt Harbison <matt_harbison@yahoo.com>
Thu, 23 May 2019 21:39:19 -0400
branchstable
changeset 42376 89c0c8edc9d4
parent 41355 77763dc5b07b
child 43076 2372284d9457
permissions -rwxr-xr-x
tests: demonstrate broken manifest generation with the pure module This will be fixed next. But I don't fully understand how 'b.txt' is actually removed properly in the second test, given what's broken. Also, I'm not sure why 'bb.txt' is flagged as not being in the manifest, when it clearly appears to be.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
40292
9c6473d2038b help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents: 32544
diff changeset
    90
    for h in helptable:
9c6473d2038b help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents: 32544
diff changeset
    91
        names, sec, doc = h[0:3]
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
    92
        if callable(doc):
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26411
diff changeset
    93
            doc = doc(ui)
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, 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 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
    96
                                  initlevel_topic)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    97
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
    98
    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
    99
32544
e9f456183402 doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents: 30559
diff changeset
   100
    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
   101
                       list(extensions.disabled())):
27511
44a596a8bed1 check-seclevel: pass a ui to the extension loader
Bryan O'Sullivan <bos@serpentine.com>
parents: 27510
diff changeset
   102
        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
   103
        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
   104
            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
   105
            continue
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   106
        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
   107
                                  '%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
   108
                                  initlevel_ext)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   109
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   110
        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
   111
        if cmdtable:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   112
            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
   113
                                      '%%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
   114
                                      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
   115
    return errorcnt
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
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
   118
    if filename == '-':
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   119
        filename = 'stdin'
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   120
        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
   121
    else:
27770
1b8c7d59be43 check-seclevel: use a context manager for file I/O
Bryan O'Sullivan <bryano@fb.com>
parents: 27511
diff changeset
   122
        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
   123
            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
   124
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   125
    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
   126
            (filename, initlevel))
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   127
    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
   128
26398
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
   129
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
   130
    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
   131
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   132
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
   133
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
   134
option.
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   135
""")
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   136
    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
   137
                         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
   138
                         action="store_true")
27510
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
   139
    optparser.add_option("-d", "--debug",
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
   140
                         help="debug mode",
020d93c4a727 check-seclevel: add a --debug option
Bryan O'Sullivan <bos@serpentine.com>
parents: 27221
diff changeset
   141
                         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
   142
    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
   143
                         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
   144
                         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
   145
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   146
    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
   147
                         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
   148
                         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
   149
    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
   150
                         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
   151
                         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
   152
    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
   153
                         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
   154
                         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
   155
    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
   156
                         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
   157
                         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
   158
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   159
    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
   160
                         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
   161
                         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
   162
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   163
    (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
   164
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28965
diff changeset
   165
    ui = uimod.ui.load()
41355
77763dc5b07b py3: add b'' prefixes in doc/check-seclevel.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40292
diff changeset
   166
    ui.setconfig(b'ui', b'verbose', options.verbose, b'--verbose')
77763dc5b07b py3: add b'' prefixes in doc/check-seclevel.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40292
diff changeset
   167
    ui.setconfig(b'ui', b'debug', options.debug, b'--debug')
17648
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   168
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   169
    if options.file:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   170
        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
   171
            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
   172
    else:
26411
dd62eaa82cbe check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents: 26398
diff changeset
   173
        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
   174
            sys.exit(1)
26398
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
   175
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
   176
if __name__ == "__main__":
70abba798098 check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents: 26192
diff changeset
   177
    main()