]> git.lyx.org Git - lyx.git/blob - lib/doc/depend.py
* Change the dim parameter correctly, even if dim_ has not changed
[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
30 possible_documents = ("Intro", "FAQ", "Tutorial", "UserGuide", "EmbeddedObjects", "Extended", "Customization")
31
32 def documents(srcdir, lang, dir_prefix = None):
33     '''Return documents for specified language. Translated files are in lang 
34        directory.
35     '''
36     result = []
37     if dir_prefix is None:
38         dir_prefix = srcdir
39     for file in possible_documents:
40         fname = os.path.join(srcdir, lang, file + '.lyx')
41         if os.access(fname, os.F_OK):
42             result.append(os.path.join(dir_prefix, lang, file + '.lyx'))
43         else:
44             result.append(os.path.join(dir_prefix, file + '.lyx'))
45     return result
46
47
48 def all_documents(srcdir, dir_prefix = None):
49     '''Return available languages and its documents'''
50     languages = {}
51     if dir_prefix is None:
52         dir_prefix = srcdir
53     for dir in os.listdir(srcdir):
54         if os.path.isdir(os.path.join(srcdir, dir)) and len(dir) == 2:
55             languages[dir] = documents(srcdir, dir, dir_prefix)
56     # general, English language
57     if 'en' not in languages.keys():
58         languages['en'] = documents(srcdir, 'en', dir_prefix)
59     return languages
60   
61     
62 def main(argv):
63     print """# This is a Makefile for the TOC.lyx files.
64 # It was automatically generated by %s
65 #
66 # First come the rules for each xx/TOC.lyx file. Then comes the
67 # TOCs target, which prints all the TOC files.
68 """ % os.path.basename(argv[0])
69
70     # What are the languages available? And its documents?
71     languages = all_documents(os.path.dirname(argv[0]), '')
72
73     # sort languages alphabetically
74     langs = languages.keys()
75     langs.sort()
76
77     tocs = []
78
79     # Write rules for other languages
80     for lang in langs:
81         if lang != 'en':
82             toc_name = os.path.join(lang, 'TOC.lyx')
83         else:
84             # for English, because there is no 'en' directory
85             toc_name = 'TOC.lyx'
86         tocs.append(toc_name)
87
88         if toc_name in languages[lang]:
89             languages[lang].remove(toc_name)
90         languages[lang].sort()
91
92         print toc_name + ': $(srcdir)/' + ' $(srcdir)/'.join(languages[lang])
93         print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py %s .' % lang
94         print
95
96     # Write meta-rule to call all the other rules
97     print 'tocfiles =', ' '.join(tocs)
98
99
100 if __name__ == "__main__":
101     main(sys.argv)