]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/lys-to-tely.py
Merge branch 'stable'
[lilypond.git] / buildscripts / lys-to-tely.py
index c026522434e37b77a453592aaca71487c2e5b1b3..c9d698f92cea0764b2e608a7bda5c4b75b9f35a6 100644 (file)
@@ -12,14 +12,13 @@ TODO:
 import sys
 import os
 import getopt
+import re
 
 program_name = 'lys-to-tely'
 
 include_snippets = '@lysnippets'
 fragment_options = 'printfilename,texidoc'
-
-def help ():
-    sys.stdout.write (r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
+help_text = r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
 Construct tely doc from LY-FILEs.
 
 Options:
@@ -32,7 +31,10 @@ Options:
    instead of standard template; TEMPLATE should contain a command
    '%(include_snippets)s' to tell where to insert LY-FILEs.  When this
    option is used, NAME and TITLE are ignored.
-""" % vars ())
+"""
+
+def help (text):
+    sys.stdout.write ( text)
     sys.exit (0)
 
 (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
@@ -42,7 +44,7 @@ name = "ly-doc"
 title = "Ly Doc"
 template = '''\input texinfo
 @setfilename %%(name)s.info
-@settitle %%(name)s
+@settitle %%(title)s
 
 @documentencoding utf-8
 @iftex
@@ -58,6 +60,7 @@ template = '''\input texinfo
 @end ignore
 
 @node Top, , , (dir)
+@top %%(title)s
 
 %s
 
@@ -68,7 +71,10 @@ for opt in options:
     o = opt[0]
     a = opt[1]
     if o == '-h' or o == '--help':
-        help ()
+        # We can't use vars () inside a function, as that only contains all 
+        # local variables and none of the global variables! Thus we have to 
+        # generate the help text here and pass it to the function...
+        help (help_text % vars ())
     elif o == '-n' or o == '--name':
         name = a
     elif o == '-t' or o == '--title':
@@ -80,16 +86,23 @@ for opt in options:
     else:
         raise Exception ('unknown option: ' + o)
 
+texi_file_re = re.compile ('.*\.i?te(ly|xi)$')
+
 def name2line (n):
-    # UGR
-    s = r"""
+    if texi_file_re.match (n):
+        # We have a texi include file, simply include it:
+        s = r"@include %s" % os.path.basename (n)
+    else:
+        # Assume it's a lilypond file -> create image etc.
+        s = r"""
 @ifhtml
 @html
-<A NAME="%s"></A>
+<a name="%s"></a>
 @end html
 @end ifhtml
 
-@lilypondfile[%s]{%s}""" % (n, fragment_options, n)
+@lilypondfile[%s]{%s}
+""" % (os.path.basename (n), fragment_options, n)
     return s
 
 if files:
@@ -98,7 +111,6 @@ if files:
     name = os.path.basename (name)
     template = template % vars ()
 
-    files.sort ()
     s = "\n".join (map (name2line, files))
     s = template.replace (include_snippets, s, 1)
     f = "%s/%s" % (dir, name)