File: extract_docstrings.py

package info (click to toggle)
offpunk 3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,012 kB
  • sloc: python: 6,263; sh: 117; makefile: 2
file content (15 lines) | stat: -rwxr-xr-x 574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3
import ast
import sys
f = open('../offpunk.py', "r") #filename input
module = ast.parse(f.read())

class_definitions = [node for node in module.body if isinstance(node, ast.ClassDef)]
for class_def in class_definitions:
        function_definitions = [node for node in class_def.body if isinstance(node, ast.FunctionDef)]
        for f in function_definitions:
            if f.name.startswith('do_'):
                docstring = ast.get_docstring(f)
                if docstring is not None:
                    print('_(\n"""'+docstring+'\"""\n)')