File: cmd_tools.py

package info (click to toggle)
pychopper 2.7.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 110,288 kB
  • sloc: python: 1,200; makefile: 233; sh: 45
file content (56 lines) | stat: -rwxr-xr-x 1,552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3

"""Helper script to generate cmd_line.rst file for all scripts in bin which
have and parser object defined in their global scope - taken from tang

"""
from __future__ import print_function
import sys
import os
import imp

scripts_rel = 'scripts'
attr_name = 'parser'
blacklist = ['__init__.py']

location = os.path.join(os.path.dirname(os.path.abspath(__file__)),'..')
scripts_abs = os.path.join(location, scripts_rel)
scripts = sorted(filter(lambda s: s[0] != '.' and s not in blacklist, os.listdir(scripts_abs)))

sys.stderr.write("Found following scripts:\n{}\n{}\n{}\n".format(
    location, scripts_abs, scripts
))


print ("""
.. _command_line_tools:

Command line tools
==================
""")

for script in scripts:
    script_name, script_ext = os.path.splitext(script)
    if script_ext == '.pyc':
        continue
    
    try:
        mod_name = '{}.{}'.format(scripts_rel, script_name)
        #mod = __import__(mod_name, globals(), locals(), [attr_name])
        mod = imp.load_source(script_name, os.path.join(scripts_abs, script))
        script = script.replace('.py', '')

        print ('.. _{}:\n\n{}\n{}'.format(script, script, '-'*len(script)))
        if hasattr(mod, attr_name):
            print ("""
.. argparse::
   :ref: {}.{}
   :prog: {}
""".format(mod_name, attr_name, script_name))
        else:
            print('No documentation available')

    except Exception as e:
        # Wha' yer' gonna do?
        sys.stderr.write('Error making docs for {}:\n{}\n'.format(script_name, e))
        pass