]>
git.saurik.com Git - wxWidgets.git/blob - misc/scripts/update_doc_baseclasses.py
1 ##############################################################################
2 # Name: misc/scripts/update_doc_baseclasses.py
3 # Purpose: Warns about missing classes in the "Derived from"
4 # sections in the doc files
6 # Copyright: (c) 2007 Francesco Montorsi
7 # Licence: wxWindows licence
8 ##############################################################################
10 from update_doc_utils
import scanTexFiles
12 # classes whose docs cannot be fixed automatically
14 # 1) multiple inheritance
15 # 2) other strange things specific of these classes
16 EXCEPTIONS
=['wxNotebook','wxChoicebook','wxListbook','wxToolbook','wxTreebook','wxURLDataObject','wxHScrolledWindow','wxVScrolledWindow','wxVarHVScrollHelper','wxHVScrolledWindow','wxFileStream']
18 def myCallback(classname
, texFileName
, content
, i
):
19 # now search the base classes for this class
21 for j
in range(i
,len(content
)):
23 if line
.startswith("\wxheading{Derived from}"):
24 # take all lines contained between this \wxheading and the next one
26 for k
in range(j
+1,len(content
)):
28 if "\wxheading" in line
:
30 elif "\helpref" in line
:
31 baseclasses
.append(line
)
32 break # we've already processed the 'derived from' section for this class
35 print " no base classes declared for class %s" % classname
36 return True # keep going on with next \class tags
38 # polish baseclasses list
39 for i
in range(len(baseclasses
)):
41 baseclasses
[i
] = s
[s
.find("{")+1:s.find("}")]
43 # store the baseclasses
44 tree
[classname
] = baseclasses
45 treetex
[classname
] = texFileName
46 treepos
[classname
] = j
+1
47 print " class '%s' has %d base class(es): %s" % (classname
, len(baseclasses
), ','.join(baseclasses
))
55 count
= scanTexFiles(myCallback
)
57 print "\nProcessed %d files." % count
58 print "\nNow starting to compare the base class lists.\n"
60 def getFullListOfBaseClasses(classname
):
61 if classname
not in tree
or classname
=='':
64 # only use the first base class of info taken from .tex files
65 # i.e. we assume that at least the first class declared as base class is always correct
66 baseclass
= tree
[classname
][0]
67 return [baseclass
] + getFullListOfBaseClasses(baseclass
)
69 # now compare the theorical list of base classes with the list of base
70 # classes taken from the .tex files
73 for classname
in tree
:
74 theorical
=getFullListOfBaseClasses(classname
)
79 print "* for class '%s' documented in '%s'" % (classname
,treetex
[classname
])
80 print " theorical list: %s" % theorical
81 print " declared list: %s" % real
83 if classname
in EXCEPTIONS
:
84 tofix
.add(treetex
[classname
])
85 print " cannot fix automatically (blacklisted class!)\n"
89 file = open(treetex
[classname
], "r")
90 content
= file.readlines()
92 #print "old content is:"
93 #print ''.join(content)
95 # remove old \helpref lines
96 startidx
= treepos
[classname
]
98 while count
< len(tree
[classname
]):
99 # we want to remove n \helpref lines, where 'n' is the
100 # number of base classes declared
101 if content
[startidx
].startswith('\helpref'):
102 del content
[startidx
]
105 startidx
= startidx
+1 # probably an empty line
109 for j
in range(len(theorical
)-1):
111 content
.insert(startidx
+j
, "\helpref{%s}{%s}\\\\\n" % (c
, c
.lower()))
115 content
.insert(startidx
+j
+1, "\helpref{%s}{%s}\n" % (c
, c
.lower()))
117 #print "new content is:"
118 #print ''.join(content)
121 file = open(treetex
[classname
], "w")
122 file.write(''.join(content
))
125 print " fixed the .tex file\n"
128 print "Total number of errors reported: %d" % fixed
129 print "There are %d files to fix manually:\n%s" % (len(tofix
), '\n'.join(tofix
))