]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/build/extract_texi_filenames.py
Build updates to get rid of website warnings
[lilypond.git] / scripts / build / extract_texi_filenames.py
index 61f6014e160894808a8c1cde678b0e24b861abfa..fcb464d53d07b4ef7a99cfaccce2a0d1d1ea7cab 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
@@ -29,7 +37,8 @@ import getopt
 options_list, files = getopt.getopt (sys.argv[1:],'o:s:hI:m:',
                                      ['output=', 'split=',
                                       'help', 'include=',
-                                      'master-map-file='])
+                                      'master-map-file=',
+                                      'known-missing-files='])
 
 help_text = r"""Usage: %(program_name)s [OPTIONS]... TEXIFILE...
 Extract files names for texinfo (sub)sections from the texinfo files.
@@ -41,6 +50,8 @@ Options:
  -o, --output=DIRECTORY         write .xref-map files to DIRECTORY
  -s, --split=MODE               split manual according to MODE. Possible values
                                 are section and custom (default)
+     --known-missing-files      a filename which has a list of files known
+                                to be missing for this make
 """
 
 def help (text):
@@ -51,6 +62,8 @@ outdir = '.'
 split = "custom"
 include_path = ['.',]
 master_map_file = ''
+known_missing_files = []
+known_missing_files_file = ''
 initial_map = {}
 for opt in options_list:
     o = opt[0]
@@ -69,16 +82,25 @@ for opt in options_list:
     elif o == '-m' or o == '--master-map-file':
         if os.path.isfile (a):
             master_map_file = a
+    elif o == '--known-missing-files':
+        if os.path.isfile (a):
+            known_missing_files_file = a
+        else:
+            print 'Missing files list file not found: ', a
     else:
         raise Exception ('unknown option: ' + o)
 
+if known_missing_files_file:
+    missing_files = open (known_missing_files_file, 'r')
+    known_missing_files = missing_files.read().splitlines()
+    missing_files.close()
 
 if not os.path.isdir (outdir):
     if os.path.exists (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|\
@@ -96,8 +118,10 @@ def expand_includes (m, filename):
             filepath = os.path.join (directory, include_name)
             if os.path.exists (filepath):
                 return extract_sections (filepath)[1]
-        print 'No such file: ' + include_name
-        print 'Search path: ' + ':'.join (include_path)
+        if not (include_name in known_missing_files):
+            # Not found
+            print 'No such file: ' + include_name
+            print 'Search path: ' + ':'.join (include_path)
         return ''
 
 lang_re = re.compile (r'^@documentlanguage (.+)', re.M)
@@ -154,9 +178,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))
@@ -227,7 +252,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])