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
57 @c This file was autogenerated
61 @setfilename %%(name)s.info
64 @documentencoding utf-8
69 @finalout @c we do not want black boxes.
71 @c Trick to use with proper font mappings the same NCSB fonts as
72 @c LilyPond instead of those provided by TeX distribution
75 \\pdfmapfile{=lilypond.map}
91 ''' % (", ".join(files), sys.argv[0], include_snippets)
96 if o == '-h' or o == '--help':
97 # We can't use vars () inside a function, as that only contains all
98 # local variables and none of the global variables! Thus we have to
99 # generate the help text here and pass it to the function...
100 help (help_text % vars ())
101 elif o == '-n' or o == '--name':
103 elif o == '-t' or o == '--title':
105 elif o == '-a' or o == '--author':
107 elif o == '-i' or o == '--input-filenames':
109 elif o == '-p' or o == '--glob-input':
111 elif o == '-f' or o == '--fragment-options':
113 elif o == '--template':
114 template = open (a, 'r').read ()
116 raise Exception ('unknown option: ' + o)
118 html_file_re = re.compile ('.*\.i?html?$')
119 info_file_re = re.compile ('.*\.info$')
120 pdf_file_re = re.compile ('.*\.i?pdf$')
121 tex_file_re = re.compile ('.*\.i?(la)?tex$')
122 texi_file_re = re.compile ('.*\.i?te(ly|xi|xinfo)$')
123 xml_file_re = re.compile ('.*\.i?(xm|mx)l$')
126 if texi_file_re.match (n):
127 # We have a texi include file, simply include it:
128 s = r"@include %s" % os.path.basename (n)
129 elif (html_file_re.match (n) or info_file_re.match (n)
130 or pdf_file_re.match (n) or tex_file_re.match (n)):
138 """ % (os.path.basename (n), os.path.basename (n))
140 elif (xml_file_re.match (n)):
141 # Assume it's a MusicXML file -> convert, create image etc.
149 @musicxmlfile[%s]{%s}
150 """ % (os.path.basename (n), fragment_options, n)
153 # Assume it's a lilypond file -> create image etc.
161 @lilypondfile[%s]{%s}
162 """ % (os.path.basename (n), fragment_options, n)
166 files = glob.glob(glob_input)
168 files = open(input_filename).read().split()
171 dir = os.path.dirname (name) or "."
172 # don't strip .tely extension, Documentation/snippets uses .itely
173 name = os.path.basename (name)
174 template = template % vars ()
176 s = "\n".join (map (name2line, files))
177 s = template.replace (include_snippets, s, 1)
178 f = "%s/%s" % (dir, name)
183 # not Unix philosophy, but hey, at least we notice when
184 # we don't distribute any .ly files.
185 sys.stderr.write ("No files specified. Doing nothing. Use -h to display usage.")