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