]> git.lyx.org Git - lyx.git/blob - lib/doc/depend.py
generate TOC files on the fly and fix broken documents (bug 2027)
[lyx.git] / lib / doc / depend.py
1 #! /usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
3 # This file is part of the LyX Documentation
4 # Copyright (C) 2004 José Matos <jamatos@lyx.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 # This script creates a "master table of contents" for a set of LyX docs.
21 # It does so by going through the files and printing out all of the
22 # chapter, section, and sub(sub)section headings out. (It numbers the
23 # sections sequentially; hopefully noone's using Section* in the docs.)
24
25 import sys
26 import os
27
28 import re
29 from glob import glob
30
31 possible_documents = ("Intro", "FAQ", "Tutorial", "UserGuide", "Extended", "Customization")
32 lang_pattern = re.compile('^([a-z]{2})_')
33
34 def documents(srcdir, prefix):
35     result = []
36     for file in possible_documents:
37         fname = srcdir + '/' + prefix + file + '.lyx'
38         if os.access(fname, os.F_OK):
39             result.append(fname)
40         else:
41             result.append(srcdir + '/' + file + '.lyx')
42     return result
43
44
45 def main(argv):
46     print """# This is a Makefile for the TOC.lyx files.
47 # It was automatically generated by %s
48 #
49 # First come the rules for each xx_TOC.lyx file. Then comes the
50 # TOCs target, which prints all the TOC files.
51 """ % argv[0]
52
53     # What are the languages available? And its documents?
54     languages = {}
55     srcdir = os.path.dirname(argv[0])
56     for file in glob(srcdir + '/*'):
57         lang = lang_pattern.match(os.path.basename(file))
58         if lang:
59             if lang.group(1) not in languages:
60                 languages[lang.group(1)] = [file]
61             else:
62                 languages[lang.group(1)].append(file)
63
64     # sort languages alphabetically
65     langs = languages.keys()
66     langs.sort()
67
68     # The default language is english and doesn't need any prefix
69     print 'TOC.lyx:', ('.lyx ' + srcdir + '/').join(possible_documents) + '.lyx'
70     print '\tpython %s/doc_toc.py' % srcdir
71     print
72     tocs = ['TOC.lyx']
73
74     # Write rules for other languages
75     for lang in langs:
76         toc_name = lang + '_TOC.lyx'
77         tocs.append(toc_name)
78
79         if toc_name in languages[lang]:
80             languages[lang].remove(toc_name)
81         if srcdir + '/' + toc_name in languages[lang]:
82             languages[lang].remove(srcdir + '/' + toc_name)
83
84         print toc_name + ':', ' '.join(languages[lang])
85         print '\tpython %s/doc_toc.py %s' % (srcdir, lang)
86         print
87
88     # Write meta-rule to call all the other rules
89     print 'TOCs =', ' '.join(tocs)
90
91
92 if __name__ == "__main__":
93     main(sys.argv)