X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fbuild%2Flys-to-tely.py;h=cab59d91483783e43cfd6f24fca7d0baaa039135;hb=b7088489f91c805f2260d2efecc01f26519c5352;hp=0eb12047e697537e146e8fe065072e4815b1d195;hpb=3a9c1df02fdb6846418c5794a7b04d07209e95b3;p=lilypond.git diff --git a/scripts/build/lys-to-tely.py b/scripts/build/lys-to-tely.py index 0eb12047e6..cab59d9148 100644 --- a/scripts/build/lys-to-tely.py +++ b/scripts/build/lys-to-tely.py @@ -6,6 +6,7 @@ TODO: * Add @nodes, split at sections? + * -o --output listed in help is not implemented?! ''' @@ -13,6 +14,7 @@ import sys import os import getopt import re +import glob program_name = 'lys-to-tely' @@ -26,7 +28,10 @@ Options: -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment options -o, --output=NAME write tely doc to NAME + -i, --input-filenames=NAME read list of files from a file instead of stdin + -g, --glob-input=GLOB a string which will be passed to glob.glob(GLOB) -t, --title=TITLE set tely doc title TITLE + -a, --author=AUTHOR set tely author AUTHOR --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 @@ -38,15 +43,25 @@ def help (text): sys.exit (0) (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:', - ['fragment-options=', 'help', 'name=', 'title=', 'template=']) + ['fragment-options=', 'help', 'name=', + 'title=', 'author=', 'template=', + 'input-filenames=', 'glob-input=']) name = "ly-doc" title = "Ly Doc" +author = "Han-Wen Nienhuys and Jan Nieuwenhuizen" +input_filename = "" +glob_input = "" template = '''\input texinfo + +@c This file was autogenerated +@c from: %s +@c by: %s + @setfilename %%(name)s.info @settitle %%(title)s -@documentencoding utf-8 +@documentencoding UTF-8 @iftex @afourpaper @end iftex @@ -55,7 +70,7 @@ template = '''\input texinfo @c fool ls-latex @ignore -@author Han-Wen Nienhuys and Jan Nieuwenhuizen +@author %%(author)s @title %%(title)s @end ignore @@ -65,20 +80,26 @@ template = '''\input texinfo %s @bye -''' % include_snippets +''' % (", ".join(files), sys.argv[0], include_snippets) for opt in options: o = opt[0] a = opt[1] if o == '-h' or o == '--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 + # 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': title = a + elif o == '-a' or o == '--author': + author = a + elif o == '-i' or o == '--input-filenames': + input_filename = a + elif o == '-p' or o == '--glob-input': + glob_input = a elif o == '-f' or o == '--fragment-options': fragment_options = a elif o == '--template': @@ -86,12 +107,40 @@ for opt in options: else: raise Exception ('unknown option: ' + o) -texi_file_re = re.compile ('.*\.i?te(ly|xi)$') +html_file_re = re.compile ('.*\.i?html?$') +info_file_re = re.compile ('.*\.info$') +pdf_file_re = re.compile ('.*\.i?pdf$') +tex_file_re = re.compile ('.*\.i?(la)?tex$') +texi_file_re = re.compile ('.*\.i?te(ly|xi|xinfo)$') +xml_file_re = re.compile ('.*\.i?(xm|mx)l$') def name2line (n): if texi_file_re.match (n): # We have a texi include file, simply include it: s = r"@include %s" % os.path.basename (n) + elif (html_file_re.match (n) or info_file_re.match (n) + or pdf_file_re.match (n) or tex_file_re.match (n)): + s = r""" +@ifhtml +@html +%s +
+@end html +@end ifhtml +""" % (os.path.basename (n), os.path.basename (n)) + + elif (xml_file_re.match (n)): + # Assume it's a MusicXML file -> convert, create image etc. + s = r""" +@ifhtml +@html + +@end html +@end ifhtml + +@musicxmlfile[%s]{%s} +""" % (os.path.basename (n), fragment_options, n) + else: # Assume it's a lilypond file -> create image etc. s = r""" @@ -105,6 +154,11 @@ def name2line (n): """ % (os.path.basename (n), fragment_options, n) return s +if glob_input: + files = glob.glob(glob_input) +elif input_filename: + files = open(input_filename).read().split() + if files: dir = os.path.dirname (name) or "." # don't strip .tely extension, Documentation/snippets uses .itely @@ -114,12 +168,10 @@ if files: 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) h.close () - sys.stderr.write ('\n') 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") + sys.stderr.write ("No files specified. Doing nothing. Use -h to display usage.")