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.
83 ''' % (", ".join(files), sys.argv[0], include_snippets)
88 if o == '-h' or o == '--help':
89 # We can't use vars () inside a function, as that only contains all
90 # local variables and none of the global variables! Thus we have to
91 # generate the help text here and pass it to the function...
92 help (help_text % vars ())
93 elif o == '-n' or o == '--name':
95 elif o == '-t' or o == '--title':
97 elif o == '-a' or o == '--author':
99 elif o == '-i' or o == '--input-filenames':
101 elif o == '-p' or o == '--glob-input':
103 elif o == '-f' or o == '--fragment-options':
105 elif o == '--template':
106 template = open (a, 'r').read ()
108 raise Exception ('unknown option: ' + o)
110 html_file_re = re.compile ('.*\.i?html?$')
111 info_file_re = re.compile ('.*\.info$')
112 pdf_file_re = re.compile ('.*\.i?pdf$')
113 tex_file_re = re.compile ('.*\.i?(la)?tex$')
114 texi_file_re = re.compile ('.*\.i?te(ly|xi|xinfo)$')
115 xml_file_re = re.compile ('.*\.i?(xm|mx)l$')
118 if texi_file_re.match (n):
119 # We have a texi include file, simply include it:
120 s = r"@include %s" % os.path.basename (n)
121 elif (html_file_re.match (n) or info_file_re.match (n)
122 or pdf_file_re.match (n) or tex_file_re.match (n)):
130 """ % (os.path.basename (n), os.path.basename (n))
132 elif (xml_file_re.match (n)):
133 # Assume it's a MusicXML file -> convert, create image etc.
141 @musicxmlfile[%s]{%s}
142 """ % (os.path.basename (n), fragment_options, n)
145 # Assume it's a lilypond file -> create image etc.
153 @lilypondfile[%s]{%s}
154 """ % (os.path.basename (n), fragment_options, n)
158 files = glob.glob(glob_input)
160 files = open(input_filename).read().split()
163 dir = os.path.dirname (name) or "."
164 # don't strip .tely extension, Documentation/snippets uses .itely
165 name = os.path.basename (name)
166 template = template % vars ()
168 s = "\n".join (map (name2line, files))
169 s = template.replace (include_snippets, s, 1)
170 f = "%s/%s" % (dir, name)
175 # not Unix philosophy, but hey, at least we notice when
176 # we don't distribute any .ly files.
177 sys.stderr.write ("No files specified. Doing nothing. Use -h to display usage.")