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