2012-07-13 09:42:14 +02:00
|
|
|
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'))))
|
2012-07-13 09:42:14 +02:00
|
|
|
if not root:
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(ListItem().join(Strong("parent config:"), Text(prefix)))
|
|
|
|
if not root:
|
|
|
|
content.add(ListItem().join(Strong("type:"), Text(descr._group_type)))
|
2012-07-13 09:42:14 +02:00
|
|
|
if not root:
|
|
|
|
content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
|
2013-06-05 14:56:46 +02:00
|
|
|
if not root:
|
|
|
|
content.add(ListItem().join(Strong("properties"), Text(str([prop for prop in descr._properties]))))
|
2012-07-13 09:42:14 +02:00
|
|
|
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:
|
2012-07-13 09:42:14 +02:00
|
|
|
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')
|
2012-07-13 09:42:14 +02:00
|
|
|
else:
|
|
|
|
doc = name
|
2013-06-04 17:42:21 +02:00
|
|
|
content.add(OrderedListItem(link, Text(opt.impl_get_information('doc'))))
|
2012-07-13 09:42:14 +02:00
|
|
|
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
|
|
|
|
2012-07-13 09:42:14 +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)))
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(ListItem().join(Strong("type:"), Text(descr.__class__.__name__)))
|
|
|
|
content.add(ListItem().join(Strong("current value:"), Text(str(value))))
|
2012-07-13 09:42:14 +02:00
|
|
|
content.add(ListItem().join(Strong("path:"), Text(path)))
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(ListItem().join(Strong("parent config:"), Text(prefix)))
|
|
|
|
if isinstance(descr, ChoiceOption):
|
2014-04-17 18:47:48 +02:00
|
|
|
content.add(ListItem().join(Strong("possible values:"), Text(str(descr.impl_get_values()))))
|
2012-07-13 09:42:14 +02:00
|
|
|
if not isinstance(descr, SymLinkOption):
|
2014-04-17 18:47:48 +02:00
|
|
|
content.add(ListItem().join(Strong("mime type:"), Text(str(descr.__class__.__name__))))
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(ListItem().join(Strong("default value:"), Text(str(descr.impl_getdefault()))))
|
2013-06-05 11:19:47 +02:00
|
|
|
content.add(ListItem().join(Strong("description:"), Text(str(descr.impl_get_information('doc')))))
|
2012-07-13 09:42:14 +02:00
|
|
|
content.add(ListItem().join(Strong("requirements:"), Text(str(descr._requires))))
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(ListItem().join(Strong("properties"), Text(str([prop for prop in descr._properties]))))
|
2012-07-13 09:42:14 +02:00
|
|
|
else:
|
|
|
|
content.add(ListItem().join(Strong("links to:"), Text(str(descr.path))))
|
|
|
|
content.add(Transition())
|
2013-06-05 14:56:46 +02:00
|
|
|
content.add(Paragraph(Link("back to parent config", join(prefix + ".html"))))
|
2012-07-13 09:42:14 +02:00
|
|
|
make_rst_file(join(docdir, path + '.txt'), content)
|
2013-06-04 17:42:21 +02:00
|
|
|
|
2012-07-13 09:42:14 +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)
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-06-04 17:42:21 +02:00
|
|
|
from sampleconfig import get_example_config
|
2012-07-13 09:42:14 +02:00
|
|
|
make_rest_overview(get_example_config())
|
|
|
|
# ____________________________________________________________
|