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.impl_get_information('doc'))))
28 content.add(ListItem().join(Strong("parent config:"), Text(prefix)))
30 content.add(ListItem().join(Strong("type:"), Text(descr._group_type)))
32 content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
34 content.add(ListItem().join(Strong("properties"), Text(str([prop for prop in descr._properties]))))
35 content.add(Transition())
36 content.add(Title(abovechar="", belowchar="-").join(Text("Ordered list of childrens for:"), Text(path)))
37 names, options = descr._children
40 link = Link(name + ":", join(path + '.' + name + ".html"))
41 # because of SympLink opt
42 if hasattr(opt, 'impl_get_information'):
43 doc = opt.impl_get_information('doc')
46 content.add(OrderedListItem(link, Text(opt.impl_get_information('doc'))))
47 content.add(Transition())
48 content.add(Paragraph(Link("back to index", "index.html")))
49 make_rst_file(join(docdir, path + '.txt'), content)
51 make_rst_file(join(docdir, 'index.txt'), content)
53 def opt_rst_content(path, prefix, descr, value):
55 title = Title(abovechar="", belowchar="=")
56 title.join(Text("Configuration's option overview for: "), Quote(descr._name))
58 content.add(ListItem().join(Strong("name:"), Text(descr._name)))
59 content.add(ListItem().join(Strong("type:"), Text(descr.__class__.__name__)))
60 content.add(ListItem().join(Strong("current value:"), Text(str(value))))
61 content.add(ListItem().join(Strong("path:"), Text(path)))
62 content.add(ListItem().join(Strong("parent config:"), Text(prefix)))
63 if isinstance(descr, ChoiceOption):
64 content.add(ListItem().join(Strong("possible values:"), Text(str(descr._values))))
65 if not isinstance(descr, SymLinkOption):
66 content.add(ListItem().join(Strong("mime type:"), Text(str(descr._opt_type))))
67 content.add(ListItem().join(Strong("default value:"), Text(str(descr.impl_getdefault()))))
68 content.add(ListItem().join(Strong("description:"), Text(str(descr.impl_get_information('doc')))))
69 content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
70 content.add(ListItem().join(Strong("properties"), Text(str([prop for prop in descr._properties]))))
72 content.add(ListItem().join(Strong("links to:"), Text(str(descr.path))))
73 content.add(Transition())
74 content.add(Paragraph(Link("back to parent config", join(prefix + ".html"))))
75 make_rst_file(join(docdir, path + '.txt'), content)
77 def make_rest_overview(cfg, title=True):
78 descr = cfg._impl_descr
79 rootname = descr._name
80 descr_content(rootname, rootname, descr, root=True)
82 for path in descr.impl_getpaths(include_groups=True):
83 child = cfg.unwrap_from_path(path)
84 fullpath = rootname + '.' + path
85 prefix = fullpath.rsplit(".", 1)[0]
86 if isinstance(child, OptionDescription):
87 descr_content(fullpath, prefix, child)
89 value = getattr(cfg, path)
90 opt_rst_content(fullpath, prefix, child, value)
92 if __name__ == '__main__':
93 from sampleconfig import get_example_config
94 make_rest_overview(get_example_config())
95 # ____________________________________________________________