36 |
36 |
37 from docutils.core import publish_doctree, publish_from_doctree, publish_string |
37 from docutils.core import publish_doctree, publish_from_doctree, publish_string |
38 from docutils.utils import new_document |
38 from docutils.utils import new_document |
39 from docutils.writers.html4css1 import Writer,HTMLTranslator |
39 from docutils.writers.html4css1 import Writer,HTMLTranslator |
40 |
40 |
41 from iro.view.xmlrpc import TwistedInterface as Current |
41 from iro.view.xmlrpc import TwistedInterface as Current |
42 from iro import __version__ |
42 from iro import __version__ |
43 from createerm import createSchemaPlot, tables, tables_cls |
43 from createerm import createSchemaPlot, tables, tables_cls |
44 |
44 |
45 #redering text with rest syntax |
45 #redering text with rest syntax |
46 class NoHeaderHTMLTranslator(HTMLTranslator): |
46 class NoHeaderHTMLTranslator(HTMLTranslator): |
98 return '<Keyword("%s", "%s", "%s")>'%(self.name, self.typ, self.description) |
98 return '<Keyword("%s", "%s", "%s")>'%(self.name, self.typ, self.description) |
99 |
99 |
100 def keywords(f): |
100 def keywords(f): |
101 NORMAL = 0 |
101 NORMAL = 0 |
102 TYPE = 1 |
102 TYPE = 1 |
103 pd = publish_doctree(f.__doc__.decode('utf8')) |
103 pd = publish_doctree(f.__doc__) |
104 |
104 |
105 kws={} |
105 kws={} |
106 for child in pd[1][0]: |
106 for child in pd[1]: |
107 kw = Keyword() |
107 kw = Keyword() |
108 ftyp = NORMAL |
108 ftyp = NORMAL |
109 for sc in child: |
109 for sc in child: |
110 if sc.tagname == "field_name": |
110 if sc.tagname == "field_name": |
111 p = sc.astext().split() |
111 p = sc.astext().split() |
122 break |
122 break |
123 else: |
123 else: |
124 raise Exception("Unknown field_name: %s"%(p[0])) |
124 raise Exception("Unknown field_name: %s"%(p[0])) |
125 if sc.tagname == "field_body": |
125 if sc.tagname == "field_body": |
126 if ftyp == NORMAL: |
126 if ftyp == NORMAL: |
127 kw.description = Markup(reSTify(sc[0])) |
127 kw.description = Markup(reSTify(sc[0]).decode()) |
128 if ftyp == TYPE: |
128 if ftyp == TYPE: |
129 kw.typ = sc[0][0] |
129 kw.typ = sc[0][0] |
130 else: |
130 else: |
131 kws[kw.name] = kw |
131 kws[kw.name] = kw |
132 return kws |
132 return kws |
133 |
133 |
134 def ret(f): |
134 def ret(f): |
135 NORMAL = 0 |
135 NORMAL = 0 |
136 TYPE = 1 |
136 TYPE = 1 |
137 |
137 |
138 pd = publish_doctree(f.__doc__.decode('utf8')) |
138 pd = publish_doctree(f.__doc__) |
139 for child in pd[1][0]: |
139 for child in pd[1]: |
140 kw = Keyword(name="return") |
140 kw = Keyword(name="return") |
141 ftyp = NORMAL |
141 ftyp = NORMAL |
142 for sc in child: |
142 for sc in child: |
143 if sc.tagname == "field_name": |
143 if sc.tagname == "field_name": |
144 p = sc.astext().split() |
144 p = sc.astext().split() |
172 class Method(Link): |
170 class Method(Link): |
173 def __init__(self,name,methods): |
171 def __init__(self,name,methods): |
174 title=name[0].upper()+name[1:] |
172 title=name[0].upper()+name[1:] |
175 Link.__init__(self,name,title) |
173 Link.__init__(self,name,title) |
176 m=methods[name] |
174 m=methods[name] |
177 (args, varargs, keywords, defaults)=inspect.getargspec(m) |
175 |
178 a=[] |
176 signature=inspect.signature(m) |
179 for b in args: |
177 |
180 if b in ("self","session"): |
178 parameters = signature.parameters.copy() |
181 continue |
179 |
182 else: |
180 for arg in ("self", "session"): |
183 a.append(b) |
181 try: |
184 |
182 del(parameters[arg]) |
185 args = a |
183 except KeyError: |
186 self.func_line=inspect.formatargspec(args, varargs, keywords, defaults) |
184 pass |
|
185 |
|
186 self.func_line=str(signature.replace(parameters=parameters.values())) |
187 pd = publish_doctree(m.__doc__) |
187 pd = publish_doctree(m.__doc__) |
188 if pd[0].tagname == "paragraph": |
188 if pd[0].tagname == "paragraph": |
189 self.description = pd[0].astext() |
189 self.description = pd[0].astext() |
190 self.args=[Arg(a,m) for a in args] |
190 self.args=[Arg(a,m) for a in parameters] |
191 self.rets=[ret(m)] |
191 self.rets=[ret(m)] |
192 |
192 |
193 class Table(Link): |
193 class Table(Link): |
194 def __init__(self,cls): |
194 def __init__(self,cls): |
195 name=cls.__name__ |
195 name=cls.__name__ |
196 self.tablename=cls.__tablename__ |
196 self.tablename=cls.__tablename__ |
197 title=self.tablename[0].upper()+self.tablename[1:] |
197 title=self.tablename[0].upper()+self.tablename[1:] |
198 Link.__init__(self,name,title) |
198 Link.__init__(self,name,title) |
199 |
199 |
200 self.description = Markup(publish_string(cls.__doc__,writer=_w)) |
200 self.description = Markup(publish_string(cls.__doc__,writer=_w).decode()) |
201 |
201 |
202 class File: |
202 class File: |
203 def __init__(self,path): |
203 def __init__(self,path): |
204 self.version = re.search("/iro-(.*).tar.gz",path).group(1) |
204 self.version = re.search("/iro-(.*).tar.gz",path).group(1) |
205 self.name = os.path.basename(path) |
205 self.name = os.path.basename(path) |