|
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 |
|
|
10 |
from iro.user import User |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
user_methods = dict(inspect.getmembers(User(None,None))) |
|
|
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) |
|
|
50 |
l=re.match(r"^(?P<name>[a-zA-Z0-9-_.]*)\[(?P<typ>[a-zA-Z0-9-_]*)\]:(?P<d>.*)$",line) |
|
|
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): |
|
|
90 |
def __init__(self,name,title): |
|
|
91 |
Link.__init__(self,name,title) |
|
|
92 |
m=user_methods[name] |
|
|
93 |
self.description = m.__doc__.split("\n")[0] |
|
|
94 |
a=inspect.getargspec(m) |
|
|
95 |
self.args=[Arg(a,m) for a in a.args if a is not "self"] |
|
|
96 |
_, self.rets=ret(m) |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
def main(): |
|
|
100 |
sites=[Site("index.html","Iro"), |
|
|
101 |
Site("current.html","API Documentation"), |
|
|
102 |
Site("new.html","geplante API Documentation"), |
|
|
103 |
Site("impressum.html","Impressum"), |
|
|
104 |
] |
|
|
105 |
|
|
|
106 |
methods=[ |
|
|
107 |
Method("startSMS","StartSMS"), |
|
|
108 |
Method("startFAX","StartFAX"), |
|
|
109 |
Method("startMail","StartMail"), |
|
|
110 |
|
|
|
111 |
Method("status","Status"), |
|
|
112 |
Method("stop","Stop"), |
|
|
113 |
|
|
|
114 |
Method("getProvider","GetProvider"), |
|
|
115 |
Method("getDefaultProvider","GetDefaultProvider"), |
|
|
116 |
] |
|
|
117 |
for site in sites: |
|
|
118 |
print("generiere %s" % site.name) |
|
|
119 |
tmpl = loader.load(site.name) |
|
|
120 |
def a(s): |
|
|
121 |
if s == site: |
|
|
122 |
return {"class":"menu active"} |
|
|
123 |
stream = tmpl.generate(sites=sites,active=a,methods=methods) |
|
|
124 |
with open('doc/'+site.name, "w") as g: |
|
|
125 |
g.write(stream.render('html', doctype='html')) |
|
|
126 |
|
|
|
127 |
if __name__ == '__main__': |
|
|
128 |
main() |