Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Yu Watanabe | db9ecf0 | 2020-11-09 13:23:58 +0900 | [diff] [blame] | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 3 | |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 4 | import argparse |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 5 | import collections |
| 6 | import sys |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 7 | import os |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 8 | import subprocess |
| 9 | import io |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 10 | |
Zbigniew Jędrzejewski-Szmek | 8aaf611 | 2020-09-18 18:51:42 +0200 | [diff] [blame] | 11 | try: |
| 12 | from lxml import etree |
| 13 | except ModuleNotFoundError as e: |
| 14 | etree = e |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 15 | |
Zbigniew Jędrzejewski-Szmek | 198fda4 | 2020-09-20 13:15:44 +0200 | [diff] [blame] | 16 | try: |
| 17 | from shlex import join as shlex_join |
| 18 | except ImportError as e: |
| 19 | shlex_join = e |
| 20 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 21 | class NoCommand(Exception): |
| 22 | pass |
| 23 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 24 | BORING_INTERFACES = [ |
| 25 | 'org.freedesktop.DBus.Peer', |
| 26 | 'org.freedesktop.DBus.Introspectable', |
| 27 | 'org.freedesktop.DBus.Properties', |
| 28 | ] |
| 29 | |
Zbigniew Jędrzejewski-Szmek | 8aaf611 | 2020-09-18 18:51:42 +0200 | [diff] [blame] | 30 | def xml_parser(): |
| 31 | return etree.XMLParser(no_network=True, |
| 32 | remove_comments=False, |
| 33 | strip_cdata=False, |
| 34 | resolve_entities=False) |
| 35 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 36 | def print_method(declarations, elem, *, prefix, file, is_signal=False): |
| 37 | name = elem.get('name') |
| 38 | klass = 'signal' if is_signal else 'method' |
| 39 | declarations[klass].append(name) |
| 40 | |
| 41 | print(f'''{prefix}{name}(''', file=file, end='') |
| 42 | lead = ',\n' + prefix + ' ' * len(name) + ' ' |
| 43 | |
| 44 | for num, arg in enumerate(elem.findall('./arg')): |
| 45 | argname = arg.get('name') |
| 46 | |
| 47 | if argname is None: |
Zbigniew Jędrzejewski-Szmek | 04aa6fa | 2020-08-27 20:15:30 +0200 | [diff] [blame] | 48 | if opts.print_errors: |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 49 | print(f'method {name}: argument {num+1} has no name', file=sys.stderr) |
| 50 | argname = 'UNNAMED' |
| 51 | |
| 52 | type = arg.get('type') |
| 53 | if not is_signal: |
| 54 | direction = arg.get('direction') |
| 55 | print(f'''{lead if num > 0 else ''}{direction:3} {type} {argname}''', file=file, end='') |
| 56 | else: |
| 57 | print(f'''{lead if num > 0 else ''}{type} {argname}''', file=file, end='') |
| 58 | |
| 59 | print(f');', file=file) |
| 60 | |
| 61 | ACCESS_MAP = { |
| 62 | 'read' : 'readonly', |
| 63 | 'write' : 'readwrite', |
| 64 | } |
| 65 | |
| 66 | def value_ellipsis(type): |
| 67 | if type == 's': |
| 68 | return "'...'"; |
| 69 | if type[0] == 'a': |
| 70 | inner = value_ellipsis(type[1:]) |
| 71 | return f"[{inner}{', ...' if inner != '...' else ''}]"; |
| 72 | return '...' |
| 73 | |
| 74 | def print_property(declarations, elem, *, prefix, file): |
| 75 | name = elem.get('name') |
| 76 | type = elem.get('type') |
| 77 | access = elem.get('access') |
| 78 | |
| 79 | declarations['property'].append(name) |
| 80 | |
| 81 | # @org.freedesktop.DBus.Property.EmitsChangedSignal("false") |
| 82 | # @org.freedesktop.systemd1.Privileged("true") |
| 83 | # readwrite b EnableWallMessages = false; |
| 84 | |
| 85 | for anno in elem.findall('./annotation'): |
| 86 | anno_name = anno.get('name') |
| 87 | anno_value = anno.get('value') |
| 88 | print(f'''{prefix}@{anno_name}("{anno_value}")''', file=file) |
| 89 | |
| 90 | access = ACCESS_MAP.get(access, access) |
| 91 | print(f'''{prefix}{access} {type} {name} = {value_ellipsis(type)};''', file=file) |
| 92 | |
Zbigniew Jędrzejewski-Szmek | 08fe1b6 | 2020-04-10 14:46:44 +0200 | [diff] [blame] | 93 | def print_interface(iface, *, prefix, file, print_boring, only_interface, declarations): |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 94 | name = iface.get('name') |
| 95 | |
Zbigniew Jędrzejewski-Szmek | 08fe1b6 | 2020-04-10 14:46:44 +0200 | [diff] [blame] | 96 | is_boring = (name in BORING_INTERFACES or |
| 97 | only_interface is not None and name != only_interface) |
| 98 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 99 | if is_boring and print_boring: |
| 100 | print(f'''{prefix}interface {name} {{ ... }};''', file=file) |
Zbigniew Jędrzejewski-Szmek | 08fe1b6 | 2020-04-10 14:46:44 +0200 | [diff] [blame] | 101 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 102 | elif not is_boring and not print_boring: |
| 103 | print(f'''{prefix}interface {name} {{''', file=file) |
| 104 | prefix2 = prefix + ' ' |
| 105 | |
| 106 | for num, elem in enumerate(iface.findall('./method')): |
| 107 | if num == 0: |
| 108 | print(f'''{prefix2}methods:''', file=file) |
| 109 | print_method(declarations, elem, prefix=prefix2 + ' ', file=file) |
| 110 | |
| 111 | for num, elem in enumerate(iface.findall('./signal')): |
| 112 | if num == 0: |
| 113 | print(f'''{prefix2}signals:''', file=file) |
| 114 | print_method(declarations, elem, prefix=prefix2 + ' ', file=file, is_signal=True) |
| 115 | |
| 116 | for num, elem in enumerate(iface.findall('./property')): |
| 117 | if num == 0: |
| 118 | print(f'''{prefix2}properties:''', file=file) |
| 119 | print_property(declarations, elem, prefix=prefix2 + ' ', file=file) |
| 120 | |
| 121 | print(f'''{prefix}}};''', file=file) |
| 122 | |
| 123 | def document_has_elem_with_text(document, elem, item_repr): |
| 124 | predicate = f".//{elem}" # [text() = 'foo'] doesn't seem supported :( |
| 125 | for loc in document.findall(predicate): |
| 126 | if loc.text == item_repr: |
| 127 | return True |
Yu Watanabe | 45752a2 | 2020-11-20 19:47:11 +0900 | [diff] [blame] | 128 | return False |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 129 | |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 130 | def check_documented(document, declarations, stats): |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 131 | missing = [] |
| 132 | for klass, items in declarations.items(): |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 133 | stats['total'] += len(items) |
| 134 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 135 | for item in items: |
| 136 | if klass == 'method': |
| 137 | elem = 'function' |
| 138 | item_repr = f'{item}()' |
| 139 | elif klass == 'signal': |
| 140 | elem = 'function' |
| 141 | item_repr = item |
| 142 | elif klass == 'property': |
| 143 | elem = 'varname' |
| 144 | item_repr = item |
| 145 | else: |
| 146 | assert False, (klass, item) |
| 147 | |
| 148 | if not document_has_elem_with_text(document, elem, item_repr): |
Zbigniew Jędrzejewski-Szmek | 04aa6fa | 2020-08-27 20:15:30 +0200 | [diff] [blame] | 149 | if opts.print_errors: |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 150 | print(f'{klass} {item} is not documented :(') |
| 151 | missing.append((klass, item)) |
| 152 | |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 153 | stats['missing'] += len(missing) |
| 154 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 155 | return missing |
| 156 | |
Zbigniew Jędrzejewski-Szmek | 08fe1b6 | 2020-04-10 14:46:44 +0200 | [diff] [blame] | 157 | def xml_to_text(destination, xml, *, only_interface=None): |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 158 | file = io.StringIO() |
| 159 | |
| 160 | declarations = collections.defaultdict(list) |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame] | 161 | interfaces = [] |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 162 | |
| 163 | print(f'''node {destination} {{''', file=file) |
| 164 | |
| 165 | for print_boring in [False, True]: |
| 166 | for iface in xml.findall('./interface'): |
| 167 | print_interface(iface, prefix=' ', file=file, |
| 168 | print_boring=print_boring, |
Zbigniew Jędrzejewski-Szmek | 08fe1b6 | 2020-04-10 14:46:44 +0200 | [diff] [blame] | 169 | only_interface=only_interface, |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 170 | declarations=declarations) |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame] | 171 | name = iface.get('name') |
| 172 | if not name in BORING_INTERFACES: |
| 173 | interfaces.append(name) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 174 | |
| 175 | print(f'''}};''', file=file) |
| 176 | |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame] | 177 | return file.getvalue(), declarations, interfaces |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 178 | |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 179 | def subst_output(document, programlisting, stats): |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 180 | executable = programlisting.get('executable', None) |
| 181 | if executable is None: |
| 182 | # Not our thing |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 183 | return |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 184 | executable = programlisting.get('executable') |
| 185 | node = programlisting.get('node') |
| 186 | interface = programlisting.get('interface') |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 187 | |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 188 | argv = [f'{opts.build_dir}/{executable}', f'--bus-introspect={interface}'] |
Zbigniew Jędrzejewski-Szmek | 198fda4 | 2020-09-20 13:15:44 +0200 | [diff] [blame] | 189 | print(f'COMMAND: {shlex_join(argv)}') |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 190 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 191 | try: |
| 192 | out = subprocess.check_output(argv, text=True) |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 193 | except FileNotFoundError: |
| 194 | print(f'{executable} not found, ignoring', file=sys.stderr) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 195 | return |
| 196 | |
Zbigniew Jędrzejewski-Szmek | 8aaf611 | 2020-09-18 18:51:42 +0200 | [diff] [blame] | 197 | xml = etree.fromstring(out, parser=xml_parser()) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 198 | |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 199 | new_text, declarations, interfaces = xml_to_text(node, xml, only_interface=interface) |
| 200 | programlisting.text = '\n' + new_text + ' ' |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 201 | |
| 202 | if declarations: |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 203 | missing = check_documented(document, declarations, stats) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 204 | parent = programlisting.getparent() |
| 205 | |
| 206 | # delete old comments |
| 207 | for child in parent: |
| 208 | if (child.tag == etree.Comment |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame] | 209 | and 'Autogenerated' in child.text): |
| 210 | parent.remove(child) |
| 211 | if (child.tag == etree.Comment |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 212 | and 'not documented' in child.text): |
| 213 | parent.remove(child) |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame] | 214 | if (child.tag == "variablelist" |
| 215 | and child.attrib.get("generated",False) == "True"): |
| 216 | parent.remove(child) |
| 217 | |
| 218 | # insert pointer for systemd-directives generation |
| 219 | the_tail = programlisting.tail #tail is erased by addnext, so save it here. |
| 220 | prev_element = etree.Comment("Autogenerated cross-references for systemd.directives, do not edit") |
| 221 | programlisting.addnext(prev_element) |
| 222 | programlisting.tail = the_tail |
| 223 | |
| 224 | for interface in interfaces: |
| 225 | variablelist = etree.Element("variablelist") |
| 226 | variablelist.attrib['class'] = 'dbus-interface' |
| 227 | variablelist.attrib['generated'] = 'True' |
| 228 | variablelist.attrib['extra-ref'] = interface |
| 229 | |
| 230 | prev_element.addnext(variablelist) |
| 231 | prev_element.tail = the_tail |
| 232 | prev_element = variablelist |
| 233 | |
| 234 | for decl_type,decl_list in declarations.items(): |
| 235 | for declaration in decl_list: |
| 236 | variablelist = etree.Element("variablelist") |
| 237 | variablelist.attrib['class'] = 'dbus-'+decl_type |
| 238 | variablelist.attrib['generated'] = 'True' |
| 239 | if decl_type == 'method' : |
| 240 | variablelist.attrib['extra-ref'] = declaration + '()' |
| 241 | else: |
| 242 | variablelist.attrib['extra-ref'] = declaration |
| 243 | |
| 244 | prev_element.addnext(variablelist) |
| 245 | prev_element.tail = the_tail |
| 246 | prev_element = variablelist |
| 247 | |
| 248 | last_element = etree.Comment("End of Autogenerated section") |
| 249 | prev_element.addnext(last_element) |
| 250 | prev_element.tail = the_tail |
| 251 | last_element.tail = the_tail |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 252 | |
| 253 | # insert comments for undocumented items |
| 254 | for item in reversed(missing): |
| 255 | comment = etree.Comment(f'{item[0]} {item[1]} is not documented!') |
| 256 | comment.tail = programlisting.tail |
| 257 | parent.insert(parent.index(programlisting) + 1, comment) |
| 258 | |
| 259 | def process(page): |
| 260 | src = open(page).read() |
Zbigniew Jędrzejewski-Szmek | 8aaf611 | 2020-09-18 18:51:42 +0200 | [diff] [blame] | 261 | xml = etree.fromstring(src, parser=xml_parser()) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 262 | |
| 263 | # print('parsing {}'.format(name), file=sys.stderr) |
| 264 | if xml.tag != 'refentry': |
| 265 | return |
| 266 | |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 267 | stats = collections.Counter() |
| 268 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 269 | pls = xml.findall('.//programlisting') |
| 270 | for pl in pls: |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 271 | subst_output(xml, pl, stats) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 272 | |
| 273 | out_text = etree.tostring(xml, encoding='unicode') |
Frantisek Sumsal | 86b52a3 | 2020-04-21 20:46:53 +0200 | [diff] [blame] | 274 | # massage format to avoid some lxml whitespace handling idiosyncrasies |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 275 | # https://bugs.launchpad.net/lxml/+bug/526799 |
| 276 | out_text = (src[:src.find('<refentryinfo')] + |
| 277 | out_text[out_text.find('<refentryinfo'):] + |
| 278 | '\n') |
| 279 | |
Zbigniew Jędrzejewski-Szmek | 1b584f3 | 2020-08-27 19:55:55 +0200 | [diff] [blame] | 280 | if not opts.test: |
| 281 | with open(page, 'w') as out: |
| 282 | out.write(out_text) |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 283 | |
Zbigniew Jędrzejewski-Szmek | 1b584f3 | 2020-08-27 19:55:55 +0200 | [diff] [blame] | 284 | return dict(stats=stats, outdated=(out_text != src)) |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 285 | |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 286 | def parse_args(): |
| 287 | p = argparse.ArgumentParser() |
Zbigniew Jędrzejewski-Szmek | 1b584f3 | 2020-08-27 19:55:55 +0200 | [diff] [blame] | 288 | p.add_argument('--test', action='store_true', |
| 289 | help='only verify that everything is up2date') |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 290 | p.add_argument('--build-dir', default='build') |
| 291 | p.add_argument('pages', nargs='+') |
Zbigniew Jędrzejewski-Szmek | 04aa6fa | 2020-08-27 20:15:30 +0200 | [diff] [blame] | 292 | opts = p.parse_args() |
| 293 | opts.print_errors = not opts.test |
| 294 | return opts |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 295 | |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 296 | if __name__ == '__main__': |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 297 | opts = parse_args() |
Zbigniew Jędrzejewski-Szmek | e5dd26c | 2020-04-07 16:58:58 +0200 | [diff] [blame] | 298 | |
Zbigniew Jędrzejewski-Szmek | 198fda4 | 2020-09-20 13:15:44 +0200 | [diff] [blame] | 299 | for item in (etree, shlex_join): |
| 300 | if isinstance(item, Exception): |
| 301 | print(item, file=sys.stderr) |
| 302 | exit(77 if opts.test else 1) |
Zbigniew Jędrzejewski-Szmek | 8aaf611 | 2020-09-18 18:51:42 +0200 | [diff] [blame] | 303 | |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 304 | if not os.path.exists(f'{opts.build_dir}/systemd'): |
| 305 | exit(f"{opts.build_dir}/systemd doesn't exist. Use --build-dir=.") |
Zbigniew Jędrzejewski-Szmek | c351d56 | 2020-04-24 12:09:07 +0200 | [diff] [blame] | 306 | |
Zbigniew Jędrzejewski-Szmek | 0f5cea0 | 2020-08-27 19:27:18 +0200 | [diff] [blame] | 307 | stats = {page.split('/')[-1] : process(page) for page in opts.pages} |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 308 | |
| 309 | # Let's print all statistics at the end |
| 310 | mlen = max(len(page) for page in stats) |
Zbigniew Jędrzejewski-Szmek | 1b584f3 | 2020-08-27 19:55:55 +0200 | [diff] [blame] | 311 | total = sum((item['stats'] for item in stats.values()), start=collections.Counter()) |
| 312 | total = 'total', dict(stats=total, outdated=False) |
| 313 | outdated = [] |
| 314 | for page, info in sorted(stats.items()) + [total]: |
| 315 | m = info['stats']['missing'] |
| 316 | t = info['stats']['total'] |
Zbigniew Jędrzejewski-Szmek | af4c7dc | 2020-08-27 19:21:21 +0200 | [diff] [blame] | 317 | p = page + ':' |
Zbigniew Jędrzejewski-Szmek | 1b584f3 | 2020-08-27 19:55:55 +0200 | [diff] [blame] | 318 | c = 'OUTDATED' if info['outdated'] else '' |
| 319 | if c: |
| 320 | outdated.append(page) |
| 321 | print(f'{p:{mlen + 1}} {t - m}/{t} {c}') |
| 322 | |
| 323 | if opts.test and outdated: |
Zbigniew Jędrzejewski-Szmek | c91e311 | 2020-08-27 20:18:05 +0200 | [diff] [blame] | 324 | exit(f'Outdated pages: {", ".join(outdated)}\n' |
| 325 | f'Hint: ninja -C {opts.build_dir} man/update-dbus-docs') |