2014-01-29 09:51:57 -04:00
from xml . sax . saxutils import escape
2014-02-15 20:47:11 -04:00
import codecs
2013-10-17 20:47:15 -03:00
2014-02-15 16:24:53 -04:00
class DokuWikiTablesOutput ( ) :
def __init__ ( self , groups ) :
result = " ====== Parameter Reference ====== \n This list is auto-generated every few minutes and contains the most recent parameter names and default values. \n \n "
2013-10-17 20:47:15 -03:00
for group in groups :
result + = " ==== %s ==== \n \n " % group . GetName ( )
2014-01-29 09:51:57 -04:00
result + = " |< 100 % 20% 20 % 10% 10 % 10% 30 % >| \n "
2014-02-13 21:21:24 -04:00
result + = " ^ Name ^ Description ^ Min ^ Max ^ Default ^ Comment ^ \n "
2013-10-17 20:47:15 -03:00
for param in group . GetParams ( ) :
code = param . GetFieldValue ( " code " )
name = param . GetFieldValue ( " short_desc " )
min_val = param . GetFieldValue ( " min " )
2014-02-13 21:21:24 -04:00
max_val = param . GetFieldValue ( " max " )
def_val = param . GetFieldValue ( " default " )
long_desc = param . GetFieldValue ( " long_desc " )
name = name . replace ( " \n " , " " )
result + = " | %s | %s | " % ( code , name )
2013-10-17 20:47:15 -03:00
if min_val is not None :
2014-02-13 21:21:24 -04:00
result + = " %s | " % min_val
2014-01-13 03:33:25 -04:00
else :
2014-02-13 21:21:24 -04:00
result + = " | "
2013-10-17 20:47:15 -03:00
if max_val is not None :
2014-02-13 21:21:24 -04:00
result + = " %s | " % max_val
2014-01-13 03:33:25 -04:00
else :
2014-02-13 21:21:24 -04:00
result + = " | "
2013-10-17 20:47:15 -03:00
if def_val is not None :
2014-02-13 21:21:24 -04:00
result + = " %s | " % def_val
2014-01-13 03:33:25 -04:00
else :
2014-02-13 21:21:24 -04:00
result + = " | "
2014-01-13 03:33:25 -04:00
if long_desc is not None :
2014-02-13 21:21:24 -04:00
long_desc = long_desc . replace ( " \n " , " " )
result + = " %s | " % long_desc
2014-01-13 03:33:25 -04:00
else :
2014-02-13 21:21:24 -04:00
result + = " | "
result + = " \n "
2014-01-13 03:33:25 -04:00
result + = " \n "
2014-02-15 16:24:53 -04:00
self . output = result ;
def Save ( self , filename ) :
2014-02-15 20:47:11 -04:00
with codecs . open ( filename , ' w ' , ' utf-8 ' ) as f :
2014-02-15 16:24:53 -04:00
f . write ( self . output )
def SaveRpc ( self , filename ) :
2014-02-15 20:47:11 -04:00
with codecs . open ( filename , ' w ' , ' utf-8 ' ) as f :
2014-02-15 16:24:53 -04:00
f . write ( """ <?xml version= ' 1.0 ' ?>
< methodCall >
< methodName > wiki . putPage < / methodName >
< params >
< param >
< value >
< string > : firmware : parameters < / string >
< / value >
< / param >
< param >
< value >
< string > """ )
f . write ( escape ( self . output ) )
f . write ( """ </string>
< / value >
< / param >
< param >
< value >
< name > sum < / name >
< string > Updated parameters automagically from code . < / string >
< / value >
< / param >
< / params >
< / methodCall > """ )