X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fdoc%2Fdepend.py;h=deeb067afc9cef98d6c362a1f5dd3c260472e42b;hb=abcada9e13b72f57df00815d6a9f4a54a67009d3;hp=50df48a9056dee010ec9539b5dcb9882be3ff419;hpb=4ae87a3bb8503b5a672bb85448b11f08ebcfeffd;p=lyx.git diff --git a/lib/doc/depend.py b/lib/doc/depend.py index 50df48a905..deeb067afc 100644 --- a/lib/doc/depend.py +++ b/lib/doc/depend.py @@ -1,7 +1,7 @@ -#! /usr/bin/env python -tt -# -*- coding: iso-8859-1 -*- +#! /usr/bin/env python +# -*- coding: utf-8 -*- # This file is part of the LyX Documentation -# Copyright (C) 2004 José Matos +# Copyright (C) 2004 José Matos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -21,60 +21,71 @@ # 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.) +# It calls the script doc_toc.py using this syntax: +# depend.py doc_toc.py SetOfDocuments +# where SetOfDocuments is a set of documents 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})_') +possible_documents = ("Customization", "EmbeddedObjects", "Extended", "FAQ", "Intro", "Math", "Tutorial", "UserGuide") -def documents(srcdir, prefix): +def documents(srcdir, lang, dir_prefix = None): + '''Return documents for specified language. Translated files are in lang + directory. + ''' result = [] + if dir_prefix is None: + dir_prefix = srcdir for file in possible_documents: - fname = srcdir + '/' + prefix + file + '.lyx' + fname = os.path.join(srcdir, lang, file + '.lyx') if os.access(fname, os.F_OK): - result.append(fname) + result.append(os.path.join(dir_prefix, lang, file + '.lyx')) else: - result.append(srcdir + '/' + file + '.lyx') + result.append(os.path.join(dir_prefix, file + '.lyx')) return result +def all_documents(srcdir, dir_prefix = None): + '''Return available languages and its documents''' + languages = {} + if dir_prefix is None: + dir_prefix = srcdir + for dir in os.listdir(srcdir): + if os.path.isdir(os.path.join(srcdir, dir)) and len(dir) == 2: + languages[dir] = documents(srcdir, dir, dir_prefix) + # general, English language + if 'en' not in languages.keys(): + languages['en'] = documents(srcdir, 'en', dir_prefix) + return languages + + 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 +# First come the rules for each xx/TOC.lyx file. Then comes the # TOCs target, which prints all the TOC files. """ % os.path.basename(argv[0]) # What are the languages available? And its documents? - languages = {} - srcdir = os.path.dirname(argv[0]) - for file in glob(srcdir + '/*'): - file = os.path.basename(file) - lang = lang_pattern.match(file) - if lang: - if lang.group(1) not in languages: - languages[lang.group(1)] = [file] - else: - languages[lang.group(1)].append(file) + languages = all_documents(os.path.dirname(argv[0]), '') # sort languages alphabetically langs = languages.keys() langs.sort() - # The default language is english and doesn't need any prefix - print 'TOC.lyx: $(srcdir)/' + '.lyx $(srcdir)/'.join(possible_documents) + '.lyx' - print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py' - print - tocs = ['TOC.lyx'] + tocs = [] # Write rules for other languages for lang in langs: - toc_name = lang + '_TOC.lyx' + if lang != 'en': + toc_name = os.path.join(lang, 'TOC.lyx') + else: + # for English, because there is no 'en' directory + toc_name = 'TOC.lyx' tocs.append(toc_name) if toc_name in languages[lang]: @@ -82,7 +93,7 @@ def main(argv): languages[lang].sort() print toc_name + ': $(srcdir)/' + ' $(srcdir)/'.join(languages[lang]) - print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py %s' % lang + print '\tPYTHONPATH=$(top_builddir)/lib/lyx2lyx python -tt $(srcdir)/doc_toc.py %s .' % lang print # Write meta-rule to call all the other rules