doc/check-seclevel.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 13 Aug 2012 21:25:48 +0900
changeset 17648 07f1ac17b722
child 21792 e15c991fe2ec
permissions -rw-r--r--
doc: add the tool to check section marks in help documents This patch adds "doc/check-seclevel.py" which checks below in help documents: - whether unknown or unavailable section marks are used or not - whether appropriate section mark is used at sub-sectioning It should be invoked in "doc" directory. It checks all help documents of Mercurial (topics, commands, extensions), if no file is specified by --file option. With --file option, it checks contents of the specified file as help document, for self testing purpose: -t/-c/-e/-C are used to specify what kind of help document contents of the specified file is. This checking is related to changeset 979b107eaea2.
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
#
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
# checkseclevel - checking section title levels in each online help documents
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
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    17
from mercurial import util
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
_verbose = False
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
def verbose(msg):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    22
    if _verbose:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    23
        print msg
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    24
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    25
def error(msg):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    26
    sys.stderr.write('%s\n' % msg)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    27
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    28
level2mark = ['"', '=', '-', '.', '#']
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    29
reservedmarks = ['"']
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    30
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    31
mark2level = {}
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    32
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
    33
    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
    34
        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
    35
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    36
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
    37
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
    38
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
    39
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
    40
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    41
def showavailables(initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    42
    error('    available marks and order of them in this help: %s' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    43
          (', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]])))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    44
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    45
def checkseclevel(doc, name, initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    46
    verbose('checking "%s"' % name)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    47
    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
    48
    errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    49
    curlevel = initlevel
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    50
    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
    51
        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
    52
            continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    53
        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
    54
        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
    55
        if (mark not in mark2level) or (mark2level[mark] <= initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    56
            error('invalid section mark %r for "%s" of %s' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    57
                  (mark * 4, title, name))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    58
            showavailables(initlevel)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    59
            errorcnt += 1
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    60
            continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    61
        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
    62
        if curlevel < nextlevel and curlevel + 1 != nextlevel:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    63
            error('gap of section level at "%s" of %s' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    64
                  (title, name))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    65
            showavailables(initlevel)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    66
            errorcnt += 1
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    67
            continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    68
        verbose('appropriate section level for "%s %s"' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    69
                (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
    70
        curlevel = nextlevel
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    71
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    72
    return errorcnt
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    73
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    74
def checkcmdtable(cmdtable, namefmt, initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    75
    errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    76
    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
    77
        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
    78
        if not entry[0].__doc__:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    79
            verbose('skip checking %s: no help document' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    80
                    (namefmt % name))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    81
            continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    82
        errorcnt += checkseclevel(entry[0].__doc__,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    83
                                  namefmt % name,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    84
                                  initlevel)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    85
    return errorcnt
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    86
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    87
def checkhghelps():
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    88
    errorcnt = 0
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    89
    for names, sec, doc in helptable:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    90
        if util.safehasattr(doc, '__call__'):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    91
            doc = doc()
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    92
        errorcnt += checkseclevel(doc,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    93
                                  '%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
    94
                                  initlevel_topic)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    95
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    96
    errorcnt += checkcmdtable(table, '%s command', initlevel_cmd)
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
    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
    99
                       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
   100
        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
   101
        if not mod.__doc__:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   102
            verbose('skip checking %s extension: no help document' % name)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   103
            continue
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   104
        errorcnt += checkseclevel(mod.__doc__,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   105
                                  '%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
   106
                                  initlevel_ext)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   107
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   108
        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
   109
        if cmdtable:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   110
            errorcnt += checkcmdtable(cmdtable,
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   111
                                      '%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
   112
                                      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
   113
    return errorcnt
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   114
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   115
def checkfile(filename, initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   116
    if filename == '-':
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   117
        filename = 'stdin'
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   118
        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
   119
    else:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   120
        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
   121
        try:
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
        finally:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   124
            fp.close()
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   125
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   126
    verbose('checking input from %s with initlevel %d' %
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   127
            (filename, initlevel))
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   128
    return checkseclevel(doc, 'input from %s' % filename, initlevel)
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   129
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   130
if __name__ == "__main__":
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   131
    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
   132
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   133
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
   134
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
   135
option.
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   136
""")
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("-v", "--verbose",
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   138
                         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
   139
                         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
   140
    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
   141
                         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
   142
                         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
   143
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("-t", "--topic",
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 topic",
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=0)
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("-c", "--command",
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   148
                         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
   149
                         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
   150
    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
   151
                         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
   152
                         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
   153
    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
   154
                         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
   155
                         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
   156
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   157
    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
   158
                         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
   159
                         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
   160
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   161
    (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
   162
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   163
    _verbose = options.verbose
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   164
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   165
    if options.file:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   166
        if checkfile(options.file, options.initlevel):
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   167
            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
   168
    else:
07f1ac17b722 doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   169
        if checkhghelps():
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)