]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/build/extract_texi_filenames.py
Merge branch 'instrumentName-groups'
[lilypond.git] / scripts / build / extract_texi_filenames.py
index f91bae398250d0e283baca5743138d56f0af47bd..fda8fc1d6168854a39016ab2ad6f8b889dff55e6 100644 (file)
 #        NODE\tFILENAME\tANCHOR
 # LANG is the document language in case it's not 'en'
 # Note: The filename does not have any extension appended!
-# This file can then be used by our texi2html init script to determine
+# This file should then be used by our texi2html init script to determine
 # the correct file name and anchor for external refs
 
+# For translated documentation: cross-references to nodes that exist
+# only in documentation in English are allowed, that's why the already
+# generated map file of docs in English is loaded with
+# --master-map-file option, then the node names that are defined in
+# the map for the manual in English but not in the translated manual
+# are added to the map for the translated manual.
+
+
 import sys
 import re
 import os
@@ -49,7 +57,7 @@ def help (text):
 
 outdir = '.'
 split = "custom"
-include_path = []
+include_path = ['.',]
 master_map_file = ''
 initial_map = {}
 for opt in options_list:
@@ -78,7 +86,7 @@ if not os.path.isdir (outdir):
         os.unlink (outdir)
     os.makedirs (outdir)
 
-include_re = re.compile (r'@include ((?!../lily-).*?\.i?texi)$', re.M)
+include_re = re.compile (r'@include ((?!../lily-).*?\.i?te(xi|ly))$', re.M)
 whitespaces = re.compile (r'\s+')
 section_translation_re = re.compile ('^@(node|(?:unnumbered|appendix)\
 (?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|\
@@ -87,15 +95,17 @@ section_translation_re = re.compile ('^@(node|(?:unnumbered|appendix)\
 external_node_re = re.compile (r'\s+@c\s+external.*')
 
 def expand_includes (m, filename):
-    filepath = os.path.join (os.path.dirname (filename), m.group(1))
+    include_name = m.group (1)
+    filepath = os.path.join (os.path.dirname (filename), include_name)
     if os.path.exists (filepath):
         return extract_sections (filepath)[1]
     else:
         for directory in include_path:
-            filepath = os.path.join (directory, m.group(1))
+            filepath = os.path.join (directory, include_name)
             if os.path.exists (filepath):
                 return extract_sections (filepath)[1]
-        print 'No such file: ' + filepath
+        print 'No such file: ' + include_name
+        print 'Search path: ' + ':'.join (include_path)
         return ''
 
 lang_re = re.compile (r'^@documentlanguage (.+)', re.M)
@@ -152,9 +162,10 @@ def texinfo_file_name(title):
         result = 't_g' + result
     return result
 
-texinfo_re = re.compile (r'@.*{(.*)}')
+texinfo_re = re.compile (r'@.*?{(.*?)}')
 def remove_texinfo (title):
-    return texinfo_re.sub (r'\1', title)
+    title = title.replace ('--', '-')
+    return texinfo_re.sub (r'\1', title).strip ()
 
 def create_texinfo_anchor (title):
     return texinfo_file_name (remove_texinfo (title))
@@ -183,6 +194,7 @@ def process_sections (filename, lang_suffix, page):
     sections = section_translation_re.findall (page)
     basename = os.path.splitext (os.path.basename (filename))[0]
     p = os.path.join (outdir, basename) + lang_suffix + '.xref-map'
+    print 'writing:', p
     f = open (p, 'w')
 
     this_title = ''
@@ -224,7 +236,7 @@ def process_sections (filename, lang_suffix, page):
             # treat this case here, too: If we already had a section
             # and encounter another one before the next @node, we
             # write out the old one and start with the new values
-            if had_section and this_title:
+            if had_section and split != 'node' and this_title:
                 f.write (this_title + "\t" + this_filename + "\t" + this_anchor + "\n")
                 this_title = remove_texinfo (sec[1])
                 this_anchor = create_texinfo_anchor (sec[1])