]> git.donarmstrong.com Git - lilypond.git/commitdiff
Move langdefs.py to python, and clean up doc building scripts
authorJohn Mandereau <john.mandereau@gmail.com>
Sat, 19 Apr 2008 14:41:15 +0000 (16:41 +0200)
committerJohn Mandereau <john.mandereau@gmail.com>
Sat, 19 Apr 2008 14:41:15 +0000 (16:41 +0200)
* 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)

13 files changed:
Documentation/GNUmakefile
GNUmakefile.in
buildscripts/add_html_footer.py
buildscripts/html-gettext.py
buildscripts/langdefs.py [deleted file]
buildscripts/mass-link.py
buildscripts/mirrortree.py
buildscripts/texi-gettext.py
buildscripts/www_post.py
make/doclang-rules.make
make/doclang-targets.make
make/lilypond-vars.make
python/langdefs.py [new file with mode: 0644]

index dbf4805d50c3dd3b45b38566e0c5028a2517b270..1524efc58b2966e1e573ece1600f37f37235f3d0 100644 (file)
@@ -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
index fb0265a36e9db80362aa45aee927b31d27ffeb65..92f33fb18ada3db9a4d24f7bf156a26536709b29 100644 (file)
@@ -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
 
 
index bd7d8409cee5af622e6792fde092fda347776e0f..3c1bf0a22594e05281716a780e27f42d209f364f 100644 (file)
@@ -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):
index 65efe8f28396637b75ffd2f2fea7655632205066..a63fc3c3592649524533dc9c77af0a0ba46c145c 100644 (file)
@@ -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 = ((' -- ', ' &ndash; '),
              (' --- ', ' &mdash; '))
@@ -80,7 +78,7 @@ def h_gettext (m):
 def crossmanual_ref_gettext (m):
        return '<a href="' + m.group(1) + '">' + _(m.group(2)) + '</a>'
 
-for filename in args[3:]:
+for filename in files:
        f = open (filename, 'r')
        page = f.read ()
        f.close()
diff --git a/buildscripts/langdefs.py b/buildscripts/langdefs.py
deleted file mode 100644 (file)
index 4c9a0a7..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-#!@PYTHON@
-#-*- coding: utf-8 -*-
-
-"""
-Documentation i18n module
-"""
-
-import re
-
-def lang_file_name (p, langext, ext):
-    if langext != '':
-        return p + '.' + langext + ext
-    return p + ext
-
-class LanguageDef:
-    def __init__ (self, code, name, webext=None, double_punct_char_sep='', html_filter=lambda s: s):
-        self.code = code
-        self.name = name
-        self.enabled = True
-        if webext == None:
-            self.webext = self.code
-        else:
-            self.webext = webext
-        self.double_punct_char_sep = double_punct_char_sep
-        self.html_filter = html_filter
-    
-    def file_name (self, prefix, ext):
-        return lang_file_name (prefix, self.webext, ext)
-
-
-# All language information needed for documentation i18n is defined
-# here. For each 'Documentation/ab' directory containing docs
-# translated in 'ab', there should be one entry in LANGUAGES.
-
-site = LanguageDef ('en', 'English', webext='')
-
-html_page_body = re.compile ('</?body>', re.M | re.I)
-french_html_typo_rules = ((' :', '&nbsp;:'),
-                          (' ;', '&nbsp;;'),
-                          (' ?', '&thinsp;?'),
-                          (' !', '&thinsp;!'))
-
-def french_html_filter (page):
-    parts = html_page_body.split (page)
-    for r in french_html_typo_rules:
-        parts[1] = parts[1].replace (r[0], r[1])
-    return parts[0] + '<body>' + parts[1] + '</body>' + parts[2]
-
-fr = LanguageDef ('fr', 'français', double_punct_char_sep='&nbsp;', html_filter = french_html_filter)
-es = LanguageDef ('es', 'español')
-de = LanguageDef ('de', 'deutsch')
-
-# Outdated or broken translations may be disabled
-# (please run 'make web-clean' before doing that):
-#fr.enabled = False
-
-LANGUAGES = (site, fr, es, de)
-
-if __name__ == '__main__':
-    print ' '.join ([l.code for l in LANGUAGES if l.enabled and l.code != 'en'])
-else:
-    LANGDICT = {}
-    for l in LANGUAGES:
-        LANGDICT[l.code] = l
index 947cd8ccef5a47990a4796a4d6b0c62d1be3619c..17412e5559f6aa7b34a0a17c5e1561703aaa3bff 100644 (file)
@@ -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):
index 507d56639ae8ad1723073abbd9c184f991722943..0aa0bc881270f2cf6e3263d2e904ab51dbe407c2 100644 (file)
@@ -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])
index 2c993526660c9d7e0eef033237b84da92f20ccf8..8fbc2243b749b21a00a002e12b4243b3cea447d9 100644 (file)
@@ -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)
index 278895aff93b7cc51ea73e9cd980fe932cfa2e0b..b2d7ca510cb9bf663e3697d958709bce57acb96d 100644 (file)
@@ -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,
index 3a82132ec954a8e347d67d0baac422af3cee98f4..6c4dbc532ddd88713ae0c41e9e8511e84c0b11a7 100644 (file)
@@ -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
index 4f4750c9a72d6c666be1913889b5e0ad7b339222..4fd4bad6948c430cfdc0a5f50813001b3db178a5 100644 (file)
@@ -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
index 6096bfb790c78d417a80faa58e18577bd08181d0..7fa9aa9ab3f222dee7bddbbb27568213651716f0 100644 (file)
@@ -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/python/langdefs.py b/python/langdefs.py
new file mode 100644 (file)
index 0000000..2b79cae
--- /dev/null
@@ -0,0 +1,79 @@
+#!@PYTHON@
+#-*- coding: utf-8 -*-
+
+"""
+Documentation i18n module
+"""
+
+import re
+
+def lang_file_name (p, langext, ext):
+    if langext != '':
+        return p + '.' + langext + ext
+    return p + ext
+
+class LanguageDef:
+    def __init__ (self, code, name, webext=None, double_punct_char_sep='', html_filter=lambda s: s):
+        self.code = code
+        self.name = name
+        self.enabled = True
+        if webext == None:
+            self.webext = self.code
+        else:
+            self.webext = webext
+        self.double_punct_char_sep = double_punct_char_sep
+        self.html_filter = html_filter
+    
+    def file_name (self, prefix, ext):
+        return lang_file_name (prefix, self.webext, ext)
+
+
+# All language information needed for documentation i18n is defined
+# here. For each 'Documentation/ab' directory containing docs
+# translated in 'ab', there should be one entry in LANGUAGES.
+
+site = LanguageDef ('en', 'English', webext='')
+
+html_page_body = re.compile ('</?body>', re.M | re.I)
+french_html_typo_rules = ((' :', '&nbsp;:'),
+                          (' ;', '&nbsp;;'),
+                          (' ?', '&thinsp;?'),
+                          (' !', '&thinsp;!'))
+
+def french_html_filter (page):
+    parts = html_page_body.split (page)
+    for r in french_html_typo_rules:
+        parts[1] = parts[1].replace (r[0], r[1])
+    return parts[0] + '<body>' + parts[1] + '</body>' + parts[2]
+
+fr = LanguageDef ('fr', 'français', double_punct_char_sep='&nbsp;', html_filter = french_html_filter)
+es = LanguageDef ('es', 'español')
+de = LanguageDef ('de', 'deutsch')
+
+# Outdated or broken translations may be disabled
+# (please run 'make web-clean' before doing that):
+#fr.enabled = False
+
+LANGUAGES = (site, fr, es, de)
+
+if __name__ == '__main__':
+    print ' '.join ([l.code for l in LANGUAGES if l.enabled and l.code != 'en'])
+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])