]> git.saurik.com Git - wxWidgets.git/blame - misc/scripts/update_doc_baseclasses.py
compilation fix for wxUSE_STL==1
[wxWidgets.git] / misc / scripts / update_doc_baseclasses.py
CommitLineData
eaa78507
VZ
1##############################################################################\r
2# Name: misc/scripts/update_doc_baseclasses.py\r
3# Purpose: Warns about missing classes in the "Derived from" \r
4# sections in the doc files\r
5# Created: 2007-07-28\r
6# RCS-ID: $Id: makeunixtags.sh 46320 2007-06-04 11:02:29Z VZ $\r
7# Copyright: (c) 2007 Francesco Montorsi\r
8# Licence: wxWindows licence\r
9##############################################################################\r
10\r
11from update_doc_utils import scanTexFiles\r
12\r
13# classes whose docs cannot be fixed automatically\r
14# because of:\r
15# 1) multiple inheritance\r
16# 2) other strange things specific of these classes\r
17EXCEPTIONS=['wxNotebook','wxChoicebook','wxListbook','wxToolbook','wxTreebook','wxURLDataObject','wxHScrolledWindow','wxVScrolledWindow','wxVarHVScrollHelper','wxHVScrolledWindow','wxFileStream']\r
18\r
19def myCallback(classname, texFileName, content, i):\r
20 # now search the base classes for this class\r
21 baseclasses = []\r
22 for j in range(i,len(content)):\r
23 line = content[j]\r
24 if line.startswith("\wxheading{Derived from}"):\r
25 # take all lines contained between this \wxheading and the next one\r
26 # as base classes\r
27 for k in range(j+1,len(content)):\r
28 line = content[k]\r
29 if "\wxheading" in line:\r
30 break\r
31 elif "\helpref" in line:\r
32 baseclasses.append(line)\r
33 break # we've already processed the 'derived from' section for this class\r
34\r
35 if baseclasses == []:\r
36 print " no base classes declared for class %s" % classname\r
37 return True # keep going on with next \class tags\r
38\r
39 # polish baseclasses list\r
40 for i in range(len(baseclasses)):\r
41 s = baseclasses[i]\r
42 baseclasses[i] = s[s.find("{")+1:s.find("}")]\r
43\r
44 # store the baseclasses\r
45 tree[classname] = baseclasses\r
46 treetex[classname] = texFileName\r
47 treepos[classname] = j+1\r
48 print " class '%s' has %d base class(es): %s" % (classname, len(baseclasses), ','.join(baseclasses))\r
49\r
50 return True\r
51\r
52\r
53tree = dict()\r
54treetex = dict()\r
55treepos = dict()\r
56count = scanTexFiles(myCallback)\r
57\r
58print "\nProcessed %d files." % count\r
59print "\nNow starting to compare the base class lists.\n"\r
60\r
61def getFullListOfBaseClasses(classname):\r
62 if classname not in tree or classname=='':\r
63 return []\r
64\r
65 # only use the first base class of info taken from .tex files\r
66 # i.e. we assume that at least the first class declared as base class is always correct\r
67 baseclass = tree[classname][0]\r
68 return [baseclass] + getFullListOfBaseClasses(baseclass)\r
69\r
70# now compare the theorical list of base classes with the list of base\r
71# classes taken from the .tex files\r
72fixed=0\r
73tofix=set()\r
74for classname in tree:\r
75 theorical=getFullListOfBaseClasses(classname)\r
76 real=tree[classname]\r
77\r
78 # compare them\r
79 if real!=theorical:\r
80 print "* for class '%s' documented in '%s'" % (classname,treetex[classname])\r
81 print " theorical list: %s" % theorical\r
82 print " declared list: %s" % real\r
83\r
84 if classname in EXCEPTIONS:\r
85 tofix.add(treetex[classname])\r
86 print " cannot fix automatically (blacklisted class!)\n"\r
87 continue\r
88\r
89 # fix it!\r
90 file = open(treetex[classname], "r")\r
91 content = file.readlines()\r
92\r
93 #print "old content is:"\r
94 #print ''.join(content)\r
95\r
96 # remove old \helpref lines\r
97 startidx = treepos[classname]\r
98 count = 0\r
99 while count < len(tree[classname]):\r
100 # we want to remove n \helpref lines, where 'n' is the\r
101 # number of base classes declared\r
102 if content[startidx].startswith('\helpref'):\r
103 del content[startidx]\r
104 count = count+1\r
105 else:\r
106 startidx = startidx+1 # probably an empty line\r
107\r
108 # insert new ones\r
109 if len(theorical)>1:\r
110 for j in range(len(theorical)-1):\r
111 c = theorical[j]\r
112 content.insert(startidx+j, "\helpref{%s}{%s}\\\\\n" % (c, c.lower()))\r
113 else:\r
114 j=-1\r
115 c = theorical[j+1]\r
116 content.insert(startidx+j+1, "\helpref{%s}{%s}\n" % (c, c.lower()))\r
117\r
118 #print "new content is:"\r
119 #print ''.join(content)\r
120\r
121 # save the file\r
122 file = open(treetex[classname], "w")\r
123 file.write(''.join(content))\r
124 file.flush()\r
125\r
126 print " fixed the .tex file\n"\r
127 fixed=fixed+1\r
128\r
129print "Total number of errors reported: %d" % fixed\r
130print "There are %d files to fix manually:\n%s" % (len(tofix), '\n'.join(tofix))\r