From ce2ed4b97e50a4dfe6d585c24611761d4ca14d60 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Sat, 19 Apr 2008 16:41:15 +0200 Subject: [PATCH] Move langdefs.py to python, and clean up doc building scripts * move langdefs.py to python/, so that lilypond-book and scripts in buildscripts can load it more easily * move lilypond-doc gettext domain loading to langdefs.py (this avoids code duplication in a lot of doc building scripts) * match docs building with new lp-boo naming XX/lily-XXXXXXXX (this fixes a lot of broken ly images and lily-*.ly links) --- Documentation/GNUmakefile | 2 +- GNUmakefile.in | 4 +++- buildscripts/add_html_footer.py | 5 ++--- buildscripts/html-gettext.py | 16 +++++++--------- buildscripts/mass-link.py | 5 ++++- buildscripts/mirrortree.py | 2 +- buildscripts/texi-gettext.py | 18 ++++++++---------- buildscripts/www_post.py | 12 ++---------- make/doclang-rules.make | 2 +- make/doclang-targets.make | 4 ++-- make/lilypond-vars.make | 2 ++ {buildscripts => python}/langdefs.py | 15 +++++++++++++++ 12 files changed, 48 insertions(+), 39 deletions(-) rename {buildscripts => python}/langdefs.py (79%) diff --git a/Documentation/GNUmakefile b/Documentation/GNUmakefile index dbf4805d50..1524efc58b 100644 --- a/Documentation/GNUmakefile +++ b/Documentation/GNUmakefile @@ -1,7 +1,7 @@ depth = .. NAME = documentation -LANGS = $(shell $(PYTHON) $(buildscript-dir)/langdefs.py) +LANGS = $(shell $(PYTHON) $(top-src-dir)/python/langdefs.py) SUBDIRS=user bibliography pictures topdocs misc po $(LANGS) STEPMAKE_TEMPLATES=documentation texinfo tex LOCALSTEPMAKE_TEMPLATES=lilypond ly diff --git a/GNUmakefile.in b/GNUmakefile.in index fb0265a36e..92f33fb18a 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -30,6 +30,8 @@ INSTALLATION_FILES=$(config_make) VERSION # bootstrap stepmake: # STEPMAKE_TEMPLATES=toplevel po install +LOCALSTEPMAKE_TEMPLATES=lilypond + include $(depth)/make/stepmake.make @@ -85,7 +87,7 @@ local-WWW-post: echo -e 'AddDefaultCharset utf-8\nAddCharset utf-8 .html\nAddCharset utf-8 .en\nAddCharset utf-8 .nl\nAddCharset utf-8 .txt\n' > $(top-build-dir)/.htaccess $(PYTHON) $(buildscript-dir)/mutopia-index.py -o $(outdir)/examples.html input/ find $(outdir) -name '*-root' | xargs rm -rf - $(PYTHON) $(buildscript-dir)/www_post.py $(PACKAGE_NAME) $(TOPLEVEL_VERSION) $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(outdir) "$(WEB_TARGETS)" + $(PYTHON) $(buildscript-dir)/www_post.py $(PACKAGE_NAME) $(TOPLEVEL_VERSION) $(buildscript-dir) $(outdir) "$(WEB_TARGETS)" find $(outdir)/offline-root -type l -delete diff --git a/buildscripts/add_html_footer.py b/buildscripts/add_html_footer.py index bd7d8409ce..3c1bf0a225 100644 --- a/buildscripts/add_html_footer.py +++ b/buildscripts/add_html_footer.py @@ -231,15 +231,13 @@ def add_menu (page_flavors, prefix, available, target, translation): return page_flavors -def add_html_footer (translation, - package_name = '', +def add_html_footer (package_name = '', package_version = '', target = 'offline', name_filter = lambda s: s): """Add header, footer to a number of HTML files Arguments: - translation gettext translations dictionary, with language codes as keys package_name=NAME set package_name to NAME package_version=VERSION set package version to VERSION targets=offline|online set page processing depending on the target @@ -248,6 +246,7 @@ def add_html_footer (translation, negotiation name_filter a HTML file name filter """ + translation = langdefs.translation localtime = time.strftime ('%c %Z', time.localtime (time.time ())) if re.search ("http://", mail_address): diff --git a/buildscripts/html-gettext.py b/buildscripts/html-gettext.py index 65efe8f283..a63fc3c359 100644 --- a/buildscripts/html-gettext.py +++ b/buildscripts/html-gettext.py @@ -1,7 +1,7 @@ #!@PYTHON@ # html-gettext.py -# USAGE: html-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES +# USAGE: html-gettext.py [-o OUTDIR] LANG FILES # # -o OUTDIR specifies that output files should be written in OUTDIR # rather than be overwritten @@ -11,22 +11,20 @@ import sys import re import os import getopt -import gettext + +import langdefs optlist, args = getopt.getopt(sys.argv[1:],'o:') -buildscript_dir, localedir, lang = args[0:3] +lang = args[0] +files = args [1:] outdir = '.' for x in optlist: if x[0] == '-o': outdir = x[1] -sys.path.append (buildscript_dir) -import langdefs - double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep -t = gettext.translation('lilypond-doc', localedir, [lang]) -my_gettext = t.gettext +my_gettext = langdefs.translation[lang] html_codes = ((' -- ', ' – '), (' --- ', ' — ')) @@ -80,7 +78,7 @@ def h_gettext (m): def crossmanual_ref_gettext (m): return '' + _(m.group(2)) + '' -for filename in args[3:]: +for filename in files: f = open (filename, 'r') page = f.read () f.close() diff --git a/buildscripts/mass-link.py b/buildscripts/mass-link.py index 947cd8ccef..17412e5559 100644 --- a/buildscripts/mass-link.py +++ b/buildscripts/mass-link.py @@ -54,7 +54,10 @@ def relative_path (f): return f return f[len (source_dir) + 1:] -destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (relative_path (f))), sourcefiles) +destfiles = [os.path.join (dest_dir, insert_suffix (relative_path (f))) for f in sourcefiles] + +destdirs = set ([os.path.dirname (dest) for dest in destfiles]) +[os.makedirs (d) for d in destdirs if not os.path.exists (d)] def force_link (src,dest): if os.path.exists (dest): diff --git a/buildscripts/mirrortree.py b/buildscripts/mirrortree.py index 507d56639a..0aa0bc8812 100644 --- a/buildscripts/mirrortree.py +++ b/buildscripts/mirrortree.py @@ -41,7 +41,7 @@ def walk_tree (tree_roots = [], for current_dir, dirs, files in os.walk(d): i = 0 while i < len(dirs): - if exclude_dirs_re.search (dirs[i]): + if exclude_dirs_re.search (os.path.join (current_dir, dirs[i])): del dirs[i] else: p = os.path.join (current_dir, dirs[i]) diff --git a/buildscripts/texi-gettext.py b/buildscripts/texi-gettext.py index 2c99352666..8fbc2243b7 100644 --- a/buildscripts/texi-gettext.py +++ b/buildscripts/texi-gettext.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # texi-gettext.py -# USAGE: texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES +# USAGE: texi-gettext.py [-o OUTDIR] LANG FILES # # -o OUTDIR specifies that output files should rather be written in OUTDIR # @@ -13,24 +13,22 @@ import sys import re import os import getopt -import gettext + +import langdefs optlist, args = getopt.getopt (sys.argv[1:],'o:') -buildscript_dir, localedir, lang = args[0:3] +lang = args[0] +files = args[1:] outdir = '.' for x in optlist: if x[0] == '-o': outdir = x[1] -sys.path.append (buildscript_dir) -import langdefs - double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep -t = gettext.translation('lilypond-doc', localedir, [lang]) -_doc = t.gettext +_doc = langdefs.translation[lang] -include_re = re.compile (r'@include ((?!lily-).*?)\.texi$', re.M) +include_re = re.compile (r'@include ((?!../lily-).*?)\.texi$', re.M) whitespaces = re.compile (r'\s+') ref_re = re.compile (r'(?ms)@(rglos|ruser|rprogram|ref)(\{)(.*?)(\})') node_section_re = re.compile (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)') @@ -75,5 +73,5 @@ well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '') if os.path.exists (p): process_file (p) -for filename in args[3:]: +for filename in files: process_file (filename) diff --git a/buildscripts/www_post.py b/buildscripts/www_post.py index 278895aff9..b2d7ca510c 100644 --- a/buildscripts/www_post.py +++ b/buildscripts/www_post.py @@ -9,9 +9,8 @@ import sys import os import re -import gettext -package_name, package_version, buildscript_dir, localedir, outdir, targets = sys.argv[1:] +package_name, package_version, buildscript_dir, outdir, targets = sys.argv[1:] targets = targets.split (' ') outdir = os.path.normpath (outdir) doc_dirs = ['input', 'Documentation', outdir] @@ -49,7 +48,7 @@ sys.stderr.write ("Mirrorring...\n") dirs, symlinks, files = mirrortree.walk_tree ( tree_roots = doc_dirs, process_dirs = outdir, - exclude_dirs = '(^|/)(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + r'|po|out|.*?[.]t2d|\w*?-root)(/|$)', + exclude_dirs = '(^|/)(' + r'|po|out|out-test|.*?[.]t2d|\w*?-root)(/|$)|Documentation/(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + ')', find_files = r'.*?\.(?:midi|html|pdf|png|txt|ly|signature)$|VERSION', exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)') @@ -92,17 +91,10 @@ if 'online' in targets: f.write ('#.htaccess\nDirectoryIndex index\n') f.close () -# load gettext messages catalogs -translation = {} -for l in langdefs.LANGUAGES: - if l.enabled and l.code != 'en': - translation[l.code] = gettext.translation('lilypond-doc', localedir, [l.code]).gettext - add_html_footer.build_pages_dict (html_files) for t in targets: sys.stderr.write ("Processing HTML pages for %s target...\n" % t) add_html_footer.add_html_footer ( - translation = translation, package_name = package_name, package_version = package_version, target = t, diff --git a/make/doclang-rules.make b/make/doclang-rules.make index 3a82132ec9..6c4dbc532d 100644 --- a/make/doclang-rules.make +++ b/make/doclang-rules.make @@ -6,7 +6,7 @@ $(outdir)/%-big-page.html: $(outdir)/%.texi $(outdir)/version.itexi -$(MAKEINFO) -P $(outdir) --output=$@ --css-include=$(top-src-dir)/Documentation/texinfo.css --html --no-split --no-headers $< $(outdir)/%.pdftexi: $(outdir)/%.texi doc-po $(outdir)/version.itexi - $(PYTHON) $(buildscript-dir)/texi-gettext.py $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(ISOLANG) $< + $(PYTHON) $(buildscript-dir)/texi-gettext.py $(ISOLANG) $< $(outdir)/%.pdf: $(outdir)/%.pdftexi cd $(outdir); texi2pdf $(TEXI2PDF_FLAGS) $(TEXINFO_PAPERSIZE_OPTION) $(notdir $*).pdftexi diff --git a/make/doclang-targets.make b/make/doclang-targets.make index 4f4750c9a7..4fd4bad694 100644 --- a/make/doclang-targets.make +++ b/make/doclang-targets.make @@ -2,9 +2,9 @@ default: # BIG_PAGE_HTML_FILES is defined differently in each language makefile local-WWW: $(DEEP_HTML_FILES) $(PDF_FILES) doc-po $(BIG_PAGE_HTML_FILES) - find $(outdir) -name '*.html' | xargs grep -L 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/html-gettext.py $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(ISOLANG) + find $(outdir) -name '*.html' | xargs grep -L 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/html-gettext.py $(ISOLANG) find $(outdir) -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME' | sed 's!$(outdir)/!!g' | xargs $(PYTHON) $(buildscript-dir)/mass-link.py --prepend-suffix .$(ISOLANG) hard $(outdir) $(top-build-dir)/Documentation/user/$(outdir) $(TELY_FILES:%.tely=%.pdf) - find $(outdir) \( -name 'lily-??????????.png' -o -name 'lily-??????????.ly' \) | sed 's!$(outdir)/!!g' | xargs $(PYTHON) $(buildscript-dir)/mass-link.py hard $(outdir) $(top-build-dir)/Documentation/user/$(outdir) + find $(outdir) \( -name 'lily-*.png' -o -name 'lily-*.ly' \) | sed 's!$(outdir)/!!g' | xargs $(PYTHON) $(buildscript-dir)/mass-link.py hard $(outdir) $(top-build-dir)/Documentation/user/$(outdir) doc-po: $(MAKE) -C $(depth)/Documentation/po out=www messages diff --git a/make/lilypond-vars.make b/make/lilypond-vars.make index 6096bfb790..7fa9aa9ab3 100644 --- a/make/lilypond-vars.make +++ b/make/lilypond-vars.make @@ -48,6 +48,8 @@ endif TEXINPUTS=$(top-src-dir)/tex/:: export TEXINPUTS +export LYDOC_LOCALEDIR:= $(top-build-dir)/Documentation/po/out-www + #texi-html for www only: LILYPOND_BOOK_FORMAT=$(if $(subst out-www,,$(notdir $(outdir))),texi,texi-html) LY2DVI = $(LILYPOND_BINARY) diff --git a/buildscripts/langdefs.py b/python/langdefs.py similarity index 79% rename from buildscripts/langdefs.py rename to python/langdefs.py index 4c9a0a7d8b..2b79caee70 100644 --- a/buildscripts/langdefs.py +++ b/python/langdefs.py @@ -62,3 +62,18 @@ else: LANGDICT = {} for l in LANGUAGES: LANGDICT[l.code] = l + + try: + import gettext + import os + + translation = {} + for l in LANGUAGES: + if l.enabled and l.code != 'en': + t = gettext.translation('lilypond-doc', + os.environ['LYDOC_LOCALEDIR'], + [l.code]) + translation[l.code] = t.gettext + except: + sys.stderr.write ('URGUHIU\n') + translation = dict ([(l.code, lambda x: x) for l in LANGUAGES]) -- 2.39.2