##// END OF EJS Templates
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler -
r32544:e9f45618 default
parent child Browse files
Show More
@@ -23,11 +23,11 b' from mercurial import ('
23 23 table = commands.table
24 24 helptable = help.helptable
25 25
26 level2mark = ['"', '=', '-', '.', '#']
27 reservedmarks = ['"']
26 level2mark = [b'"', b'=', b'-', b'.', b'#']
27 reservedmarks = [b'"']
28 28
29 29 mark2level = {}
30 for m, l in zip(level2mark, xrange(len(level2mark))):
30 for m, l in zip(level2mark, range(len(level2mark))):
31 31 if m not in reservedmarks:
32 32 mark2level[m] = l
33 33
@@ -37,22 +37,25 b' initlevel_ext = 1'
37 37 initlevel_ext_cmd = 3
38 38
39 39 def showavailables(ui, initlevel):
40 ui.warn((' available marks and order of them in this help: %s\n') %
41 (', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]])))
40 avail = (' available marks and order of them in this help: %s\n') % (
41 ', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1:]]))
42 ui.warn(avail.encode('utf-8'))
42 43
43 44 def checkseclevel(ui, doc, name, initlevel):
44 45 ui.note(('checking "%s"\n') % name)
46 if not isinstance(doc, bytes):
47 doc = doc.encode('utf-8')
45 48 blocks, pruned = minirst.parse(doc, 0, ['verbose'])
46 49 errorcnt = 0
47 50 curlevel = initlevel
48 51 for block in blocks:
49 if block['type'] != 'section':
52 if block[b'type'] != b'section':
50 53 continue
51 mark = block['underline']
52 title = block['lines'][0]
54 mark = block[b'underline']
55 title = block[b'lines'][0]
53 56 if (mark not in mark2level) or (mark2level[mark] <= initlevel):
54 ui.warn(('invalid section mark %r for "%s" of %s\n') %
55 (mark * 4, title, name))
57 ui.warn((('invalid section mark %r for "%s" of %s\n') %
58 (mark * 4, title, name)).encode('utf-8'))
56 59 showavailables(ui, initlevel)
57 60 errorcnt += 1
58 61 continue
@@ -72,7 +75,7 b' def checkseclevel(ui, doc, name, initlev'
72 75 def checkcmdtable(ui, cmdtable, namefmt, initlevel):
73 76 errorcnt = 0
74 77 for k, entry in cmdtable.items():
75 name = k.split("|")[0].lstrip("^")
78 name = k.split(b"|")[0].lstrip(b"^")
76 79 if not entry[0].__doc__:
77 80 ui.note(('skip checking %s: no help document\n') %
78 81 (namefmt % name))
@@ -93,8 +96,8 b' def checkhghelps(ui):'
93 96
94 97 errorcnt += checkcmdtable(ui, table, '%s command', initlevel_cmd)
95 98
96 for name in sorted(extensions.enabled().keys() +
97 extensions.disabled().keys()):
99 for name in sorted(list(extensions.enabled()) +
100 list(extensions.disabled())):
98 101 mod = extensions.load(ui, name, None)
99 102 if not mod.__doc__:
100 103 ui.note(('skip checking %s extension: no help document\n') % name)
@@ -106,7 +109,7 b' def checkhghelps(ui):'
106 109 cmdtable = getattr(mod, 'cmdtable', None)
107 110 if cmdtable:
108 111 errorcnt += checkcmdtable(ui, cmdtable,
109 '%s command of ' + name + ' extension',
112 '%%s command of %s extension' % name,
110 113 initlevel_ext_cmd)
111 114 return errorcnt
112 115
General Comments 0
You need to be logged in to leave comments. Login now