1 from os.path import dirname, join
2 from rst import Rest, Paragraph, Strong, OrderedListItem, ListItem, Title, Link, Transition
3 from rst import Directive, Em, Quote, Text
4 from tiramisu.option import *
5 from tiramisu.config import *
6 #from makerestdoc import *
8 docdir = join(dirname(__file__), 'build')
10 def make_rst_file(filename, rstcontent):
11 fh = file(filename, 'w')
12 fh.write(rstcontent.text())
15 def descr_content(path, prefix, descr, root=False):
17 title = Title(abovechar="", belowchar="=")
19 title.join(Text("Configuration's overview for: "), Quote(descr._name))
21 title.join(Text("Group's overview for: "), Quote(descr._name))
23 content.add(ListItem().join(Strong("name:"), Text(descr._name)))
25 content.add(ListItem().join(Strong("path:"), Text(path)))
26 content.add(ListItem().join(Strong("description:"), Text(descr.doc)))
28 content.add(ListItem().join(Strong("container:"), Text(prefix)))
30 content.add(ListItem().join(Strong("type:"), Text(descr.group_type)))
32 content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
33 content.add(ListItem().join(Strong("is hidden:"), Text(str(descr._is_hidden()))))
34 content.add(ListItem().join(Strong("is disabled:"), Text(str(descr._is_disabled()))))
35 content.add(Transition())
36 content.add(Title(abovechar="", belowchar="-").join(Text("Ordered list of childrens for:"), Text(path)))
37 for opt in descr._children:
39 link = Link(name + ":", join(path + '.' + name + ".html"))
40 # because of SympLink opt
41 if hasattr(opt, 'doc'):
45 content.add(OrderedListItem(link, Text(opt.doc)))
46 content.add(Transition())
47 content.add(Paragraph(Link("back to index", "index.html")))
48 make_rst_file(join(docdir, path + '.txt'), content)
50 make_rst_file(join(docdir, 'index.txt'), content)
52 def opt_rst_content(path, prefix, descr, value):
54 title = Title(abovechar="", belowchar="=")
55 title.join(Text("Configuration's option overview for: "), Quote(descr._name))
57 content.add(ListItem().join(Strong("name:"), Text(descr._name)))
58 content.add(ListItem().join(Strong("value:"), Text(str(value))))
59 content.add(ListItem().join(Strong("path:"), Text(path)))
60 content.add(ListItem().join(Strong("container:"), Text(prefix)))
61 if isinstance(descr, ChoiceOption):
62 content.add(ListItem().join(Strong("possible values:"), Text(str(descr.values))))
63 if not isinstance(descr, SymLinkOption):
64 content.add(ListItem().join(Strong("type:"), Text(str(descr.opt_type))))
65 content.add(ListItem().join(Strong("default:"), Text(str(descr.getdefault()))))
66 content.add(ListItem().join(Strong("description:"), Text(str(descr.getdoc()))))
67 content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
68 content.add(ListItem().join(Strong("is hidden:"), Text(str(descr._is_hidden()))))
69 content.add(ListItem().join(Strong("is disabled:"), Text(str(descr._is_disabled()))))
70 content.add(ListItem().join(Strong("is frozen:"), Text(str(descr._frozen))))
71 content.add(ListItem().join(Strong("is multi:"), Text(str(descr.multi))))
72 content.add(ListItem().join(Strong("is mandatory:"), Text(str(descr.is_mandatory()))))
74 content.add(ListItem().join(Strong("links to:"), Text(str(descr.path))))
75 content.add(Transition())
76 content.add(Paragraph(Link("back to container", join(prefix + ".html"))))
77 make_rst_file(join(docdir, path + '.txt'), content)
79 def make_rest_overview(cfg, title=True):
80 rootname = cfg._cfgimpl_descr._name
81 descr_content(rootname, rootname, cfg._cfgimpl_descr, root=True)
82 #cfg.cfgimpl_read_write()
83 cfg._cfgimpl_disabled = False
84 cfg._cfgimpl_hidden = False
85 for path in cfg.getpaths(include_groups=True, allpaths=True):
86 child = cfg.unwrap_from_path(path)
87 fullpath = rootname + '.' + path
88 prefix = fullpath.rsplit(".", 1)[0]
89 if isinstance(child, OptionDescription):
90 descr_content(fullpath, prefix, child)
92 value = getattr(cfg, path)
93 opt_rst_content(fullpath, prefix, child, value)
95 if __name__ == '__main__':
96 from test_config_big_example import get_example_config
97 make_rest_overview(get_example_config())
98 # ____________________________________________________________