tiramisu/report/generate.py

104 lines
4.6 KiB
Python
Raw Normal View History

from os.path import dirname, join
from rst import Rest, Paragraph, Strong, OrderedListItem, ListItem, Title, Link, Transition
from rst import Directive, Em, Quote, Text
from tiramisu.option import *
from tiramisu.config import *
#from makerestdoc import *
docdir = join(dirname(__file__), 'build')
def make_rst_file(filename, rstcontent):
fh = file(filename, 'w')
fh.write(rstcontent.text())
fh.close()
def descr_content(path, prefix, descr, root=False):
content = Rest()
title = Title(abovechar="", belowchar="=")
if root:
title.join(Text("Configuration's overview for: "), Quote(descr._name))
else:
title.join(Text("Group's overview for: "), Quote(descr._name))
content.add(title)
content.add(ListItem().join(Strong("name:"), Text(descr._name)))
if not root:
content.add(ListItem().join(Strong("path:"), Text(path)))
2013-06-04 17:42:21 +02:00
content.add(ListItem().join(Strong("description:"), Text(descr.impl_get_information('doc'))))
if not root:
content.add(ListItem().join(Strong("container:"), Text(prefix)))
2013-06-05 11:19:47 +02:00
# FIXME
# if not root:
# content.add(ListItem().join(Strong("type:"), Text(descr.group_type)))
if not root:
content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
2013-06-04 17:42:21 +02:00
# FIXME
# content.add(ListItem().join(Strong("is hidden:"), Text(str(descr._is_hidden()))))
# content.add(ListItem().join(Strong("is disabled:"), Text(str(descr._is_disabled()))))
content.add(Transition())
content.add(Title(abovechar="", belowchar="-").join(Text("Ordered list of childrens for:"), Text(path)))
2013-06-04 17:42:21 +02:00
names, options = descr._children
for opt in options:
name = opt._name
link = Link(name + ":", join(path + '.' + name + ".html"))
# because of SympLink opt
2013-06-04 17:42:21 +02:00
if hasattr(opt, 'impl_get_information'):
doc = opt.impl_get_information('doc')
else:
doc = name
2013-06-04 17:42:21 +02:00
content.add(OrderedListItem(link, Text(opt.impl_get_information('doc'))))
content.add(Transition())
content.add(Paragraph(Link("back to index", "index.html")))
make_rst_file(join(docdir, path + '.txt'), content)
if root:
make_rst_file(join(docdir, 'index.txt'), content)
2013-06-04 17:42:21 +02:00
def opt_rst_content(path, prefix, descr, value):
content = Rest()
title = Title(abovechar="", belowchar="=")
title.join(Text("Configuration's option overview for: "), Quote(descr._name))
content.add(title)
content.add(ListItem().join(Strong("name:"), Text(descr._name)))
content.add(ListItem().join(Strong("value:"), Text(str(value))))
content.add(ListItem().join(Strong("path:"), Text(path)))
content.add(ListItem().join(Strong("container:"), Text(prefix)))
2013-06-05 11:19:47 +02:00
# FIXME
# if isinstance(descr, ChoiceOption):
# content.add(ListItem().join(Strong("possible values:"), Text(str(descr.values))))
if not isinstance(descr, SymLinkOption):
2013-06-05 11:19:47 +02:00
# FIXME
# content.add(ListItem().join(Strong("type:"), Text(str(descr.opt_type))))
# content.add(ListItem().join(Strong("default:"), Text(str(descr.getdefault()))))
content.add(ListItem().join(Strong("description:"), Text(str(descr.impl_get_information('doc')))))
content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
2013-06-05 11:19:47 +02:00
# FIXME
# content.add(ListItem().join(Strong("is hidden:"), Text(str(descr._is_hidden()))))
# content.add(ListItem().join(Strong("is disabled:"), Text(str(descr._is_disabled()))))
# content.add(ListItem().join(Strong("is frozen:"), Text(str(descr._frozen))))
# content.add(ListItem().join(Strong("is multi:"), Text(str(descr.multi))))
# content.add(ListItem().join(Strong("is mandatory:"), Text(str(descr.is_mandatory()))))
else:
content.add(ListItem().join(Strong("links to:"), Text(str(descr.path))))
content.add(Transition())
content.add(Paragraph(Link("back to container", join(prefix + ".html"))))
make_rst_file(join(docdir, path + '.txt'), content)
2013-06-04 17:42:21 +02:00
def make_rest_overview(cfg, title=True):
2013-06-04 17:42:21 +02:00
descr = cfg._impl_descr
rootname = descr._name
descr_content(rootname, rootname, descr, root=True)
2013-06-05 11:19:47 +02:00
for path in descr.impl_getpaths(include_groups=True):
child = cfg.unwrap_from_path(path)
fullpath = rootname + '.' + path
prefix = fullpath.rsplit(".", 1)[0]
if isinstance(child, OptionDescription):
descr_content(fullpath, prefix, child)
else:
value = getattr(cfg, path)
opt_rst_content(fullpath, prefix, child, value)
if __name__ == '__main__':
2013-06-04 17:42:21 +02:00
from sampleconfig import get_example_config
make_rest_overview(get_example_config())
# ____________________________________________________________