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
32 ################################################################
33 # Users of python modules should include this snippet
34 # and customize variables below.
36 # We'll suffer this path init stuff as long as we don't install our
37 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
38 # it as we do with teTeX on Red Hat Linux: set some environment var
39 # (PYTHONPATH) in profile)
41 # If set, LILYPONDPREFIX must take prevalence
42 # if datadir is not set, we're doing a build and LILYPONDPREFIX
43 import getopt, os, sys
44 datadir = '@local_lilypond_datadir@'
45 if not os.path.isdir (datadir):
46 datadir = '@lilypond_datadir@'
47 if os.environ.has_key ('LILYPONDPREFIX') :
48 datadir = os.environ['LILYPONDPREFIX']
49 while datadir[-1] == os.sep:
52 sys.path.insert (0, os.path.join (datadir, 'python'))
55 #if __name__ == '__main__':
63 program_version = '@TOPLEVEL_VERSION@'
64 program_name = 'lilypond-book'
67 original_dir = os.getcwd ()
70 help_summary = _ ("""Process LilyPond snippets in hybrid HTML, LaTeX or texinfo document.
73 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
74 lilypond-book --filter="convert-ly --no-version --from=2.0.0 -" BOOK
75 lilypond-book --process='lilypond-bin -I include' BOOK
79 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>',
80 'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
82 option_definitions = [
83 (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
84 (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
85 ('', 'h', 'help', _ ("print this help")),
86 (_ ("DIR"), 'I', 'include', _ ("add DIR to include path")),
87 (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
88 (_ ("DIR"), 'o', 'output', _ ("write output to DIR")),
89 ('', 'V', 'verbose', _ ("be verbose")),
90 ('', 'v', 'version', _ ("print version information")),
91 ('', 'w', 'warranty', _ ("show warranty and copyright")),
94 include_path = [ly.abspath (os.getcwd ())]
95 lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
97 # only use installed binary when we're installed too.
98 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
99 lilypond_binary = 'lilypond-bin'
105 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
107 process_cmd = lilypond_binary
108 default_ly_options = {}
113 EXAMPLEINDENT = 'exampleindent'
114 FRAGMENT = 'fragment'
118 LINEWIDTH = 'linewidth'
119 NOFRAGMENT = 'nofragment'
120 NOINDENT = 'noindent'
125 PREAMBLE = 'preamble'
126 PRINTFILENAME = 'printfilename'
127 RAGGEDRIGHT = 'raggedright'
128 RELATIVE = 'relative'
130 STAFFSIZE = 'staffsize'
133 VERBATIM = 'verbatim'
135 # Recognize special sequences in the input
137 # (?P<name>regex) -- assign result of REGEX to NAME
138 # *? -- match non-greedily.
139 # (?m) -- multiline regex: make ^ and $ match at each line
140 # (?s) -- make the dot match all characters including newline
145 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
146 'lilypond_block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
147 'lilypond_file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
148 'multiline_comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
149 'singleline_comment': no_match,
150 'verb': r'''(?P<code><pre>.*?</pre>)''',
151 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
155 'include': r'(?m)^[^%\n]*?(?P<match>\\input{(?P<filename>[^}]+)})',
156 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
157 'lilypond_block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
158 'lilypond_file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
159 'multiline_comment': no_match,
160 'singleline_comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
161 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
162 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
166 'include': '(?m)^[^%\n]*?(?P<match>@include\s+(?P<filename>\S+))',
167 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
168 'lilypond_block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
169 'lilypond_file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
170 'multiline_comment': r'(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end\s+ignore)\s',
171 'singleline_comment': r'(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))',
173 # don't do this: fucks up with @code{@{}
174 # 'verb': r'''(?P<code>@code{.*?})''',
175 'verbatim': r'''(?s)(?P<code>@example\s.*?@end\s+example\s)''',
181 'option-sep' : '\s*',
182 'intertext': r',?\s*intertext=\".*?\"',
185 'intertext': r',?\s*intertext=\".*?\"',
186 'option-sep' : ',\s*',
189 'intertext': r',?\s*intertext=\".*?\"',
190 'option-sep' : ',\s*',
196 RELATIVE: r'''\relative c%(relative_quotes)s''',
201 indent = %(indent)s''',
203 linewidth = %(linewidth)s''',
209 \remove Time_signature_engraver
212 linewidth = %(linewidth)s - 2.0 * %(exampleindent)s
216 raggedright = ##t''',
220 #(set-global-staff-size %(staffsize)s)''',
226 FILTER: r'''<lilypond %(options)s>
236 <a href="%(base)s.ly">''',
238 <img align="center" valign="center"
239 border="0" src="%(image)s" alt="[image of music]">''',
240 PRINTFILENAME:'<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
241 QUOTE: r'''<blockquote>
252 OUTPUT: r'''{\parindent 0pt
254 \ifx\preLilyPondExample\undefined\relax\else\preLilyPondExample\fi
257 \ifx\postLilyPondExample\undefined\relax\else\postLilyPondExample\fi
259 PRINTFILENAME: '''\\texttt{%(filename)s}
262 QUOTE: r'''\begin{quotation}
266 VERBATIM: r'''\noindent
268 %(verb)s\end{verbatim}
270 FILTER: r'''\begin{lilypond}[%(options)s]
276 FILTER: r'''@lilypond[%(options)s]
281 OUTPUT: r'''@noindent
282 @image{%(base)s,,,[image of music],%(ext)s}
284 PRINTFILENAME: '''@file{%(filename)s}
287 QUOTE: r'''@quotation
291 # FIXME: @exampleindent 5 is the default...
292 VERBATIM: r'''@exampleindent 0
300 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
301 %%%% Options: [%(option_string)s]
302 #(set! toplevel-score-handler ly:parser-print-score)
303 #(set! toplevel-music-handler (lambda (p m)
304 (ly:parser-print-score
305 p (ly:music-scorify m))
308 \paper {%(paper_string)s
318 texinfo_linewidths = {
319 '@afourpaper': '160 \\mm',
320 '@afourwide': '6.5 \\in',
321 '@afourlatex': '150 \\mm',
322 '@smallbook': '5 \\in' ,
323 '@letterpaper': '6\\in',
326 def classic_lilypond_book_compatibility (o):
327 if o == 'singleline':
329 m = re.search ('relative\s*([-0-9])', o)
331 return 'relative=%s' % m.group (1)
332 m = re.match ('([0-9]+)pt', o)
334 return 'staffsize=%s' % m.group (1)
335 m = re.match ('indent=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
337 f = float (m.group (1))
338 return 'indent=%f\\%s' % (f, m.group (2))
339 m = re.match ('linewidth=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
341 f = float (m.group (1))
342 return 'linewidth=%f\\%s' % (f, m.group (2))
345 def compose_ly (code, options):
347 for i in default_ly_options.keys ():
352 if QUOTE in options and LINEWIDTH in options:
353 options.remove (LINEWIDTH)
355 m = re.search (r'''\\(header|score)''', code)
356 if not m and (not options \
357 or not NOFRAGMENT in options or FRAGMENT in options):
358 if RAGGEDRIGHT not in options:
359 options.append (RAGGEDRIGHT)
368 override.update (default_ly_options)
369 #FIXME: where to get sane value for exampleindent?
370 override[EXAMPLEINDENT] = r'9.0 \mm'
372 option_string = string.join (options, ',')
375 preamble_options = []
377 c = classic_lilypond_book_compatibility (i)
379 ly.warning (_ ("deprecated ly-option used: %s" % i))
380 ly.warning (_ ("compatibility mode translation: %s" \
384 if string.find (i, '=') > 0:
385 key, value = string.split (i, '=')
386 override[key] = value
389 if i not in override.keys ():
392 if key in ly_options[NOTES].keys ():
393 notes_options.append (ly_options[NOTES][key])
394 elif key in ly_options[PREAMBLE].keys ():
395 preamble_options.append (ly_options[PREAMBLE][key])
396 elif key in ly_options[PAPER].keys ():
397 paper_options.append (ly_options[PAPER][key])
398 elif key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
399 RELATIVE, VERBATIM, TEXIDOC):
400 ly.warning (_("ignoring unknown ly option: %s") % i)
403 if RELATIVE in override.keys () and override[RELATIVE]:
404 relative = string.atoi (override[RELATIVE])
410 relative_quotes += ',' * (- relative)
412 relative_quotes += "'" * relative
414 program_name = __main__.program_name
415 paper_string = string.join (paper_options, '\n ') % override
416 preamble_string = string.join (preamble_options, '\n ') % override
417 notes_string = string.join (notes_options, '\n ') % vars ()
418 return (PREAMBLE_LY + body) % vars ()
421 # use lilypond-bin for latex (.lytex) books,
422 # and lilypond --preview for html, texinfo books?
424 cmd = r'latex "\nonstopmode \input %s"' % file
425 # Ugh. (La)TeX writes progress and error messages on stdout
427 cmd = '(( %s >&2 ) >&- )' % cmd
429 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
433 # check if it really is EPS.
434 # Otherwise music glyphs disappear from 2nd and following pages.
436 # TODO: should run dvips -pp -E per page, then we get proper
439 f = open ('%s.eps' % file)
440 for x in range(0,10) :
441 if re.search ("^%%Pages: ", f.readline ()):
444 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
449 def find_file (name):
450 for i in include_path:
451 full = os.path.join (i, name)
452 if os.path.exists (full):
454 ly.error (_ ('file not found: %s') % name + '\n')
458 def verbatim_html (s):
459 return re.sub ('>', '>',
461 re.sub ('&', '&', s)))
463 def verbatim_texinfo (s):
464 return re.sub ('{', '@{',
466 re.sub ('@', '@@', s)))
468 def split_options (option_string):
469 return re.split (format_res[format]['option-sep'], option_string)
473 def replacement_text (self):
476 def filter_text (self):
477 return self.replacement_text ()
480 def is_outdated (self):
483 class Substring (Chunk):
484 def __init__ (self, source, start, end):
489 def replacement_text (self):
490 return self.source [self.start:self.end]
492 class Snippet (Chunk):
493 def __init__ (self, type, match, format):
500 def replacement_text (self):
501 return self.match.group (0)
503 def substring (self, s):
504 return self.match.group (s)
507 return `self.__class__` + " type = " + self.type
509 class Include_snippet (Snippet):
510 def processed_filename (self):
511 f = self.substring ('filename')
512 return os.path.splitext (f)[0] + format2ext[format]
514 def replacement_text (self):
515 s = self.match.group (0)
516 f = self.substring ('filename')
518 return re.sub (f, self.processed_filename (), s)
520 class Lilypond_snippet (Snippet):
521 def __init__ (self, type, match, format):
522 Snippet.__init__ (self, type, match, format)
523 os = match.group ('options')
525 self.options = split_options (os)
528 return self.substring ('code')
533 return compose_ly (s, self.options)
538 self.hash = abs (hash (self.full_ly ()))
543 return 'lily-%d' % self.get_hash ()
547 outf = open (self.basename () + '.ly', 'w')
548 outf.write (self.full_ly ())
550 def is_outdated (self):
551 base = self.basename ()
553 tex_file = '%s.tex' % base
554 ly_file = '%s.ly' % base
555 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
556 and os.stat (tex_file)[stat.ST_SIZE] \
557 and open (tex_file).readlines ()[-1][1:-1] \
560 if format == HTML or format == TEXINFO:
561 ok = ok and (os.path.exists (base + '.png')
562 or glob.glob (base + '-page*.png'))
564 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
565 # TODO: something smart with target formats
566 # (ps, png) and m/ctimes
570 def filter_text (self):
571 code = self.substring ('code')
572 s = run_filter (code)
574 'options': self.match.group ('options')
577 return output[self.format][FILTER] % d
579 def replacement_text (self):
580 func = Lilypond_snippet.__dict__ ['output_' + self.format]
583 def get_images (self):
584 base = self.basename ()
586 single = '%(base)s.png' % vars ()
587 multiple = '%(base)s-page1.png' % vars ()
589 if os.path.exists (multiple) \
590 and (not os.path.exists (single)\
591 or (os.stat (multiple)[stat.ST_MTIME] \
592 > os.stat (single)[stat.ST_MTIME])):
593 images = glob.glob ('%(base)s-page*.png' % vars ())
596 def output_html (self):
598 base = self.basename ()
600 str += self.output_print_filename (HTML)
601 if VERBATIM in self.options:
602 verb = verbatim_html (self.substring ('code'))
603 str += write (output[HTML][VERBATIM] % vars ())
604 if QUOTE in self.options:
605 str = output[HTML][QUOTE] % vars ()
607 str += output[HTML][BEFORE] % vars ()
608 for image in self.get_images ():
609 base, ext = os.path.splitext (image)
610 str += output[HTML][OUTPUT] % vars ()
611 str += output[HTML][AFTER] % vars ()
614 def output_info (self):
615 str = self.output_print_filename (HTML)
616 str = output[TEXINFO][BEFORE] % vars ()
617 for image in self.get_images ():
618 base, ext = os.path.splitext (image)
619 # URG, makeinfo implicitely prepends dot to ext
620 # specifying no extension is most robust
622 str += output[TEXINFO][OUTPUT] % vars ()
623 str += output[TEXINFO][AFTER] % vars ()
626 def output_latex (self):
628 base = self.basename ()
630 str += self.output_print_filename (LATEX)
631 if VERBATIM in self.options:
632 verb = self.substring ('code')
633 str += (output[LATEX][VERBATIM] % vars ())
634 if QUOTE in self.options:
635 str = output[LATEX][QUOTE] % vars ()
637 str += (output[LATEX][BEFORE]
638 + (output[LATEX][OUTPUT] % vars ())
639 + output[LATEX][AFTER])
642 def output_print_filename (self,format):
644 if PRINTFILENAME in self.options:
645 base = self.basename ()
646 filename = self.substring ('filename')
647 str = output[format][PRINTFILENAME] % vars ()
650 def output_texinfo (self):
652 # self.output_print_filename (TEXINFO)
653 str += ('@html\n' + self.output_print_filename (HTML)
655 str += ('@tex\n' + self.output_print_filename (LATEX)
657 base = self.basename ()
658 if TEXIDOC in self.options:
659 texidoc = base + '.texidoc'
660 if os.path.exists (texidoc):
661 str += '@include %(texidoc)s\n\n' % vars ()
663 if VERBATIM in self.options:
664 verb = verbatim_texinfo (self.substring ('code'))
665 str += (output[TEXINFO][VERBATIM] % vars ())
667 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
668 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
669 str += ('@html\n' + self.output_html () + '\n@end html\n')
671 if QUOTE in self.options:
672 str = output[TEXINFO][QUOTE] % vars ()
674 # need par after image
679 class Lilypond_file_snippet (Lilypond_snippet):
681 name = self.substring ('filename')
682 return '\\renameinput \"%s\"\n' % name\
683 + open (find_file (name)).read ()
686 snippet_type_to_class = {
687 'lilypond_file' : Lilypond_file_snippet,
688 'lilypond_block' : Lilypond_snippet,
689 'lilypond' : Lilypond_snippet,
690 'include' : Include_snippet,
693 def find_toplevel_snippets (s, types):
696 res[i] = ly.re.compile (snippet_res[format][i])
700 ## found = dict (map (lambda x: (x, None), types))
703 map (lambda x, f=found: f.setdefault (x, None), types)
705 # We want to search for multiple regexes, without searching
706 # the string multiple times for one regex.
707 # Hence, we use earlier results to limit the string portion
709 # Since every part of the string is traversed at most once for
710 # every type of snippet, this is linear.
716 if not found[type] or found[type][0] < index:
718 m = res[type].search (s[index:endex])
723 if snippet_type_to_class.has_key (type):
724 cl = snippet_type_to_class[type]
725 snip = cl (type, m, format)
726 start = index + m.start (0)
727 found[type] = (start, snip)
730 and (not first or found[type][0] < found[first][0]):
735 # Limiting the search space is a cute
736 # idea, but this *requires* to search
737 # for possible containing blocks
738 # first, at least long as we do not
739 # search for the start of blocks, but
740 # always/directly for the entire
741 # @block ... @end block.
743 endex = found[first][0]
746 snippets.append (Substring (s, index, len (s)))
749 (start , snip) = found[first]
750 snippets.append (Substring (s, index, start))
751 snippets.append (snip)
753 index = start + len (snip.match.group (0))
757 def filter_pipe (input, cmd):
759 ly.progress (_ ("Opening filter `%s\'") % cmd)
761 stdin, stdout, stderr = os.popen3 (cmd)
763 status = stdin.close ()
767 output = stdout.read ()
768 status = stdout.close ()
769 error = stderr.read ()
773 signal = 0x0f & status
774 if status or (not output and error):
775 exit_status = status >> 8
776 ly.error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
777 ly.error (_ ("The error log is as follows:"))
778 sys.stderr.write (error)
779 sys.stderr.write (stderr.read ())
788 return filter_pipe (s, filter_cmd)
790 def is_derived_class (cl, baseclass):
793 for b in cl.__bases__:
794 if is_derived_class (b, baseclass):
799 def process_snippets (cmd, snippets):
800 names = filter (lambda x: x, map (Lilypond_snippet.basename, snippets))
802 ly.system (string.join ([cmd] + names))
804 if format == HTML or format == TEXINFO:
806 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
808 ly.make_ps_images (i + '.eps', resolution=110)
809 # elif os.path.exists (i + '.ps'):
810 # ly.make_ps_images (i + '.ps', resolution=110)
813 LATEX_DOCUMENT = r'''
816 \typeout{textwidth=\the\textwidth}
817 \typeout{columnsep=\the\columnsep}
818 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
821 #need anything else besides textwidth?
822 def get_latex_textwidth (source):
823 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
824 preamble = source[:m.start (0)]
825 latex_document = LATEX_DOCUMENT % vars ()
826 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
829 m = re.search ('columns=([0-9.]*)', parameter_string)
831 columns = string.atoi (m.group (1))
834 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
836 columnsep = string.atof (m.group (1))
839 m = re.search('textwidth=([0-9.]*)pt', parameter_string)
841 textwidth = string.atof (m.group (1))
843 textwidth = (textwidth - columnsep) / columns
854 '.texinfo' : TEXINFO,
860 #TEXINFO: '.texinfo',
865 def do_file (input_filename):
869 e = os.path.splitext (input_filename)[1]
870 if e in ext2format.keys ():
872 format = ext2format[e]
874 ly.error (_ ("cannot determine format for: %s" \
877 if not input_filename or input_filename == '-':
878 in_handle = sys.stdin
879 input_fullname = '<stdin>'
881 if os.path.exists (input_filename):
882 input_fullname = input_filename
883 elif format == LATEX:
884 # urg python interface to libkpathsea?
885 input_fullname = ly.read_pipe ('kpsewhich '
886 + input_filename)[:-1]
888 input_fullname = find_file (input_filename)
889 in_handle = open (input_fullname)
891 if input_filename == '-':
894 input_base = os.path.basename \
895 (os.path.splitext (input_filename)[0])
897 # only default to stdout when filtering
898 if output_name == '-' or (not output_name and filter_cmd):
899 output_filename = '-'
900 output_file = sys.stdout
903 output_filename = input_base + format2ext[format]
905 if not os.path.isdir (output_name):
906 os.mkdir (output_name, 0777)
907 output_filename = (output_name
909 + format2ext[format])
912 if (os.path.exists (input_filename) and
913 os.path.exists (output_filename) and
914 os.path.samefile (output_filename, input_fullname)):
915 ly.error (_("Output would overwrite input file; use --output."))
918 output_file = open (output_filename, 'w')
920 os.chdir (output_name)
922 ly.progress (_ ("Reading %s...") % input_fullname)
923 source = in_handle.read ()
926 # FIXME: containing blocks must be first, see find_toplevel_snippets
932 'singleline_comment',
936 ly.progress (_ ("Dissecting..."))
937 chunks = find_toplevel_snippets (source, snippet_types)
940 global default_ly_options
942 if LINEWIDTH not in default_ly_options.keys ():
944 textwidth = get_latex_textwidth (source)
945 default_ly_options[LINEWIDTH] = '''%.0f\\pt''' \
947 elif format == TEXINFO:
948 for (k, v) in texinfo_linewidths.items ():
949 # FIXME: @paper is usually not in chunk #0:
950 # \input texinfo @c -*-texinfo-*-
951 # bluntly search first K of source
952 # s = chunks[0].replacement_text ()
953 if re.search (k, source[:1024]):
954 default_ly_options[LINEWIDTH] = v
958 output_file.writelines ([c.filter_text () for c in chunks])
962 outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
963 and x.is_outdated (), chunks)
964 ly.progress (_ ("Writing snippets..."))
965 map (Lilypond_snippet.write_ly, outdated)
969 ly.progress (_ ("Processing..."))
970 process_snippets (process_cmd, outdated)
972 ly.progress (_ ("All snippets are up to date..."))
975 ly.progress (_ ("Compiling %s...") % output_filename)
976 output_file.writelines ([s.replacement_text () \
980 def process_include (snippet):
981 os.chdir (original_dir)
982 name = snippet.substring ('filename')
983 ly.progress (_ ('Processing include: %s') % name)
987 map (process_include,
988 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
991 global format, output_name
992 global filter_cmd, process_cmd, verbose_p
994 (sh, long) = ly.getopt_args (option_definitions)
996 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
997 except getopt.error, s:
998 sys.stderr.write ('\n')
999 ly.error (_ ("getopt says: `%s\'" % s))
1000 sys.stderr.write ('\n')
1010 elif o == '--filter' or o == '-F':
1013 elif o == '--format' or o == '-f':
1015 if a == 'texi-html' or a == 'texi':
1017 elif o == '--help' or o == '-h':
1020 elif o == '--include' or o == '-I':
1021 include_path.append (os.path.join (original_dir,
1023 elif o == '--output' or o == '-o':
1025 elif o == '--outdir':
1027 elif o == '--process' or o == '-P':
1030 elif o == '--version' or o == '-v':
1031 ly.identify (sys.stdout)
1033 elif o == '--verbose' or o == '-V':
1035 elif o == '--warranty' or o == '-w':
1042 files = do_options ()
1045 process_cmd += string.join ([(' -I %s' % p)
1046 for p in include_path])
1048 ly.identify (sys.stderr)
1049 ly.setup_environment ()
1053 if __name__ == '__main__':