| author | Sandro Knauß <knauss@netzguerilla.net> |
| Wed, 21 Dec 2011 22:07:48 +0100 | |
| changeset 90 | eb04ac3a8327 |
| parent 74 | c471fed3cab8 |
| child 76 | 9f7da8dc8df8 |
| permissions | -rwxr-xr-x |
| 72 | 1 |
#!/usr/bin/env python2.7 |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
from genshi.template import TemplateLoader |
|
5 |
||
6 |
loader = TemplateLoader('doc/tmpl', auto_reload=True) |
|
7 |
||
8 |
import re |
|
9 |
import inspect |
|
| 73 | 10 |
from iro.user import User as Current |
11 |
from iro.newuser import User as New |
|
| 72 | 12 |
|
13 |
||
14 |
||
15 |
class Link(): |
|
16 |
def __init__(self,name,title): |
|
17 |
self.name=name |
|
18 |
self.title=title |
|
19 |
||
20 |
def getLink(self): |
|
21 |
return self.name |
|
22 |
||
23 |
def __getitem__(self,name): |
|
24 |
if name == "link": |
|
25 |
return self.getLink() |
|
26 |
return AttributeError(name) |
|
27 |
||
28 |
class Site(Link): |
|
29 |
pass |
|
30 |
||
31 |
||
32 |
class Keyword(): |
|
33 |
def __init__(self,name,typ,description): |
|
34 |
self.name=name |
|
35 |
self.typ=typ |
|
36 |
self.description=description |
|
37 |
||
38 |
def section(text): |
|
39 |
ret={} |
|
40 |
li=[] |
|
41 |
kw=None |
|
42 |
for line in text.split("\n"): |
|
43 |
if re.match("^\s*$",line): |
|
44 |
continue |
|
45 |
||
46 |
if line[0] not in (" ","\t"): |
|
47 |
if kw: |
|
48 |
ret[kw.name]=kw |
|
49 |
li.append(kw) |
|
| 73 | 50 |
l=re.match(r"^(?P<name>[a-zA-Z0-9-_.]*)\[(?P<typ>[a-zA-Z0-9-_|]*)\]:(?P<d>.*)$",line) |
| 72 | 51 |
kw=Keyword(name=l.group("name"),typ=l.group("typ"),description=l.group("d")) |
52 |
else: |
|
53 |
kw.description+="\n"+line.strip() |
|
54 |
if kw: |
|
55 |
ret[kw.name]=kw |
|
56 |
li.append(kw) |
|
57 |
return ret,li |
|
58 |
||
59 |
||
60 |
||
61 |
def keywords(f): |
|
62 |
doc=f.__doc__ |
|
63 |
kwds=re.search("Keywords:\n(?P<keywords>(?P<whitespace>\s*)(.+\n)*)\n",doc) |
|
64 |
k=kwds.group("keywords") |
|
65 |
#get rid of beginning whitespaces |
|
66 |
k=re.sub(re.compile(r"^"+kwds.group("whitespace"),re.M),"",k) |
|
67 |
return section(k) |
|
68 |
||
69 |
def ret(f): |
|
70 |
doc=f.__doc__ |
|
71 |
kwds=re.search("Return:\n(?P<ret>(?P<whitespace>\s*)(.+\n)*)\n",doc) |
|
72 |
k=kwds.group("ret") |
|
73 |
#get rid of beginning whitespaces |
|
74 |
k=re.sub(re.compile(r"^"+kwds.group("whitespace"),re.M),"",k) |
|
75 |
return section(k) |
|
76 |
||
77 |
||
78 |
||
79 |
class Arg(): |
|
80 |
def __init__(self,name,f): |
|
81 |
self.name=name |
|
82 |
k,_ = keywords(f) |
|
83 |
kwd=k[name] |
|
84 |
self.typ=kwd.typ |
|
85 |
self.description=kwd.description |
|
86 |
||
87 |
||
88 |
||
89 |
class Method(Link): |
|
| 73 | 90 |
def __init__(self,name,methods): |
91 |
title=name[0].upper()+name[1:] |
|
| 72 | 92 |
Link.__init__(self,name,title) |
| 73 | 93 |
m=methods[name] |
|
74
c471fed3cab8
update document creation:
Sandro Knauß <knauss@netzguerilla.net>
parents:
73
diff
changeset
|
94 |
(args, varargs, keywords, defaults)=inspect.getargspec(m) |
|
c471fed3cab8
update document creation:
Sandro Knauß <knauss@netzguerilla.net>
parents:
73
diff
changeset
|
95 |
args= [b for b in args if b is not "self"] |
|
c471fed3cab8
update document creation:
Sandro Knauß <knauss@netzguerilla.net>
parents:
73
diff
changeset
|
96 |
self.func_line=inspect.formatargspec(args, varargs, keywords, defaults) |
| 72 | 97 |
self.description = m.__doc__.split("\n")[0] |
|
74
c471fed3cab8
update document creation:
Sandro Knauß <knauss@netzguerilla.net>
parents:
73
diff
changeset
|
98 |
self.args=[Arg(a,m) for a in args] |
| 72 | 99 |
_, self.rets=ret(m) |
100 |
||
101 |
||
102 |
def main(): |
|
103 |
sites=[Site("index.html","Iro"), |
|
104 |
Site("current.html","API Documentation"), |
|
105 |
Site("new.html","geplante API Documentation"), |
|
106 |
Site("impressum.html","Impressum"), |
|
107 |
] |
|
108 |
||
| 73 | 109 |
current_methods = dict(inspect.getmembers(Current(None,None))) |
110 |
current=[ |
|
111 |
Method("startSMS",current_methods), |
|
112 |
Method("startFAX",current_methods), |
|
113 |
Method("startMail",current_methods), |
|
114 |
||
115 |
Method("status",current_methods), |
|
116 |
Method("stop",current_methods), |
|
| 72 | 117 |
|
| 73 | 118 |
Method("getProvider",current_methods), |
119 |
Method("getDefaultProvider",current_methods), |
|
120 |
] |
|
121 |
||
122 |
new_methods = dict(inspect.getmembers(New())) |
|
123 |
newm=[ |
|
124 |
Method("sms",new_methods), |
|
125 |
Method("fax",new_methods), |
|
126 |
Method("mail",new_methods), |
|
| 72 | 127 |
|
| 73 | 128 |
Method("status",new_methods), |
129 |
Method("stop",new_methods), |
|
130 |
||
131 |
Method("routes",new_methods), |
|
132 |
Method("defaultRoute",new_methods), |
|
| 72 | 133 |
] |
| 73 | 134 |
|
135 |
||
| 72 | 136 |
for site in sites: |
137 |
print("generiere %s" % site.name) |
|
138 |
tmpl = loader.load(site.name) |
|
139 |
def a(s): |
|
140 |
if s == site: |
|
141 |
return {"class":"menu active"} |
|
| 73 | 142 |
stream = tmpl.generate(sites=sites,active=a,current=current,new=newm) |
| 72 | 143 |
with open('doc/'+site.name, "w") as g: |
144 |
g.write(stream.render('html', doctype='html')) |
|
145 |
||
146 |
if __name__ == '__main__': |
|
147 |
main() |