list is Multi now which enables us to implement item access
[tiramisu.git] / report / makerestdoc.py
1 from tiramisu.config import Config
2 from tiramisu import option
3 # we shall keep extendable types out of the reach of unexceptional guys like us 
4 # horror __metaclass__ = extendabletype
5
6 def get_fullpath(opt, path):
7     if path:
8         return "%s.%s" % (path, opt._name)
9     else:
10         return opt._name
11
12 class Option:
13     def make_rest_doc(self, path=""):
14         fullpath = get_fullpath(self, path)
15         result = Rest(
16             Title(fullpath, abovechar="=", belowchar="="),
17             ListItem(Strong("name:"), self._name),
18             ListItem(Strong("description:"), self.doc))
19         return result
20
21 class ChoiceOption(Option, option.ChoiceOption):
22     def make_rest_doc(self, path=""):
23         content = super(ChoiceOption, self).make_rest_doc(path)
24         content.add(ListItem(Strong("option type:"), "choice option"))
25         content.add(ListItem(Strong("possible values:"),
26                              *[ListItem(str(val)) for val in self.values]))
27         if self.default is not None:
28             content.add(ListItem(Strong("default:"), str(self.default)))
29
30 #        requirements = []
31 #        
32 #        for val in self.values:
33 #            if val not in self._requires:
34 #                continue
35 #            req = self._requires[val]
36 #            requirements.append(ListItem("value '%s' requires:" % (val, ),
37 #                *[ListItem(Link(opt, opt + ".html"),
38 #                           "to be set to '%s'" % (rval, ))
39 #                      for (opt, rval) in req]))
40 #        if requirements:
41 #            content.add(ListItem(Strong("requirements:"), *requirements))
42         return content
43
44 class BoolOption(Option, option.BoolOption):
45     def make_rest_doc(self, path=""):
46         content = super(BoolOption, self).make_rest_doc(path)
47         fullpath = get_fullpath(self, path)
48         content.add(ListItem(Strong("option type:"), "boolean option"))
49         if self.default is not None:
50             content.add(ListItem(Strong("default:"), str(self.default)))
51 #        if self._requires is not None:
52 #            requirements = [ListItem(Link(opt, opt + ".html"),
53 #                               "must be set to '%s'" % (rval, ))
54 #                                for (opt, rval) in self._requires]
55 #            if requirements:
56 #                content.add(ListItem(Strong("requirements:"), *requirements))
57         return content
58
59 class IntOption(Option, option.IntOption):
60     def make_rest_doc(self, path=""):
61         content = super(IntOption, self).make_rest_doc(path)
62         content.add(ListItem(Strong("option type:"), "integer option"))
63         if self.default is not None:
64             content.add(ListItem(Strong("default:"), str(self.default)))
65         return content
66
67 class FloatOption(Option, option.FloatOption):
68     def make_rest_doc(self, path=""):
69         content = super(FloatOption, self).make_rest_doc(path)
70         content.add(ListItem(Strong("option type:"), "float option"))
71         if self.default is not None:
72             content.add(ListItem(Strong("default:"), str(self.default)))
73         return content
74
75 class StrOption(Option, option.StrOption):
76     def make_rest_doc(self, path=""):
77         content = super(StrOption, self).make_rest_doc(path)
78         content.add(ListItem(Strong("option type:"), "string option"))
79         if self.default is not None:
80             content.add(ListItem(Strong("default:"), str(self.default)))
81         return content
82
83 #class ArbitraryOption:
84 #    def make_rest_doc(self, path=""):
85 #        content = super(ArbitraryOption, self).make_rest_doc(path)
86 #        content.add(ListItem(Strong("option type:"),
87 #                             "arbitrary option (mostly internal)"))
88 #        if self.default is not None:
89 #            content.add(ListItem(Strong("default:"), str(self.default)))
90 #        elif self.defaultfactory is not None:
91 #            content.add(ListItem(Strong("factory for the default value:"),
92 #                                 str(self.defaultfactory)))
93 #        return content
94
95 class OptionDescription(option.OptionDescription):
96     def make_rest_doc(self, path=""):
97         fullpath = get_fullpath(self, path)
98         content = Rest(
99             Title(fullpath, abovechar="=", belowchar="="))
100         toctree = []
101         for child in self._children:
102             subpath = fullpath + "." + child._name
103             toctree.append(subpath)
104         content.add(Directive("toctree", *toctree, **{'maxdepth': 4}))
105         content.join(
106             ListItem(Strong("name:"), self._name),
107             ListItem(Strong("description:"), self.doc))
108         stack = []
109         curr = content
110 #        config = Config(self)
111         return content
112
113 # ____________________________________________________________
114
115