]> kaliko git repositories - python-musicpdaio.git/blob - doc/extract_supported_commands.py
Update documentation
[python-musicpdaio.git] / doc / extract_supported_commands.py
1 #!/usr/bin/python3
2 import re
3 import sys
4
5 START = 'self._commands = {'
6 END = '}'
7
8 def find_start(fd):
9     line = fd.readline()
10     while START not in line:
11         line = fd.readline()
12         if not line:
13             break
14     if not line:
15         print('Reach end of file!', file=sys.stderr)
16         sys.exit(1)
17
18
19 def main():
20     with open('mpdaio/client.py', 'r', encoding='utf-8') as fd:
21         # fast forward to find self._commands
22         find_start(fd)
23         cmd_patt = '"(?P<command>.*)":'
24         tit_patt = '# ?(?P<title>.*)'
25         cmd_regex = re.compile(cmd_patt)
26         tit_regex = re.compile(tit_patt)
27         # Now extract supported commands
28         line = 'foo'
29         while line and END not in line:
30             line = fd.readline()
31             cmd = cmd_regex.search(line)
32             tit = tit_regex.search(line)
33             if tit:
34                 print(f'\n{tit[1]}')
35                 print('^'*len(tit[1]))
36             if cmd:
37                 print(f'* {cmd[1]}')
38
39
40 if __name__ == '__main__':
41     main()