-
Notifications
You must be signed in to change notification settings - Fork 31
/
make_docs.py
87 lines (67 loc) · 1.76 KB
/
make_docs.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import bips
import os
import tempfile
from tools.interfacedocgen import help
from nipype.utils.misc import trim
from bips.workflows.base import save_config
base_dir = os.path.abspath('doc/workflows/generated')
workflows = bips.workflows.get_workflows()
container='generated'
all_wf_path = os.path.join(base_dir,"all.rst")
all_wf = open(all_wf_path,'w')
title=""".. AUTO-GENERATED FILE -- DO NOT EDIT!
.. toctree::
:maxdepth: 1
"""
all_wf.write(title)
config="""Config
^^^^^^
"""
tags="""
Tags
^^^^
"""
Uuid="""uuid: """
def write_graph_section(fname):
ad="""Graph
^^^^^
"""
ad += '.. graphviz::\n\n'
fhandle = open(fname)
for line in fhandle:
ad += '\t' + line + '\n'
fhandle.close()
os.remove(fname)
os.remove(fname + ".png")
return ad
for wf in workflows:
uuid = wf[0]
mwf = wf[1]["object"]
fname = os.path.join(base_dir,"uuid_"+uuid+'.rst')
print fname
foo = open(fname,'w')
foo.write(mwf.help)
foo.write(Uuid)
foo.write(uuid+'\n')
foo.write(tags)
for t in mwf.tags:
foo.write('* '+t+'\n')
foo.write(config)
cls = mwf.config_ui()
jsonname = 'doc/configs/%s.txt'%uuid
jsonname = save_config(cls,jsonname)
foo.write(""":download:`download <../../configs/%s>`\n\n"""%(os.path.split(jsonname)[1]))
foo.write(trim(help(cls,True))+'\n')
(_,graphname) = tempfile.mkstemp(suffix=".dot")
try:
mwf.workflow_function(mwf.config_ui()).write_graph(dotfilename=graphname,graph2use="orig")
graph = write_graph_section(graphname) + '\n'
foo.write(graph)
except TypeError:
pass
#except:
# print "There is some error :("
foo.close()
all_wf.write(" "+container+'/'+"uuid_"+uuid+'.rst'+'\n')
all_wf.close()
print "done"