7 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
10 lilypond-book --filter="convert-ly --no-version --from=1.6.11 -" BOOK
12 classic lilypond-book:
13 lilypond-book --process="lilypond-bin" BOOK.tely
16 * ly-options: intertext ?
18 * eps in latex / eps by lilypond-bin -fps ?
19 * check latex parameters, twocolumn, multicolumn?
21 * Converting from lilypond-book source, substitute:
22 @mbinclude foo.itely -> @include foo.itely
31 ################################################################
32 # Users of python modules should include this snippet
33 # and customize variables below.
35 # We'll suffer this path init stuff as long as we don't install our
36 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
37 # it as we do with teTeX on Red Hat Linux: set some environment var
38 # (PYTHONPATH) in profile)
40 # If set, LILYPONDPREFIX must take prevalence
41 # if datadir is not set, we're doing a build and LILYPONDPREFIX
42 import getopt, os, sys
43 datadir = '@local_lilypond_datadir@'
44 if not os.path.isdir (datadir):
45 datadir = '@lilypond_datadir@'
46 if os.environ.has_key ('LILYPONDPREFIX') :
47 datadir = os.environ['LILYPONDPREFIX']
48 while datadir[-1] == os.sep:
51 sys.path.insert (0, os.path.join (datadir, 'python'))
54 #if __name__ == '__main__':
62 program_version = '@TOPLEVEL_VERSION@'
63 program_name = 'lilypond-book'
66 original_dir = os.getcwd ()
69 help_summary = _ ("""Process LilyPond snippets in hybrid HTML, LaTeX or texinfo document.
72 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
73 lilypond-book --filter="convert-ly --no-version --from=2.0.0 -" BOOK
74 lilypond-book --process='lilypond-bin -I include' BOOK
78 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>',
79 'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
81 option_definitions = [
82 (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
83 (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
84 ('', 'h', 'help', _ ("print this help")),
85 (_ ("DIR"), 'I', 'include', _ ("add DIR to include path")),
86 (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
87 (_ ("DIR"), 'o', 'output', _ ("write output to DIR")),
88 ('', 'V', 'verbose', _ ("be verbose")),
89 ('', 'v', 'version', _ ("print version information")),
90 ('', 'w', 'warranty', _ ("show warranty and copyright")),
93 include_path = [ly.abspath (os.getcwd ())]
94 lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
96 # only use installed binary when we're installed too.
97 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
98 lilypond_binary = 'lilypond-bin'
104 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
106 process_cmd = lilypond_binary
107 default_ly_options = {}
112 EXAMPLEINDENT = 'exampleindent'
113 FRAGMENT = 'fragment'
117 LINEWIDTH = 'linewidth'
118 NOFRAGMENT = 'nofragment'
119 NOINDENT = 'noindent'
124 PREAMBLE = 'preamble'
125 PRINTFILENAME = 'printfilename'
126 RAGGEDRIGHT = 'raggedright'
127 RELATIVE = 'relative'
129 STAFFSIZE = 'staffsize'
132 VERBATIM = 'verbatim'
134 # Recognize special sequences in the input
136 # (?P<name>regex) -- assign result of REGEX to NAME
137 # *? -- match non-greedily.
138 # (?m) -- multiline regex: make ^ and $ match at each line
139 # (?s) -- make the dot match all characters including newline
144 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
145 'lilypond_block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
146 'lilypond_file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
147 'multiline_comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
148 'singleline_comment': no_match,
149 'verb': r'''(?P<code><pre>.*?</pre>)''',
150 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
154 'include': r'(?m)^[^%\n]*?(?P<match>\\input{(?P<filename>[^}]+)})',
155 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
156 'lilypond_block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
157 'lilypond_file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
158 'multiline_comment': no_match,
159 'singleline_comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
160 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
161 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
165 'include': '(?m)^[^%\n]*?(?P<match>@include\s+(?P<filename>\S+))',
166 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
167 'lilypond_block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
168 'lilypond_file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
169 'multiline_comment': r'(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end\s+ignore)\s',
170 'singleline_comment': r'(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))',
172 # don't do this: fucks up with @code{@{}
173 # 'verb': r'''(?P<code>@code{.*?})''',
174 'verbatim': r'''(?s)(?P<code>@example\s.*?@end\s+example\s)''',
180 'option-sep' : '\s*',
181 'intertext': r',?\s*intertext=\".*?\"',
184 'intertext': r',?\s*intertext=\".*?\"',
185 'option-sep' : ',\s*',
188 'intertext': r',?\s*intertext=\".*?\"',
189 'option-sep' : ',\s*',
195 RELATIVE: r'''\relative c%(relative_quotes)s''',
200 indent = %(indent)s''',
202 linewidth = %(linewidth)s''',
208 \remove Time_signature_engraver
211 linewidth = %(linewidth)s - 2.0 * %(exampleindent)s
215 raggedright = ##t''',
219 #(set-global-staff-size %(staffsize)s)''',
225 FILTER: r'''<lilypond %(options)s>
235 <a href="%(base)s.ly">''',
237 <img align="center" valign="center"
238 border="0" src="%(image)s" alt="[image of music]">''',
239 PRINTFILENAME:'<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
240 QUOTE: r'''<blockquote>
251 OUTPUT: r'''{\parindent 0pt
253 \ifx\preLilyPondExample\undefined\relax\else\preLilyPondExample\fi
256 \ifx\postLilyPondExample\undefined\relax\else\postLilyPondExample\fi
258 PRINTFILENAME: '''\\texttt{%(filename)s}
261 QUOTE: r'''\begin{quotation}
265 VERBATIM: r'''\noindent
267 %(verb)s\end{verbatim}
269 FILTER: r'''\begin{lilypond}[%(options)s]
275 FILTER: r'''@lilypond[%(options)s]
280 OUTPUT: r'''@noindent
281 @image{%(base)s,,,[image of music],%(ext)s}
283 PRINTFILENAME: '''@file{%(filename)s}
286 QUOTE: r'''@quotation
290 # FIXME: @exampleindent 5 is the default...
291 VERBATIM: r'''@exampleindent 0
299 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
300 %%%% Options: [%(option_string)s]
301 #(set! toplevel-score-handler ly:parser-print-score)
302 #(set! toplevel-music-handler (lambda (p m)
303 (ly:parser-print-score
304 p (ly:music-scorify m))
307 \paper {%(paper_string)s
317 texinfo_linewidths = {
318 '@afourpaper': '160 \\mm',
319 '@afourwide': '6.5 \\in',
320 '@afourlatex': '150 \\mm',
321 '@smallbook': '5 \\in' ,
322 '@letterpaper': '6\\in',
325 def classic_lilypond_book_compatibility (o):
326 if o == 'singleline':
328 m = re.search ('relative\s*([-0-9])', o)
330 return 'relative=%s' % m.group (1)
331 m = re.match ('([0-9]+)pt', o)
333 return 'staffsize=%s' % m.group (1)
334 m = re.match ('indent=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
336 f = float (m.group (1))
337 return 'indent=%f\\%s' % (f, m.group (2))
338 m = re.match ('linewidth=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
340 f = float (m.group (1))
341 return 'linewidth=%f\\%s' % (f, m.group (2))
344 def compose_ly (code, options):
346 for i in default_ly_options.keys ():
351 if QUOTE in options and LINEWIDTH in options:
352 options.remove (LINEWIDTH)
354 if FRAGMENT in options:
355 if RAGGEDRIGHT not in options:
356 options.append (RAGGEDRIGHT)
365 override.update (default_ly_options)
366 #FIXME: where to get sane value for exampleindent?
367 override[EXAMPLEINDENT] = r'9.0 \mm'
369 option_string = string.join (options, ',')
372 preamble_options = []
374 c = classic_lilypond_book_compatibility (i)
376 ly.warning (_ ("deprecated ly-option used: %s" % i))
377 ly.warning (_ ("compatibility mode translation: %s" \
381 if string.find (i, '=') > 0:
382 key, value = string.split (i, '=')
383 override[key] = value
386 if i not in override.keys ():
389 if key in ly_options[NOTES].keys ():
390 notes_options.append (ly_options[NOTES][key])
391 elif key in ly_options[PREAMBLE].keys ():
392 preamble_options.append (ly_options[PREAMBLE][key])
393 elif key in ly_options[PAPER].keys ():
394 paper_options.append (ly_options[PAPER][key])
395 elif key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
396 RELATIVE, VERBATIM, TEXIDOC):
397 ly.warning (_("ignoring unknown ly option: %s") % i)
400 if RELATIVE in override.keys () and override[RELATIVE]:
401 relative = string.atoi (override[RELATIVE])
407 relative_quotes += ',' * (- relative)
409 relative_quotes += "'" * relative
411 program_name = __main__.program_name
412 paper_string = string.join (paper_options, '\n ') % override
413 preamble_string = string.join (preamble_options, '\n ') % override
414 notes_string = string.join (notes_options, '\n ') % vars ()
415 return (PREAMBLE_LY + body) % vars ()
418 # use lilypond-bin for latex (.lytex) books,
419 # and lilypond --preview for html, texinfo books?
421 cmd = r'latex "\nonstopmode \input %s"' % file
422 # Ugh. (La)TeX writes progress and error messages on stdout
424 cmd = '(( %s >&2 ) >&- )' % cmd
426 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
430 # check if it really is EPS.
431 # Otherwise music glyphs disappear from 2nd and following pages.
433 # TODO: should run dvips -pp -E per page, then we get proper
436 f = open ('%s.eps' % file)
437 for x in range(0,10) :
438 if re.search ("^%%Pages: ", f.readline ()):
441 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
446 def find_file (name):
447 for i in include_path:
448 full = os.path.join (i, name)
449 if os.path.exists (full):
451 ly.error (_ ('file not found: %s') % name + '\n')
455 def verbatim_html (s):
456 return re.sub ('>', '>',
458 re.sub ('&', '&', s)))
460 def verbatim_texinfo (s):
461 return re.sub ('{', '@{',
463 re.sub ('@', '@@', s)))
465 def split_options (option_string):
466 return re.split (format_res[format]['option-sep'], option_string)
470 def replacement_text (self):
473 def filter_text (self):
474 return self.replacement_text ()
477 def is_outdated (self):
480 class Substring (Chunk):
481 def __init__ (self, source, start, end):
486 def replacement_text (self):
487 return self.source [self.start:self.end]
489 class Snippet (Chunk):
490 def __init__ (self, type, match, format):
497 def replacement_text (self):
498 return self.match.group (0)
500 def substring (self, s):
501 return self.match.group (s)
504 return `self.__class__` + " type = " + self.type
506 class Include_snippet (Snippet):
507 def processed_filename (self):
508 f = self.substring ('filename')
509 return os.path.splitext (f)[0] + format2ext[format]
511 def replacement_text (self):
512 s = self.match.group (0)
513 f = self.substring ('filename')
515 return re.sub (f, self.processed_filename (), s)
517 class Lilypond_snippet (Snippet):
518 def __init__ (self, type, match, format):
519 Snippet.__init__ (self, type, match, format)
520 os = match.group ('options')
522 self.options = split_options (os)
525 return self.substring ('code')
530 return compose_ly (s, self.options)
535 self.hash = abs (hash (self.full_ly ()))
540 return 'lily-%d' % self.get_hash ()
544 outf = open (self.basename () + '.ly', 'w')
545 outf.write (self.full_ly ())
547 def is_outdated (self):
548 base = self.basename ()
550 tex_file = '%s.tex' % base
551 ly_file = '%s.ly' % base
552 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
553 and os.stat (tex_file)[stat.ST_SIZE] \
554 and open (tex_file).readlines ()[-1][1:-1] \
557 if format == HTML or format == TEXINFO:
558 ok = ok and (os.path.exists (base + '.png')
559 or glob.glob (base + '-page*.png'))
561 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
562 # TODO: something smart with target formats
563 # (ps, png) and m/ctimes
567 def filter_text (self):
568 code = self.substring ('code')
569 s = run_filter (code)
571 'options': self.match.group ('options')
574 return output[self.format][FILTER] % d
576 def replacement_text (self):
577 func = Lilypond_snippet.__dict__ ['output_' + self.format]
580 def get_images (self):
581 base = self.basename ()
583 single = '%(base)s.png' % vars ()
584 multiple = '%(base)s-page1.png' % vars ()
586 if os.path.exists (multiple) \
587 and (not os.path.exists (single)\
588 or (os.stat (multiple)[stat.ST_MTIME] \
589 > os.stat (single)[stat.ST_MTIME])):
590 images = glob.glob ('%(base)s-page*.png' % vars ())
593 def output_html (self):
595 base = self.basename ()
597 str += self.output_print_filename (HTML)
598 if VERBATIM in self.options:
599 verb = verbatim_html (self.substring ('code'))
600 str += write (output[HTML][VERBATIM] % vars ())
601 if QUOTE in self.options:
602 str = output[HTML][QUOTE] % vars ()
604 str += output[HTML][BEFORE] % vars ()
605 for image in self.get_images ():
606 base, ext = os.path.splitext (image)
607 str += output[HTML][OUTPUT] % vars ()
608 str += output[HTML][AFTER] % vars ()
611 def output_info (self):
612 str = self.output_print_filename (HTML)
613 str = output[TEXINFO][BEFORE] % vars ()
614 for image in self.get_images ():
615 base, ext = os.path.splitext (image)
616 # URG, makeinfo implicitely prepends dot to ext
617 # specifying no extension is most robust
619 str += output[TEXINFO][OUTPUT] % vars ()
620 str += output[TEXINFO][AFTER] % vars ()
623 def output_latex (self):
625 base = self.basename ()
627 str += self.output_print_filename (LATEX)
628 if VERBATIM in self.options:
629 verb = self.substring ('code')
630 str += (output[LATEX][VERBATIM] % vars ())
631 if QUOTE in self.options:
632 str = output[LATEX][QUOTE] % vars ()
634 str += (output[LATEX][BEFORE]
635 + (output[LATEX][OUTPUT] % vars ())
636 + output[LATEX][AFTER])
639 def output_print_filename (self,format):
641 if PRINTFILENAME in self.options:
642 base = self.basename ()
643 filename = self.substring ('filename')
644 str = output[format][PRINTFILENAME] % vars ()
647 def output_texinfo (self):
649 # self.output_print_filename (TEXINFO)
650 str += ('@html\n' + self.output_print_filename (HTML)
652 str += ('@tex\n' + self.output_print_filename (LATEX)
654 base = self.basename ()
655 if TEXIDOC in self.options:
656 texidoc = base + '.texidoc'
657 if os.path.exists (texidoc):
658 str += '@include %(texidoc)s\n\n' % vars ()
660 if VERBATIM in self.options:
661 verb = verbatim_texinfo (self.substring ('code'))
662 str += (output[TEXINFO][VERBATIM] % vars ())
664 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
665 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
666 str += ('@html\n' + self.output_html () + '\n@end html\n')
668 if QUOTE in self.options:
669 str = output[TEXINFO][QUOTE] % vars ()
671 # need par after image
676 class Lilypond_file_snippet (Lilypond_snippet):
678 name = self.substring ('filename')
679 return '\\renameinput \"%s\"\n' % name\
680 + open (find_file (name)).read ()
683 snippet_type_to_class = {
684 'lilypond_file' : Lilypond_file_snippet,
685 'lilypond_block' : Lilypond_snippet,
686 'lilypond' : Lilypond_snippet,
687 'include' : Include_snippet,
690 def find_toplevel_snippets (s, types):
693 res[i] = ly.re.compile (snippet_res[format][i])
697 ## found = dict (map (lambda x: (x, None), types))
700 map (lambda x, f=found: f.setdefault (x, None), types)
702 # We want to search for multiple regexes, without searching
703 # the string multiple times for one regex.
704 # Hence, we use earlier results to limit the string portion
706 # Since every part of the string is traversed at most once for
707 # every type of snippet, this is linear.
713 if not found[type] or found[type][0] < index:
715 m = res[type].search (s[index:endex])
720 if snippet_type_to_class.has_key (type):
721 cl = snippet_type_to_class[type]
722 snip = cl (type, m, format)
723 start = index + m.start (0)
724 found[type] = (start, snip)
727 and (not first or found[type][0] < found[first][0]):
732 # Limiting the search space is a cute
733 # idea, but this *requires* to search
734 # for possible containing blocks
735 # first, at least long as we do not
736 # search for the start of blocks, but
737 # always/directly for the entire
738 # @block ... @end block.
740 endex = found[first][0]
743 snippets.append (Substring (s, index, len (s)))
746 (start , snip) = found[first]
747 snippets.append (Substring (s, index, start))
748 snippets.append (snip)
750 index = start + len (snip.match.group (0))
754 def filter_pipe (input, cmd):
756 ly.progress (_ ("Opening filter `%s\'") % cmd)
758 stdin, stdout, stderr = os.popen3 (cmd)
760 status = stdin.close ()
764 output = stdout.read ()
765 status = stdout.close ()
766 error = stderr.read ()
770 signal = 0x0f & status
771 if status or (not output and error):
772 exit_status = status >> 8
773 ly.error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
774 ly.error (_ ("The error log is as follows:"))
775 sys.stderr.write (error)
776 sys.stderr.write (stderr.read ())
785 return filter_pipe (s, filter_cmd)
787 def is_derived_class (cl, baseclass):
790 for b in cl.__bases__:
791 if is_derived_class (b, baseclass):
796 def process_snippets (cmd, snippets):
797 names = filter (lambda x: x, map (Lilypond_snippet.basename, snippets))
799 ly.system (string.join ([cmd] + names))
801 if format == HTML or format == TEXINFO:
803 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
805 ly.make_ps_images (i + '.eps', resolution=110)
806 # elif os.path.exists (i + '.ps'):
807 # ly.make_ps_images (i + '.ps', resolution=110)
810 LATEX_DOCUMENT = r'''
813 \typeout{textwidth=\the\textwidth}
814 \typeout{columnsep=\the\columnsep}
815 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
818 #need anything else besides textwidth?
819 def get_latex_textwidth (source):
820 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
821 preamble = source[:m.start (0)]
822 latex_document = LATEX_DOCUMENT % vars ()
823 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
826 m = re.search ('columns=([0-9.]*)', parameter_string)
828 columns = string.atoi (m.group (1))
831 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
833 columnsep = string.atof (m.group (1))
836 m = re.search('textwidth=([0-9.]*)pt', parameter_string)
838 textwidth = string.atof (m.group (1))
840 textwidth = (textwidth - columnsep) / columns
851 '.texinfo' : TEXINFO,
857 #TEXINFO: '.texinfo',
862 def do_file (input_filename):
866 e = os.path.splitext (input_filename)[1]
867 if e in ext2format.keys ():
869 format = ext2format[e]
871 ly.error (_ ("cannot determine format for: %s" \
874 if not input_filename or input_filename == '-':
875 in_handle = sys.stdin
876 input_fullname = '<stdin>'
878 if os.path.exists (input_filename):
879 input_fullname = input_filename
880 elif format == LATEX:
881 # urg python interface to libkpathsea?
882 input_fullname = ly.read_pipe ('kpsewhich '
883 + input_filename)[:-1]
885 input_fullname = find_file (input_filename)
886 in_handle = open (input_fullname)
888 if input_filename == '-':
891 input_base = os.path.basename \
892 (os.path.splitext (input_filename)[0])
894 # only default to stdout when filtering
895 if output_name == '-' or (not output_name and filter_cmd):
896 output_filename = '-'
897 output_file = sys.stdout
900 output_filename = input_base + format2ext[format]
902 if not os.path.isdir (output_name):
903 os.mkdir (output_name, 0777)
904 output_filename = (output_name
906 + format2ext[format])
909 if (os.path.exists (input_filename) and
910 os.path.exists (output_filename) and
911 os.path.samefile (output_filename, input_fullname)):
912 ly.error (_("Output would overwrite input file; use --output."))
915 output_file = open (output_filename, 'w')
917 os.chdir (output_name)
919 ly.progress (_ ("Reading %s...") % input_fullname)
920 source = in_handle.read ()
923 # FIXME: containing blocks must be first, see find_toplevel_snippets
929 'singleline_comment',
933 ly.progress (_ ("Dissecting..."))
934 chunks = find_toplevel_snippets (source, snippet_types)
937 global default_ly_options
939 if LINEWIDTH not in default_ly_options.keys ():
941 textwidth = get_latex_textwidth (source)
942 default_ly_options[LINEWIDTH] = '''%.0f\\pt''' \
944 elif format == TEXINFO:
945 for (k, v) in texinfo_linewidths.items ():
946 # FIXME: @paper is usually not in chunk #0:
947 # \input texinfo @c -*-texinfo-*-
948 # bluntly search first K of source
949 # s = chunks[0].replacement_text ()
950 if re.search (k, source[:1024]):
951 default_ly_options[LINEWIDTH] = v
955 output_file.writelines ([c.filter_text () for c in chunks])
959 outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
960 and x.is_outdated (), chunks)
961 ly.progress (_ ("Writing snippets..."))
962 map (Lilypond_snippet.write_ly, outdated)
966 ly.progress (_ ("Processing..."))
967 process_snippets (process_cmd, outdated)
969 ly.progress (_ ("All snippets are up to date..."))
972 ly.progress (_ ("Compiling %s...") % output_filename)
973 output_file.writelines ([s.replacement_text () \
977 def process_include (snippet):
978 os.chdir (original_dir)
979 name = snippet.substring ('filename')
980 ly.progress (_ ('Processing include: %s') % name)
984 map (process_include,
985 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
988 global format, output_name
989 global filter_cmd, process_cmd, verbose_p
991 (sh, long) = ly.getopt_args (option_definitions)
993 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
994 except getopt.error, s:
995 sys.stderr.write ('\n')
996 ly.error (_ ("getopt says: `%s\'" % s))
997 sys.stderr.write ('\n')
1007 elif o == '--filter' or o == '-F':
1010 elif o == '--format' or o == '-f':
1012 if a == 'texi-html' or a == 'texi':
1014 elif o == '--help' or o == '-h':
1017 elif o == '--include' or o == '-I':
1018 include_path.append (os.path.join (original_dir,
1020 elif o == '--output' or o == '-o':
1022 elif o == '--outdir':
1024 elif o == '--process' or o == '-P':
1027 elif o == '--version' or o == '-v':
1028 ly.identify (sys.stdout)
1030 elif o == '--verbose' or o == '-V':
1032 elif o == '--warranty' or o == '-w':
1039 files = do_options ()
1042 process_cmd += string.join ([(' -I %s' % p)
1043 for p in include_path])
1045 ly.identify (sys.stderr)
1046 ly.setup_environment ()
1050 if __name__ == '__main__':