7 * Add @nodes, split at sections?
9 * -o --output listed in help is not implemented?!
19 program_name = 'lys-to-tely'
21 include_snippets = '@lysnippets'
22 fragment_options = 'printfilename,texidoc'
23 help_text = r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
24 Construct tely doc from LY-FILEs.
27 -h, --help print this help
28 -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
30 -o, --output=NAME write tely doc to NAME
31 -i, --input-filenames=NAME read list of files from a file instead of stdin
32 -g, --glob-input=GLOB a string which will be passed to glob.glob(GLOB)
33 -t, --title=TITLE set tely doc title TITLE
34 -a, --author=AUTHOR set tely author AUTHOR
35 --template=TEMPLATE use TEMPLATE as Texinfo template file,
36 instead of standard template; TEMPLATE should contain a command
37 '%(include_snippets)s' to tell where to insert LY-FILEs. When this
38 option is used, NAME and TITLE are ignored.
42 sys.stdout.write ( text)
45 (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
46 ['fragment-options=', 'help', 'name=',
47 'title=', 'author=', 'template=',
48 'input-filenames=', 'glob-input='])
52 author = "Han-Wen Nienhuys and Jan Nieuwenhuizen"
55 template = '''\input texinfo
56 @setfilename %%(name)s.info
59 @documentencoding utf-8
64 @finalout @c we do not want black boxes.
66 @c Trick to use with proper font mappings the same NCSB fonts as
67 @c LilyPond instead of those provided by TeX distribution
70 \\pdfmapfile{=lilypond.map}
86 ''' % include_snippets
91 if o == '-h' or o == '--help':
92 # We can't use vars () inside a function, as that only contains all
93 # local variables and none of the global variables! Thus we have to
94 # generate the help text here and pass it to the function...
95 help (help_text % vars ())
96 elif o == '-n' or o == '--name':
98 elif o == '-t' or o == '--title':
100 elif o == '-a' or o == '--author':
102 elif o == '-i' or o == '--input-filenames':
104 elif o == '-p' or o == '--glob-input':
106 elif o == '-f' or o == '--fragment-options':
108 elif o == '--template':
109 template = open (a, 'r').read ()
111 raise Exception ('unknown option: ' + o)
113 html_file_re = re.compile ('.*\.i?html?$')
114 info_file_re = re.compile ('.*\.info$')
115 pdf_file_re = re.compile ('.*\.i?pdf$')
116 tex_file_re = re.compile ('.*\.i?(la)?tex$')
117 texi_file_re = re.compile ('.*\.i?te(ly|xi|xinfo)$')
118 xml_file_re = re.compile ('.*\.i?(xm|mx)l$')
121 if texi_file_re.match (n):
122 # We have a texi include file, simply include it:
123 s = r"@include %s" % os.path.basename (n)
124 elif (html_file_re.match (n) or info_file_re.match (n)
125 or pdf_file_re.match (n) or tex_file_re.match (n)):
133 """ % (os.path.basename (n), os.path.basename (n))
135 elif (xml_file_re.match (n)):
136 # Assume it's a MusicXML file -> convert, create image etc.
144 @musicxmlfile[%s]{%s}
145 """ % (os.path.basename (n), fragment_options, n)
148 # Assume it's a lilypond file -> create image etc.
156 @lilypondfile[%s]{%s}
157 """ % (os.path.basename (n), fragment_options, n)
161 files = glob.glob(glob_input)
163 files = open(input_filename).read().split()
166 dir = os.path.dirname (name) or "."
167 # don't strip .tely extension, Documentation/snippets uses .itely
168 name = os.path.basename (name)
169 template = template % vars ()
171 s = "\n".join (map (name2line, files))
172 s = template.replace (include_snippets, s, 1)
173 f = "%s/%s" % (dir, name)
178 # not Unix philosophy, but hey, at least we notice when
179 # we don't distribute any .ly files.
180 sys.stderr.write ("No files specified. Doing nothing")