| 1 | ############################################################################## |
| 2 | # Name: misc/scripts/update_doc_utils.py |
| 3 | # Purpose: base utilities for others update_doc_*.py scripts |
| 4 | # Created: 2007-08-1 |
| 5 | # RCS-ID: $Id$ |
| 6 | # Copyright: (c) 2007 Francesco Montorsi |
| 7 | # Licence: wxWindows licence |
| 8 | ############################################################################## |
| 9 | |
| 10 | import sys, os, glob, distutils.file_util |
| 11 | |
| 12 | DOCS_PATH="../../docs/latex/wx" |
| 13 | |
| 14 | # Calls the given callback with the name of a documented class, its .tex related file, |
| 15 | # the content of that .tex file and the number of the line of the relative \class tag, |
| 16 | # for all documented class in DOCS_PATH. If the callback returns false the processing is stopped. |
| 17 | # Returns the number of .tex files processed. |
| 18 | def scanTexFiles(callback): |
| 19 | count = 0 |
| 20 | for f in glob.glob(DOCS_PATH + '/*.tex'): |
| 21 | file = open(f, "r") |
| 22 | if not file: |
| 23 | print "could not open %s" % f |
| 24 | continue |
| 25 | print "opened file %s" % f |
| 26 | count = count + 1 |
| 27 | |
| 28 | # search \class tags |
| 29 | content = file.readlines() |
| 30 | classdecl = 0 |
| 31 | for i in range(len(content)): |
| 32 | line = content[i] |
| 33 | if "\class{" in line: |
| 34 | classdecl = classdecl + 1 |
| 35 | |
| 36 | # polish the class name |
| 37 | classname = line |
| 38 | classname = classname[classname.find("\class{"):] |
| 39 | classname = classname[classname.find("{")+1:classname.find("}")] |
| 40 | print " the class declared is named '%s'" % classname |
| 41 | |
| 42 | # process this \class |
| 43 | if not callback(classname, f, content, i): |
| 44 | return count |
| 45 | |
| 46 | print " file %s contains %d class declarations" % (f, classdecl) |
| 47 | |
| 48 | return count |
| 49 | |