]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix translated docs makefile and scripts
authorJohn Mandereau <john.mandereau@gmail.com>
Mon, 25 Jun 2007 20:28:10 +0000 (22:28 +0200)
committerJohn Mandereau <john.mandereau@gmail.com>
Mon, 25 Jun 2007 20:28:10 +0000 (22:28 +0200)
* buildscripts/texi-gettext.py: gettext @ref's properly by eating
  trailing spaces and newlines.

* buildscripts/texi-gettext.py, make/doclang-targets.make: write
  gettexted *.texi to *.pdftexi to avoid makeinfo generate unwanted
  filenames.

* make/doclang-targets.make(local-WWW): use mass-link.py for merging
  output.

buildscripts/mass-link.py
buildscripts/texi-gettext.py
make/doclang-targets.make

index 1f0ff074c6455675661990620651e6ca0682e34a..61ea81e2db40a5f24036ab3117c3614be2294e3e 100644 (file)
@@ -1,10 +1,11 @@
 #!@PYTHON@
 # mass-link.py
 
-# USAGE:  mass-link.py   symbolic | hard   SOURCEDIR DESTDIR FILES
+# USAGE:  mass-link.py  [--prepend-suffix SUFFIX]   symbolic | hard   SOURCEDIR DESTDIR FILES
 #
 # create hard or symbolic links to SOURCEDIR/FILES in DESTDIR
 #
+# if --prepend-suffix is specified, link to foo.bar will be called fooSUFFIX.bar
 # shell-wildcard expansion is performed on FILES.
 
 print "mass_link.py"
@@ -12,9 +13,26 @@ print "mass_link.py"
 import sys
 import os
 import glob
-
-link_type, source_dir, dest_dir = sys.argv[1:4]
-files = sys.argv[4:]
+import getopt
+
+optlist, args = getopt.getopt (sys.argv[1:], '', ['prepend-suffix='])
+link_type, source_dir, dest_dir = args[0:3]
+files = args[3:]
+
+prepended_suffix = ''
+for x in optlist:
+    if x[0] == '--prepend-suffix':
+        prepended_suffix = x[1]
+
+if prepended_suffix:
+    def insert_suffix (p):
+        l = p.split ('.')
+        if len (l) >= 2:
+            l[-2] += prepended_suffix
+            return '.'.join (l)
+        return p + prepended_suffix
+else:
+    insert_suffix = lambda p: p
 
 if link_type == 'symbolic':
     link = os.symlink
@@ -28,7 +46,7 @@ sourcefiles = []
 for pattern in files:
     sourcefiles += (glob.glob (os.path.join (source_dir, pattern)))
 
-destfiles = map (lambda f: os.path.join (dest_dir, os.path.basename (f)), sourcefiles)
+destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (os.path.basename (f))), sourcefiles)
 
 def force_link (src,dest):
     if os.path.exists (dest):
index dcbcded41b4c82ac784ad6542aa8d2ef6aa55742..49cc62288b2cb7ce25fc3bec13e6c666096db33c 100644 (file)
@@ -4,8 +4,7 @@
 
 # USAGE:  texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
 #
-# -o OUTDIR specifies that output files should be written in OUTDIR
-#    rather than be overwritten
+# -o OUTDIR specifies that output files should rather be written in OUTDIR
 #
 
 print "texi_gettext.py"
@@ -16,7 +15,7 @@ import os
 import getopt
 import gettext
 
-optlist, args = getopt.getopt(sys.argv[1:],'o:')
+optlist, args = getopt.getopt (sys.argv[1:],'o:')
 buildscript_dir, localedir, lang = args[0:3]
 
 outdir = '.'
@@ -31,7 +30,11 @@ double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
 t = gettext.translation('lilypond-doc', localedir, [lang])
 _doc = t.gettext
 
-include_re = re.compile (r'@include (.*?)$', re.M)
+include_re = re.compile (r'@include ((?!lily-).*?)\.texi$', re.M)
+whitespaces = re.compile (r'\s+')
+ref_re = re.compile (r'(?ms)@(rglos|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)')
+menu_entry_re = re.compile (r'\* (.*?)::')
 
 # Why not use recode?
 # - well, it would add one more dependency...
@@ -94,32 +97,43 @@ accents2texi = (
 
 
 def title_gettext (m):
-       return '@' + m.group (1) + m.group (2) + _doc (m.group (3)) + m.group (4)
+       if m.group (2) == '{':
+               r = whitespaces.sub (' ', m.group (3))
+       else:
+               r = m.group (3)
+       return '@' + m.group (1) + m.group (2) + _doc (r) + m.group (4)
 
 def menu_entry_gettext (m):
        return '* ' + _doc (m.group (1)) + '::'
 
+def include_replace (m, filename):
+       if os.path.exists (os.path.join (os.path.dirname (filename), m.group(1)) + '.texi'):
+               return '@include ' + m.group(1) + '.pdftexi'
+       return m.group(0)
+
 def process_file (filename):
        print "Processing %s" % filename
        f = open (filename, 'r')
        page = f.read ()
        f.close()
-       page = re.sub (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)', title_gettext, page)
-       page = re.sub (r'(?L)@(rglos|ref)(\{)(.*?)(\})', title_gettext, page)
-       page = re.sub (r'\* (.*?)::', menu_entry_gettext, page)
+       page = node_section_re.sub (title_gettext, page)
+       page = ref_re.sub (title_gettext, page)
+       page = menu_entry_re.sub (menu_entry_gettext, page)
        page = page.replace ("""-- SKELETON FILE --
 When you actually translate this file, please remove these lines as
 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
        page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
+       includes = include_re.findall (page)
+       page = include_re.sub (lambda m: include_replace (m, filename), page)
        for (u_char, texiaccent_char) in accents2texi:
                page = page.replace (u_char, texiaccent_char)
-       p = os.path.join (outdir, filename)
+       p = os.path.join (outdir, filename) [:-4] + 'pdftexi'
        f = open (p, 'w')
        f.write (page)
        f.close ()
        dir = os.path.dirname (filename)
-       for file in include_re.findall (page):
-               p = os.path.join (dir, file)
+       for file in includes:
+               p = os.path.join (dir, file) + '.texi'
                if os.path.exists (p):
                        process_file (p)
 
index 1b21da230b9c261284c89158b3a4cc95e19a1c18..30a438692d2742bb56ad0b8abb258b0c3e048806 100644 (file)
@@ -14,7 +14,7 @@ $(outdir)/lilypond.nexi: $(ITELY_FILES) $(ITEXI_FILES)
 
 MAKEINFO = LANG=$(ISOLANG) $(MAKEINFO_PROGRAM) --force
 
-$(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi user-ln doc-po
+$(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi $(outdir)/user-ln doc-po
        mkdir -p $(dir $@)
        -$(MAKEINFO) -I$(outdir) --output=$(outdir)/lilypond --css-include=$(top-src-dir)/Documentation/texinfo.css --html $<
        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)
@@ -24,13 +24,14 @@ $(outdir)/lilypond/index.html: $(outdir)/lilypond.nexi user-ln doc-po
 #$(outdir)/lilypond.html: $(outdir)/lilypond.nexi
 #      -$(MAKEINFO) -I$(outdir) --output=$@ --css-include=$(top-src-dir)/Documentation/texinfo.css --html --no-split --no-headers $< 
 
-$(outdir)/%.pdf: $(outdir)/%.texi user-ln doc-po
+$(outdir)/%.pdf: $(outdir)/%.texi $(outdir)/user-ln doc-po
        $(PYTHON) $(buildscript-dir)/texi-gettext.py $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(ISOLANG) $<
-       cp $< $(<)~
-       cd $(outdir); texi2pdf --batch $(TEXINFO_PAPERSIZE_OPTION) $(<F)
+       cd $(outdir); texi2pdf --batch $(TEXINFO_PAPERSIZE_OPTION) $(notdir $*).pdftexi
 
 local-WWW: $(outdir)/lilypond.pdf $(outdir)/lilypond/index.html
-       $(foreach i, $(shell find $(outdir) -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME'), ln -f $(i) $(i:$(outdir)/%.html=$(depth)/Documentation/user/$(outdir)/%.$(ISOLANG).html) &&) ln -f $(outdir)/lilypond.pdf $(depth)/Documentation/user/$(outdir)/lilypond.$(ISOLANG).pdf && true
+       find $(outdir) -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/mass-link.py --prepend-suffix .$(ISOLANG) hard . $(depth)/Documentation/user/$(outdir) $(outdir)/lilypond.pdf
+# ugh, this is not enough to avoid wasting build time, $(outdir)/user-ln should be touched for all languages
+       touch -mr $(top-build-dir)/Documentation/user/$(outdir) $(outdir)/user-ln
 
 LINKED_PNGS = henle-flat-gray.png baer-flat-gray.png lily-flat-bw.png
 
@@ -39,7 +40,8 @@ LINKED_PNGS = henle-flat-gray.png baer-flat-gray.png lily-flat-bw.png
 # lilypond-book -I flag seems broken too, and texi2pdf -I flag confuses
 # pdfetex with .aux and other files from English manual
 # symlinking lily-*...
-user-ln:
+$(outdir)/user-ln: $(top-build-dir)/Documentation/user/$(outdir)
+       touch -mr $(top-build-dir)/Documentation/user/$(outdir) $@
        mkdir -p $(outdir)/lilypond
        $(PYTHON) $(buildscript-dir)/mass-link.py symbolic $(top-build-dir)/Documentation/user/$(outdir) $(outdir) 'lily-*.pdf' 'lily-*.tex' 'lily-*.texi' 'lily-*.ly' 'lily-*.txt' 'lily-*.png' 'henle-flat-gray.*' 'baer-flat-gray.*' 'lily-flat-bw.*'
        cd $(outdir)/lilypond && $(foreach i, $(LINKED_PNGS), ln -sf ../../$(depth)/Documentation/user/$(i) $(i) &&) true