update_doc_libs.py 3.6 KB

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