From 7c640bee4c88ea4044f6b025fd2ee381fc277b77 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 5 Jun 2013 11:19:47 +0200 Subject: [PATCH] report: options work again --- report/generate.py | 47 +++++++++++++++++++++++++--------------------- report/tool.py | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 report/tool.py diff --git a/report/generate.py b/report/generate.py index b48139a..9512c88 100644 --- a/report/generate.py +++ b/report/generate.py @@ -26,8 +26,9 @@ def descr_content(path, prefix, descr, root=False): content.add(ListItem().join(Strong("description:"), Text(descr.impl_get_information('doc')))) if not root: content.add(ListItem().join(Strong("container:"), Text(prefix))) - if not root: - content.add(ListItem().join(Strong("type:"), Text(descr.group_type))) +# 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)))) # FIXME @@ -60,18 +61,21 @@ def opt_rst_content(path, prefix, descr, value): 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))) - if isinstance(descr, ChoiceOption): - content.add(ListItem().join(Strong("possible values:"), Text(str(descr.values)))) + # FIXME +# if isinstance(descr, ChoiceOption): +# content.add(ListItem().join(Strong("possible values:"), Text(str(descr.values)))) if not isinstance(descr, SymLinkOption): - 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.getdoc())))) + # 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)))) - 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())))) + # 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()) @@ -82,15 +86,16 @@ def make_rest_overview(cfg, title=True): descr = cfg._impl_descr rootname = descr._name descr_content(rootname, rootname, descr, root=True) -# for path in cfg.getpaths(include_groups=True, allpaths=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) + + 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__': from sampleconfig import get_example_config diff --git a/report/tool.py b/report/tool.py new file mode 100644 index 0000000..dea6477 --- /dev/null +++ b/report/tool.py @@ -0,0 +1,40 @@ +# Copyright (C) 2012 Team tiramisu (see AUTHORS for all contributors) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# The original `Config` design model is unproudly borrowed from +# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/ +# the whole pypy projet is under MIT licence +from tiramisu.config import Config +from tiramisu.option import (OptionDescription, Option, ChoiceOption, BoolOption, + FloatOption, StrOption, IntOption, IPOption, NetmaskOption, + apply_requires) + +# extendable type +class extend(type): + """ + A magic trick for classes, which lets you add methods or attributes to a + class + """ + def extend(cls, extclass): + bases = list(extclass.__bases__) + bases.append(extclass) + for cl in bases: + for key, value in cl.__dict__.items(): + if key == '__module__': + continue + setattr(cls, key, value) + +# ____________________________________________________________