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