7 * Add @nodes, split at sections?
9 * -o --output listed in help is not implemented?!
18 program_name = 'lys-to-tely'
20 include_snippets = '@lysnippets'
21 fragment_options = 'printfilename,texidoc'
22 help_text = r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
23 Construct tely doc from LY-FILEs.
26 -h, --help print this help
27 -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
29 -o, --output=NAME write tely doc to NAME
30 -i, --input-filenames=NAME read list of files from a file instead of stdin
31 -t, --title=TITLE set tely doc title TITLE
32 -a, --author=AUTHOR set tely author AUTHOR
33 --template=TEMPLATE use TEMPLATE as Texinfo template file,
34 instead of standard template; TEMPLATE should contain a command
35 '%(include_snippets)s' to tell where to insert LY-FILEs. When this
36 option is used, NAME and TITLE are ignored.
40 sys.stdout.write ( text)
43 (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
44 ['fragment-options=', 'help', 'name=',
45 'title=', 'author=', 'template=',
50 author = "Han-Wen Nienhuys and Jan Nieuwenhuizen"
52 template = '''\input texinfo
53 @setfilename %%(name)s.info
56 @documentencoding utf-8
61 @finalout @c we do not want black boxes.
75 ''' % include_snippets
80 if o == '-h' or o == '--help':
81 # We can't use vars () inside a function, as that only contains all
82 # local variables and none of the global variables! Thus we have to
83 # generate the help text here and pass it to the function...
84 help (help_text % vars ())
85 elif o == '-n' or o == '--name':
87 elif o == '-t' or o == '--title':
89 elif o == '-a' or o == '--author':
91 elif o == '-i' or o == '--input-filenames':
93 elif o == '-f' or o == '--fragment-options':
95 elif o == '--template':
96 template = open (a, 'r').read ()
98 raise Exception ('unknown option: ' + o)
100 texi_file_re = re.compile ('.*\.i?te(ly|xi)$')
101 html_file_re = re.compile ('.*\.i?htm(l)?$')
102 xml_file_re = re.compile ('.*\.i?(xm|mx)l$')
103 tex_file_re = re.compile ('.*\.i?(la)?tex$')
104 pdf_file_re = re.compile ('.*\.i?pdf$')
107 if texi_file_re.match (n):
108 # We have a texi include file, simply include it:
109 s = r"@include %s" % os.path.basename (n)
110 elif (html_file_re.match (n) or pdf_file_re.match (n) or
111 tex_file_re.match (n)):
119 """ % (os.path.basename (n), os.path.basename (n))
121 elif (xml_file_re.match (n)):
122 # Assume it's a MusicXML file -> convert, create image etc.
130 @musicxmlfile[%s]{%s}
131 """ % (os.path.basename (n), fragment_options, n)
134 # Assume it's a lilypond file -> create image etc.
142 @lilypondfile[%s]{%s}
143 """ % (os.path.basename (n), fragment_options, n)
147 files = open(input_filename).read().splitlines()
150 dir = os.path.dirname (name) or "."
151 # don't strip .tely extension, Documentation/snippets uses .itely
152 name = os.path.basename (name)
153 template = template % vars ()
155 s = "\n".join (map (name2line, files))
156 s = template.replace (include_snippets, s, 1)
157 f = "%s/%s" % (dir, name)
158 sys.stderr.write ("%s: writing %s..." % (program_name, f))
162 sys.stderr.write ('\n')
164 # not Unix philosophy, but hey, at least we notice when
165 # we don't distribute any .ly files.
166 sys.stderr.write ("No files specified. Doing nothing")