]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/docs/bin/BuildAPIHelpBook.py
   1 import htmllib
, formatter
, string
, os
, pprint
, types
, sys
, glob
 
   3 api_name 
= sys
.argv
[1]  #'wxpyapi' 
   4 api_path 
= sys
.argv
[2]  #'./docs/api/' 
   7 header_hhx 
= '''<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 
  10 <meta name="GENERATOR" content="BuildAPIHelpBook"> 
  12 <OBJECT type="text/site properties"> 
  13  <param name="ImageType" value="Folder"> 
  17 entry_hhx 
= '''<LI> <OBJECT type="text/sitemap"> 
  18 <param name="Local" value="%s"> 
  19 <param name="Name" value="%s"> 
  23 file_hhp 
= '''[OPTIONS] 
  26 Contents file=%(n)s.hhc 
  27 Compiled file=%(n)s.chm 
  29 Default topic=index.html 
  31 Title=wxPython API Documentation 
  34 wxHelp=,"%(n)s.hhc","%(n)s.hhk","index.html",,,,,,0x2420,,0x380e,,,,,0,,, 
  39 def read_segment(fn
, start
, end
): 
  40     data 
= open(fn
).read() 
  41     begin 
= data
.find(start
)+len(start
) 
  42     return data
[begin
:data
.find(end
, begin
)] 
  45 #------------------------------------------------------------------------------- 
  48     hhp 
= file_hhp 
% {'n' : api_name}
 
  52         for name 
in glob
.glob(os
.path
.join(api_path
, mask
)): 
  53             name 
= os
.path
.split(name
)[-1] 
  57     hhp 
+= doglob("*.html") 
  58     hhp 
+= doglob("*.css") 
  60     open(os
.path
.join(api_path
, api_name
+'.hhp'), 'w').write(hhp
) 
  62 #------------------------------------------------------------------------------- 
  67             if type(i
) is types
.ListType
: 
  68                 r
.append('<UL>'+os
.linesep
) 
  70                 r
.append('</UL>'+os
.linesep
) 
  71             elif type(i
) is types
.TupleType
: 
  74                 raise Exception, 'Unhandled type: %s'%type(i
) 
  76     data 
= read_segment(os
.path
.join(api_path
, 'trees.html'), 
  77           '<!-- =========== START OF CLASS HIERARCHY =========== -->', 
  78           '<!-- =========== START OF NAVBAR =========== -->') 
  79     p 
= APIContentsParser(formatter
.NullFormatter(formatter
.NullWriter())) 
  83     traverse(p
.current
, class_hierarchy
) 
  85     data 
= read_segment(os
.path
.join(api_path
, 'wx-module.html'), 
  86           '<!-- =========== START OF SUBMODULES =========== -->', 
  87           '<!-- =========== START OF CLASSES =========== -->') 
  88     p 
= APIContentsParser(formatter
.NullFormatter(formatter
.NullWriter())) 
  91     traverse(p
.current
, submodules
) 
  94           '<UL>'+os
.linesep
+entry_hhx
%('wx-module.html', 'Submodules')+\
 
  95           ''.join(submodules
)+'</UL>'+os
.linesep
+\
 
  96           '<UL>'+os
.linesep
+entry_hhx
%('trees.html', 'Class Hierarchy')+\
 
  97           ''.join(class_hierarchy
)+'</UL>'+os
.linesep 
 
  99     open(os
.path
.join(api_path
, api_name
+'.hhc'), 'w').write(hhc
) 
 102 class APIContentsParser(htmllib
.HTMLParser
): 
 103     def __init__(self
, formatter
, verbose
=0): 
 104         htmllib
.HTMLParser
.__init
__(self
, formatter
, verbose
) 
 108         self
.current 
= self
.contents
 
 113     def start_li(self
, attrs
): 
 116     def start_a(self
, attrs
): 
 118         if self
.li_a_cnt 
== 1: 
 119             if attrs
[0][0] == 'href': 
 120                 self
.cur_href 
= attrs
[0][1] 
 125     def start_code(self
, attrs
): 
 129         text 
= string
.strip(self
.save_end()) 
 130         if self
.cur_href 
and text
: 
 131             self
.current
.append( (self
.cur_href
, text
) ) 
 133     def start_ul(self
, attrs
): 
 134         self
.history
.append(self
.current
) 
 138         c 
= self
.history
.pop() 
 139         c
.append(self
.current
) 
 142 #------------------------------------------------------------------------------- 
 144 def build_keywords(): 
 145     data 
= read_segment(os
.path
.join(api_path
, 'indices.html'), 
 146           '<!-- =========== START OF IDENTIFIER INDEX =========== -->', 
 147           '<!-- =========== START OF NAVBAR =========== -->') 
 148     p 
= APIIndicesParser(formatter
.NullFormatter(formatter
.NullWriter())) 
 151     hhk 
= header_hhx
+ '<UL>'+os
.linesep
+\
 
 152           ''.join([entry_hhx
%(u
, k
) for u
, k 
in p
.indices
])+os
.linesep
+'</UL>' 
 153     open(os
.path
.join(api_path
, api_name
+'.hhk'), 'w').write(hhk
) 
 156 class APIIndicesParser(htmllib
.HTMLParser
): 
 157     def __init__(self
, formatter
, verbose
=0): 
 158         htmllib
.HTMLParser
.__init
__(self
, formatter
, verbose
) 
 164     def start_tr(self
, attrs
): 
 170     def start_a(self
, attrs
): 
 172         if self
.tr_a_cnt 
== 1: 
 173             if attrs
[0][0] == 'href': 
 174                 self
.cur_href 
= attrs
[0][1] 
 179     def start_code(self
, attrs
): 
 183         text 
= string
.strip(self
.save_end()) 
 184         if self
.cur_href 
and text
: 
 185             self
.indices
.append( (self
.cur_href
, text
) ) 
 187 #------------------------------------------------------------------------------- 
 189 if __name__ 
== '__main__': 
 190     print 'Building project...' 
 192     print 'Building contents...' 
 194     print 'Building keywords...'