X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=doc%2Fextract_supported_commands.py;fp=doc%2Fextract_supported_commands.py;h=d6a728322fc65365523578a9a69ea63169419d78;hb=a1bb332d045c1c375ad2fa331476ee95d964017c;hp=0000000000000000000000000000000000000000;hpb=254daf50788d3d8c7cd7fdec407560cdda633b35;p=python-musicpdaio.git diff --git a/doc/extract_supported_commands.py b/doc/extract_supported_commands.py new file mode 100644 index 0000000..d6a7283 --- /dev/null +++ b/doc/extract_supported_commands.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +import re +import sys + +START = 'self._commands = {' +END = '}' + +def find_start(fd): + line = fd.readline() + while START not in line: + line = fd.readline() + if not line: + break + if not line: + print('Reach end of file!', file=sys.stderr) + sys.exit(1) + + +def main(): + with open('mpdaio/client.py', 'r', encoding='utf-8') as fd: + # fast forward to find self._commands + find_start(fd) + cmd_patt = '"(?P.*)":' + tit_patt = '# ?(?P.*)' + cmd_regex = re.compile(cmd_patt) + tit_regex = re.compile(tit_patt) + # Now extract supported commands + line = 'foo' + while line and END not in line: + line = fd.readline() + cmd = cmd_regex.search(line) + tit = tit_regex.search(line) + if tit: + print(f'\n{tit[1]}') + print('^'*len(tit[1])) + if cmd: + print(f'* {cmd[1]}') + + +if __name__ == '__main__': + main()