]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/lys-to-tely.py
Change Snippets compilation
[lilypond.git] / buildscripts / lys-to-tely.py
index c0a66457a95b5d33bf8dfa46b0a36b61ad10c3cb..e2df5a6bc3fbb2f282d755bd54f17a7f1fa8d8d3 100644 (file)
@@ -4,71 +4,45 @@
 '''
 TODO:
 
- * Add @nodes, plit at sections?
- * Less kludged first introduction file
+ * Add @nodes, split at sections?
 
 '''
 
 
 import sys
 import os
-import string 
 import getopt
 
 program_name = 'lys-to-tely'
 
+include_snippets = '@lysnippets'
+fragment_options = 'printfilename,texidoc'
+
 def help ():
-    sys.stdout.write (r"""Usage: lys-to-tely [OPTIONS]... LY-FILE...
+    sys.stdout.write (r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
 Construct tely doc from LY-FILEs.
 
 Options:
- -h, --help                print this help
- -n, --name=NAME         write tely doc to NAME
- -t, --title=TITLE         set tely doc title TITLE
- -i, --introduction=FILE   use FILE as intruduction at the top
- -f, --footer=FILE         use FILE as footer on the bottom of the page
-
-""")
+ -h, --help                     print this help
+ -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
+   options
+ -o, --output=NAME              write tely doc to NAME
+ -t, --title=TITLE              set tely doc title TITLE
+     --template=TEMPLATE        use TEMPLATE as Texinfo template file,
+   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 ())
     sys.exit (0)
 
-(options, files) = getopt.getopt(sys.argv[1:], 'hn:t:i:f:', [
-    'help', 'name=', 'title=', 'introduction=', 'footer='])
+(options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
+                     ['fragment-options=', 'help', 'name=', 'title=', 'template='])
 
-name="ly-doc"
-title="Ly Doc"
-header = None
-footer = None
-for opt in options:
-    o = opt[0]
-    a = opt[1]
-    if o == '-h' or o == '--help':
-        help ()
-    elif o == '-n' or o == '--name':
-        name = a
-    elif o == '-t' or o == '--title':
-        title = a
-    elif o == '-i' or o == '--introduction':
-        header = a
-    elif o == '-f' or o == '--footer':
-        footer = a
-    else:
-        raise 'unknown opt ', o
-
-def strip_extension (f, ext):
-    (p, e) = os.path.splitext (f)
-    if e == ext:
-        e = ''
-    return p + e
-
-if files:
-    dir = os.path.dirname (name)
-    if not dir:
-        dir = "."
-    name = strip_extension (os.path.basename (name), ".tely")
-
-    s = '''\input texinfo
-@setfilename %s.info
-@settitle %s
+name = "ly-doc"
+title = "Ly Doc"
+template = '''\input texinfo
+@setfilename %%(name)s.info
+@settitle %%(name)s
 
 @documentencoding utf-8
 @iftex
@@ -76,42 +50,58 @@ if files:
 @end iftex
 
 @finalout @c we do not want black boxes.
+
 @c fool ls-latex
 @ignore
 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
-@title %s
+@title %%(title)s
 @end ignore
 
 @node Top, , , (dir)
-''' % (name, title, title)
 
-    if header:
-        header_text = open (header).read ()
-        s += header_text
+%s
 
+@bye
+''' % include_snippets
 
-    def name2line (n):
-        # UGR
-        s = r"""
+for opt in options:
+    o = opt[0]
+    a = opt[1]
+    if o == '-h' or o == '--help':
+        help ()
+    elif o == '-n' or o == '--name':
+        name = a
+    elif o == '-t' or o == '--title':
+        title = a
+    elif o == '-f' or o == '--fragment-options':
+        fragment_options = a
+    elif o == '--template':
+        template = open (a, 'r').read ()
+    else:
+        raise Exception ('unknown option: ' + o)
+
+def name2line (n):
+    s = r"""
 @ifhtml
 @html
-<A NAME="%s"></A>
+<a name="%s"></a>
 @end html
 @end ifhtml
-""" % n
-        
-        s += "\n\n@lilypondfile[printfilename,texidoc]{%s}" % n
-        return s
+
+@lilypondfile[%s]{%s}
+""" % (os.path.basename (n), fragment_options, n)
+    return s
+
+if files:
+    dir = os.path.dirname (name) or "."
+# don't strip .tely extension, input/lsr uses .itely
+    name = os.path.basename (name)
+    template = template % vars ()
+
     files.sort ()
-    s = s + string.join (map (lambda x: name2line (x), files), "\n")
-    s += '\n'
-    if footer:
-        footer_text = open (footer).read ()
-        s += footer_text
-        s += '\n'
-    s = s + '@bye\n'
-    f = "%s/%s.tely" % (dir, name)
+    s = "\n".join (map (name2line, files))
+    s = template.replace (include_snippets, s, 1)
+    f = "%s/%s" % (dir, name)
     sys.stderr.write ("%s: writing %s..." % (program_name, f))
     h = open (f, "w")
     h.write (s)
@@ -121,4 +111,3 @@ else:
     # not Unix philosophy, but hey, at least we notice when
     # we don't distribute any .ly files.
     sys.stderr.write ("No files specified. Doing nothing")
-