2 # -*- coding: iso-8859-1 -*-
3 # This file is part of the LyX Documentation
4 # Copyright (C) 2004 José Matos <jamatos@lyx.org>
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.
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.
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.
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.)
28 srcdir = os.path.dirname(sys.argv[0])
31 sys.path.insert(0, srcdir + "/../lyx2lyx")
37 # Specific language information
38 # info["isoname"] = (language, language_quotes, enconding, TOC_translated)
39 info = { 'cs' : ('czech', 'german', 'latin2', "Obsah dokumentace LyXu"),
40 'da' : ('danish', 'german', 'latin1', "Indholdsfortegnelse over LyX's dokumentation"),
41 'de' : ('german', 'german', 'latin1', "Inhaltsverzeichnis LyX Dokumentation"),
42 'fr' : ('french', 'french', 'latin1', "Plan de la documentation"),
43 'ru' : ('russian', 'english', 'koi8-r', "LyX Documentation Table of Contents"),
44 'sl' : ('slovene', 'german', 'latin2', "Kazalo dokumentacije LyXa"),
45 'en' : ('english', 'english', 'latin1', "LyX Documentation Table of Contents")}
48 print """Usage: %s [lang]
50 lang is the language to build the TOC file, if not present use english.
54 transform_table = {'Title' : 'Section*', 'Chapter': 'Enumerate',
55 'Section':'Enumerate', 'Subsection': 'Enumerate',
56 'Subsubsection' : 'Enumerate'}
58 def build_from_toc(par_list):
62 if par_list[0].name == 'Title':
64 par.name = transform_table[par.name]
66 if len(par_list) == 1:
69 for i in range(1, len(par_list)):
70 if par_list[i].name == 'Title':
72 build_from_toc(par_list[1:i]) + \
73 build_from_toc(par_list[i:])
75 return [par] + build_from_toc(par_list[1:])
77 if par_list[0].name in ('Chapter', 'Section', 'Subsection', 'Subsubsection'):
78 return nest_struct(par_list[0].name, par_list)
81 def nest_struct(name, par_list):
82 if par_list[0].name == name:
84 par.name = transform_table[par.name]
86 if len(par_list) == 1:
89 for i in range(1, len(par_list)):
90 if par_list[i].name == name:
91 par.child = build_from_toc(par_list[1:i])
92 return [par] + build_from_toc(par_list[i:])
93 par.child = build_from_toc(par_list[1:])
102 # choose language and prefix for files
113 # Determine existing translated documents for that language.
115 for file in depend.documents(srcdir, pref):
116 file = LyX.File(input= file)
118 toc_general.extend(file.get_toc())
120 file = LyX.NewFile(output= pref + 'TOC.lyx')
122 file.set_header(language = data[0], language_quotes = data[1], inputencoding = "utf-8")
123 file.language = data[0]
124 file.encoding = "utf-8"
125 body = [ LyX.Paragraph('Title', [data[3]])]
126 body.extend(build_from_toc(toc_general))
131 if __name__ == "__main__":