2006-06-30 13:54:01 +00:00
|
|
|
|
#! /usr/bin/env python -tt
|
2004-10-17 19:12:33 +00:00
|
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
|
# This file is part of the LyX Documentation
|
|
|
|
|
# Copyright (C) 2004 Jos<6F> Matos <jamatos@lyx.org>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
|
# This script creates a "master table of contents" for a set of LyX docs.
|
|
|
|
|
# It does so by going through the files and printing out all of the
|
|
|
|
|
# chapter, section, and sub(sub)section headings out. (It numbers the
|
|
|
|
|
# sections sequentially; hopefully noone's using Section* in the docs.)
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
from glob import glob
|
|
|
|
|
|
|
|
|
|
possible_documents = ("Intro", "FAQ", "Tutorial", "UserGuide", "Extended", "Customization")
|
|
|
|
|
lang_pattern = re.compile('^([a-z]{2})_')
|
|
|
|
|
|
2005-09-28 13:47:03 +00:00
|
|
|
|
def documents(srcdir, prefix):
|
2004-10-17 19:12:33 +00:00
|
|
|
|
result = []
|
|
|
|
|
for file in possible_documents:
|
2005-09-28 13:47:03 +00:00
|
|
|
|
fname = srcdir + '/' + prefix + file + '.lyx'
|
2004-10-17 19:12:33 +00:00
|
|
|
|
if os.access(fname, os.F_OK):
|
|
|
|
|
result.append(fname)
|
2005-09-28 13:47:03 +00:00
|
|
|
|
else:
|
|
|
|
|
result.append(srcdir + '/' + file + '.lyx')
|
2004-10-17 19:12:33 +00:00
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
|
print """# This is a Makefile for the TOC.lyx files.
|
|
|
|
|
# It was automatically generated by %s
|
|
|
|
|
#
|
|
|
|
|
# First come the rules for each xx_TOC.lyx file. Then comes the
|
|
|
|
|
# TOCs target, which prints all the TOC files.
|
2005-10-05 09:01:17 +00:00
|
|
|
|
""" % os.path.basename(argv[0])
|
2004-10-17 19:12:33 +00:00
|
|
|
|
|
|
|
|
|
# What are the languages available? And its documents?
|
|
|
|
|
languages = {}
|
2005-09-28 13:47:03 +00:00
|
|
|
|
srcdir = os.path.dirname(argv[0])
|
|
|
|
|
for file in glob(srcdir + '/*'):
|
2005-10-05 09:01:17 +00:00
|
|
|
|
file = os.path.basename(file)
|
|
|
|
|
lang = lang_pattern.match(file)
|
2004-10-17 19:12:33 +00:00
|
|
|
|
if lang:
|
|
|
|
|
if lang.group(1) not in languages:
|
|
|
|
|
languages[lang.group(1)] = [file]
|
|
|
|
|
else:
|
|
|
|
|
languages[lang.group(1)].append(file)
|
|
|
|
|
|
|
|
|
|
# sort languages alphabetically
|
|
|
|
|
langs = languages.keys()
|
|
|
|
|
langs.sort()
|
|
|
|
|
|
|
|
|
|
# The default language is english and doesn't need any prefix
|
2005-10-05 09:01:17 +00:00
|
|
|
|
print 'TOC.lyx: $(srcdir)/' + '.lyx $(srcdir)/'.join(possible_documents) + '.lyx'
|
2006-06-30 13:54:01 +00:00
|
|
|
|
print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py'
|
2004-10-17 19:12:33 +00:00
|
|
|
|
print
|
|
|
|
|
tocs = ['TOC.lyx']
|
|
|
|
|
|
|
|
|
|
# Write rules for other languages
|
|
|
|
|
for lang in langs:
|
|
|
|
|
toc_name = lang + '_TOC.lyx'
|
|
|
|
|
tocs.append(toc_name)
|
|
|
|
|
|
2005-09-28 13:47:03 +00:00
|
|
|
|
if toc_name in languages[lang]:
|
|
|
|
|
languages[lang].remove(toc_name)
|
2005-12-16 10:44:00 +00:00
|
|
|
|
languages[lang].sort()
|
2004-10-17 19:12:33 +00:00
|
|
|
|
|
2005-10-05 09:01:17 +00:00
|
|
|
|
print toc_name + ': $(srcdir)/' + ' $(srcdir)/'.join(languages[lang])
|
2006-06-30 13:54:01 +00:00
|
|
|
|
print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py %s' % lang
|
2004-10-17 19:12:33 +00:00
|
|
|
|
print
|
|
|
|
|
|
|
|
|
|
# Write meta-rule to call all the other rules
|
2005-10-05 09:01:17 +00:00
|
|
|
|
print 'tocfiles =', ' '.join(tocs)
|
2004-10-17 19:12:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main(sys.argv)
|