createdoc.py
changeset 73 f2f247a5b6c9
parent 72 e7b44716a564
child 74 c471fed3cab8
equal deleted inserted replaced
72:e7b44716a564 73:f2f247a5b6c9
     5 
     5 
     6 loader = TemplateLoader('doc/tmpl', auto_reload=True)
     6 loader = TemplateLoader('doc/tmpl', auto_reload=True)
     7 
     7 
     8 import re
     8 import re
     9 import inspect
     9 import inspect
    10 from iro.user import User
    10 from iro.user import User as Current
       
    11 from iro.newuser import User as New
    11 
    12 
    12 
    13 
    13 user_methods = dict(inspect.getmembers(User(None,None)))
       
    14 
    14 
    15 class Link():
    15 class Link():
    16     def __init__(self,name,title):
    16     def __init__(self,name,title):
    17         self.name=name
    17         self.name=name
    18         self.title=title
    18         self.title=title
    45 
    45 
    46         if line[0] not in (" ","\t"):
    46         if line[0] not in (" ","\t"):
    47             if kw:
    47             if kw:
    48                 ret[kw.name]=kw
    48                 ret[kw.name]=kw
    49                 li.append(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)
    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"))
    51             kw=Keyword(name=l.group("name"),typ=l.group("typ"),description=l.group("d"))
    52         else:
    52         else:
    53             kw.description+="\n"+line.strip()
    53             kw.description+="\n"+line.strip()
    54     if kw:
    54     if kw:
    55         ret[kw.name]=kw
    55         ret[kw.name]=kw
    85         self.description=kwd.description
    85         self.description=kwd.description
    86 
    86 
    87         
    87         
    88 
    88 
    89 class Method(Link):
    89 class Method(Link):
    90     def __init__(self,name,title):
    90     def __init__(self,name,methods):
       
    91         title=name[0].upper()+name[1:]
    91         Link.__init__(self,name,title)
    92         Link.__init__(self,name,title)
    92         m=user_methods[name]
    93         m=methods[name]
       
    94         self.func_line=inspect.formatargspec(*inspect.getargspec(m))
    93         self.description = m.__doc__.split("\n")[0]
    95         self.description = m.__doc__.split("\n")[0]
    94         a=inspect.getargspec(m)
    96         a=inspect.getargspec(m)
    95         self.args=[Arg(a,m) for a in a.args if a is not "self"]
    97         self.args=[Arg(a,m) for a in a.args if a is not "self"]
    96         _, self.rets=ret(m)
    98         _, self.rets=ret(m)
    97 
    99 
   101            Site("current.html","API Documentation"),
   103            Site("current.html","API Documentation"),
   102            Site("new.html","geplante API Documentation"),
   104            Site("new.html","geplante API Documentation"),
   103            Site("impressum.html","Impressum"),
   105            Site("impressum.html","Impressum"),
   104            ]
   106            ]
   105 
   107 
   106     methods=[
   108     current_methods = dict(inspect.getmembers(Current(None,None)))
   107             Method("startSMS","StartSMS"),
   109     current=[
   108             Method("startFAX","StartFAX"),
   110             Method("startSMS",current_methods),
   109             Method("startMail","StartMail"),
   111             Method("startFAX",current_methods),
       
   112             Method("startMail",current_methods),
   110             
   113             
   111             Method("status","Status"),
   114             Method("status",current_methods),
   112             Method("stop","Stop"),
   115             Method("stop",current_methods),
   113             
   116             
   114             Method("getProvider","GetProvider"),
   117             Method("getProvider",current_methods),
   115             Method("getDefaultProvider","GetDefaultProvider"),
   118             Method("getDefaultProvider",current_methods),
   116             ]
   119             ]
       
   120 
       
   121     new_methods = dict(inspect.getmembers(New()))
       
   122     newm=[
       
   123             Method("sms",new_methods),
       
   124             Method("fax",new_methods),
       
   125             Method("mail",new_methods),
       
   126             
       
   127             Method("status",new_methods),
       
   128             Method("stop",new_methods),
       
   129             
       
   130             Method("routes",new_methods),
       
   131             Method("defaultRoute",new_methods),
       
   132             ]
       
   133 
       
   134 
   117     for site in sites:
   135     for site in sites:
   118         print("generiere %s" % site.name)
   136         print("generiere %s" % site.name)
   119         tmpl = loader.load(site.name)
   137         tmpl = loader.load(site.name)
   120         def a(s):
   138         def a(s):
   121             if s == site:
   139             if s == site:
   122                 return {"class":"menu active"}
   140                 return {"class":"menu active"}
   123         stream = tmpl.generate(sites=sites,active=a,methods=methods)
   141         stream = tmpl.generate(sites=sites,active=a,current=current,new=newm)
   124         with open('doc/'+site.name, "w") as g:
   142         with open('doc/'+site.name, "w") as g:
   125             g.write(stream.render('html', doctype='html'))
   143             g.write(stream.render('html', doctype='html'))
   126 
   144 
   127 if __name__ == '__main__':
   145 if __name__ == '__main__':
   128     main()
   146     main()