]>
Commit | Line | Data |
---|---|---|
a9c3b09e VZ |
1 | ##############################################################################\r |
2 | # Name: misc/scripts/update_doc_libs.py\r | |
3 | # Purpose: Automatically insert \Library{} headers in the doc files\r | |
4 | # Created: 2007-07-28\r | |
5 | # RCS-ID: $Id: makeunixtags.sh 46320 2007-06-04 11:02:29Z VZ $\r | |
6 | # Copyright: (c) 2007 Francesco Montorsi\r | |
7 | # Licence: wxWindows licence\r | |
8 | ##############################################################################\r | |
9 | \r | |
eaa78507 | 10 | from update_doc_utils import scanTexFiles\r |
a9c3b09e | 11 | \r |
eaa78507 VZ |
12 | INCLUDE_PATH="../../include"\r |
13 | \r | |
14 | def myCallback(classname, texFileName, content, i):\r | |
15 | tofix.add(texFileName) # consider this .tex broken\r | |
16 | \r | |
17 | # now search the include file for this class\r | |
18 | include = ""\r | |
19 | for j in range(i,len(content)):\r | |
20 | line = content[j]\r | |
21 | if "wx/" in line and ".h" in line:\r | |
22 | include = line[line.find("wx/"):line.find(".h")+2]\r | |
23 | break\r | |
24 | if include == "":\r | |
25 | print " no include file declared for class %s" % classname\r | |
26 | return True # go on with next \class\r | |
27 | \r | |
28 | include = include.replace("\\_", "_")\r | |
29 | print " the include file for %s is %s" % (classname, include)\r | |
30 | \r | |
31 | # does this .tex already contains the \wxheading{Library} section nearby the include file?\r | |
32 | for k in range(j,min(len(content), j+3)):\r | |
33 | line = content[k]\r | |
34 | if "\wxheading{Library}" in line:\r | |
35 | print " this \class section already has its \wxheading{Library} section... skipping"\r | |
36 | tofix.remove(texFileName) # was a valid .tex (at least for current class)\r | |
37 | return True # go on with next \class\r | |
38 | \r | |
39 | # now try to understand which lib contains this class\r | |
40 | include = INCLUDE_PATH + "/" + include\r | |
41 | header = open(include, "r")\r | |
42 | if not header:\r | |
43 | print " could not open %s" % include\r | |
44 | return True # go on with next \class\r | |
45 | \r | |
46 | decl = ""\r | |
47 | content2 = header.readlines()\r | |
48 | \r | |
49 | # if they exist append port-specific headers contents\r | |
50 | for c in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:\r | |
51 | try:\r | |
52 | temp = include.replace("wx/", c)\r | |
53 | print " trying to open %s..." % temp\r | |
54 | header = open(temp, "r")\r | |
55 | headercontents = header.readlines()\r | |
56 | content2 = content2 + headercontents\r | |
57 | print " added %d lines from %s" % (len(headercontents), temp)\r | |
58 | except:\r | |
59 | pass\r | |
60 | \r | |
61 | # now search for the export-declaration associated with this class\r | |
62 | for line in content2:\r | |
63 | if "class " in line and classname in line:\r | |
64 | if line.find("class") < line.find(classname): # could be a comment\r | |
65 | if "_" in line:\r | |
66 | decl = line[line.find("_")+1:]\r | |
67 | decl = decl[:decl.find(" ")]\r | |
68 | decl = decl.replace("FWD_", "")\r | |
69 | decl = decl[0:1].upper() + decl[1:].lower()\r | |
70 | break\r | |
71 | elif " WXDLLEXPORT " in line:\r | |
72 | decl = "Core"\r | |
a9c3b09e | 73 | break\r |
eaa78507 VZ |
74 | \r |
75 | if decl == "":\r | |
76 | print " no declaration associated with %s" % classname\r | |
77 | return True # go on with next \class\r | |
78 | \r | |
79 | print " the declaration associated with %s is %s" % (classname, decl)\r | |
80 | tofix.remove(texFileName) # was a valid .tex (at least for current class)\r | |
81 | \r | |
82 | # now modify the .tex file\r | |
83 | content.insert(j+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl)\r | |
84 | \r | |
85 | # write it\r | |
86 | file = open(texFileName, "w")\r | |
87 | file.write(''.join(content))\r | |
88 | file.flush()\r | |
89 | \r | |
90 | print " updated %s" % texFileName\r | |
91 | fixed = fixed+1\r | |
92 | \r | |
93 | return True\r | |
94 | \r | |
95 | fixed = 0\r | |
96 | tofix = set()\r | |
97 | count = scanTexFiles(myCallback)\r | |
98 | \r | |
99 | print "\nProcessed %d files, automatically fixed %d files." % (count, fixed)\r | |
100 | print "There are %d files to fix manually:\n%s" % (len(tofix), '\n'.join(tofix))\r |