]> git.saurik.com Git - wxWidgets.git/blob - misc/scripts/update_doc_libs.py
added the script used to add libraries to the documentation files (see patch 1756715)
[wxWidgets.git] / misc / scripts / update_doc_libs.py
1 ##############################################################################
2 # Name: misc/scripts/update_doc_libs.py
3 # Purpose: Automatically insert \Library{} headers in the doc files
4 # Created: 2007-07-28
5 # RCS-ID: $Id: makeunixtags.sh 46320 2007-06-04 11:02:29Z VZ $
6 # Copyright: (c) 2007 Francesco Montorsi
7 # Licence: wxWindows licence
8 ##############################################################################
9
10 import sys, os, glob, distutils.file_util
11
12 tofix = set()
13 count = 0
14 for f in glob.glob('*.tex'):
15 file = open(f, "r")
16 if not file:
17 print "could not open %s" % f
18 continue
19 print "opened file %s" % f
20 count = count + 1
21
22 # search \class
23 content = file.readlines()
24 classdecl = 0
25 for i in range(len(content)):
26 line = content[i]
27 if "\class{" in line:
28 classdecl = classdecl + 1
29
30 classname = line
31 classname = classname[classname.find("\class{"):]
32 classname = classname[classname.find("{")+1:classname.find("}")]
33 print " the class declared is named '%s'" % classname
34
35 tofix.add(f) # consider this .tex broken
36
37 # now search the include file for this class
38 include = ""
39 for j in range(i,len(content)):
40 line = content[j]
41 if "wx/" in line and ".h" in line:
42 include = line[line.find("wx/"):line.find(".h")+2]
43 break
44 if include == "":
45 print " no include file declared for class %s" % classname
46 continue
47
48 include = include.replace("\\_", "_")
49 print " the include file for %s is %s" % (classname, include)
50
51 # now try to understand which libs contains this class
52 include = "../../../include/" + include
53 header = open(include, "r")
54 if not file:
55 print " could not open %s" % include
56 continue
57
58 decl = ""
59 content2 = header.readlines()
60
61 # if they exist append port-specific headers contents
62 for c in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:
63 try:
64 temp = include.replace("wx/", c)
65 print " trying to open %s..." % temp
66 header = open(temp, "r")
67 headercontents = header.readlines()
68 content2 = content2 + headercontents
69 print " added %d lines from %s" % (len(headercontents), temp)
70 except:
71 pass
72
73 for line in content2:
74 if "class " in line and classname in line:
75 if line.find("class") < line.find(classname): # could be a comment
76 if "_" in line:
77 decl = line[line.find("_")+1:]
78 decl = decl[:decl.find(" ")]
79 decl = decl.replace("FWD_", "")
80 decl = decl[0:1].upper() + decl[1:].lower()
81 break
82 elif " WXDLLEXPORT " in line:
83 decl = "Core"
84 break
85
86 if decl == "":
87 print " no declaration associated with %s" % classname
88 continue
89
90 print " the declaration associated with %s is %s" % (classname, decl)
91 tofix.remove(f) # was a valid .tex (at least for current class)
92
93 # now modify the .tex file
94 content.insert(j+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl)
95
96 # write it
97 file = open(f, "w")
98 file.write(''.join(content))
99 file.flush()
100
101 file = open(f, "r")
102
103 print " updated %s" % f
104
105
106 print " file %s contains %d class declarations" % (f, classdecl)
107
108 print "\nProcessed %d files." % count
109 print "There are %d files to fix:\n%s" % (len(tofix), '\n'.join(tofix))