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" BOOK.tely
16 * ly-options: intertext ?
18 * eps in latex / eps by lilypond -fps ?
19 * check latex parameters, twocolumn, multicolumn?
21 * Converting from lilypond-book source, substitute:
22 @mbinclude foo.itely -> @include foo.itely
35 # * use --png --ps --pdf for making images?
38 ################################################################
39 # Users of python modules should include this snippet
40 # and customize variables below.
42 # We'll suffer this path init stuff as long as we don't install our
43 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
44 # it as we do with teTeX on Red Hat Linux: set some environment var
45 # (PYTHONPATH) in profile)
47 # If set, LILYPONDPREFIX must take prevalence
48 # if datadir is not set, we're doing a build and LILYPONDPREFIX
49 import getopt, os, sys
50 datadir = '@local_lilypond_datadir@'
51 if not os.path.isdir (datadir):
52 datadir = '@lilypond_datadir@'
53 if os.environ.has_key ('LILYPONDPREFIX') :
54 datadir = os.environ['LILYPONDPREFIX']
55 while datadir[-1] == os.sep:
58 sys.path.insert (0, os.path.join (datadir, 'python'))
61 #if __name__ == '__main__':
69 program_version = '@TOPLEVEL_VERSION@'
70 program_name = 'lilypond-book'
73 original_dir = os.getcwd ()
76 help_summary = _ ("""Process LilyPond snippets in hybrid HTML, LaTeX or texinfo document.
79 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
80 lilypond-book --filter="convert-ly --no-version --from=2.0.0 -" BOOK
81 lilypond-book --process='lilypond -I include' BOOK
85 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>',
86 'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
88 option_definitions = [
89 (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
90 (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
91 ('', 'h', 'help', _ ("print this help")),
92 (_ ("DIR"), 'I', 'include', _ ("add DIR to include path")),
93 (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
94 (_ ("DIR"), 'o', 'output', _ ("write output to DIR")),
95 ('', 'V', 'verbose', _ ("be verbose")),
96 ('', 'v', 'version', _ ("print version information")),
97 ('', 'w', 'warranty', _ ("show warranty and copyright")),
100 include_path = [ly.abspath (os.getcwd ())]
101 lilypond_binary = os.path.join ('@bindir@', 'lilypond')
103 # only use installed binary when we're installed too.
104 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
105 lilypond_binary = 'lilypond'
111 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
114 default_ly_options = {}
117 # is this pythonic? Personally, I find this rather #define-nesque. --hwn
121 BOOKPAPER = 'bookpaper'
122 EXAMPLEINDENT = 'exampleindent'
124 FRAGMENT = 'fragment'
128 LINEWIDTH = 'linewidth'
129 NOFRAGMENT = 'nofragment'
130 NOINDENT = 'noindent'
135 PREAMBLE = 'preamble'
136 PRINTFILENAME = 'printfilename'
138 RAGGEDRIGHT = 'raggedright'
139 RELATIVE = 'relative'
140 STAFFSIZE = 'staffsize'
143 VERBATIM = 'verbatim'
145 # Recognize special sequences in the input
147 # (?P<name>regex) -- assign result of REGEX to NAME
148 # *? -- match non-greedily.
149 # (?m) -- multiline regex: make ^ and $ match at each line
150 # (?s) -- make the dot match all characters including newline
155 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
156 'lilypond_block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
157 'lilypond_file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
158 'multiline_comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
159 'singleline_comment': no_match,
160 'verb': r'''(?P<code><pre>.*?</pre>)''',
161 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
165 'include': r'(?m)^[^%\n]*?(?P<match>\\input{(?P<filename>[^}]+)})',
166 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
167 'lilypond_block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
168 'lilypond_file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
169 'multiline_comment': no_match,
170 'singleline_comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
171 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
172 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
176 'include': '(?m)^[^%\n]*?(?P<match>@include\s+(?P<filename>\S+))',
177 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
178 'lilypond_block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
179 'lilypond_file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
180 'multiline_comment': r'(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end\s+ignore)\s',
181 'singleline_comment': r'(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))',
183 # don't do this: fucks up with @code{@{}
184 # 'verb': r'''(?P<code>@code{.*?})''',
185 'verbatim': r'''(?s)(?P<code>@example\s.*?@end\s+example\s)''',
191 'option-sep' : '\s*',
192 'intertext': r',?\s*intertext=\".*?\"',
195 'intertext': r',?\s*intertext=\".*?\"',
196 'option-sep' : ',\s*',
199 'intertext': r',?\s*intertext=\".*?\"',
200 'option-sep' : ',\s*',
206 RELATIVE: r'''\relative c%(relative_quotes)s''',
210 indent = %(indent)s''',
212 linewidth = %(linewidth)s''',
216 linewidth = %(linewidth)s - 2.0 * %(exampleindent)s
220 raggedright = ##t''',
230 \remove Time_signature_engraver
237 #(set-global-staff-size %(staffsize)s)''',
243 FILTER: r'''<lilypond %(options)s>
253 <a href="%(base)s.ly">''',
255 <img align="center" valign="center"
256 border="0" src="%(image)s" alt="[image of music]">''',
257 PRINTFILENAME:'<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
258 QUOTE: r'''<blockquote>
269 OUTPUT: r'''{\parindent 0pt
271 \ifx\preLilyPondExample\undefined\relax\else\preLilyPondExample\fi
274 \ifx\postLilyPondExample\undefined\relax\else\postLilyPondExample\fi
276 PRINTFILENAME: '''\\texttt{%(filename)s}
279 QUOTE: r'''\begin{quotation}
283 VERBATIM: r'''\noindent
285 %(verb)s\end{verbatim}
287 FILTER: r'''\begin{lilypond}[%(options)s]
293 FILTER: r'''@lilypond[%(options)s]
298 OUTPUT: r'''@noindent
299 @image{%(base)s,,,[image of music],%(ext)s}
301 PRINTFILENAME: '''@file{%(filename)s}
304 QUOTE: r'''@quotation
308 # FIXME: @exampleindent 5 is the default...
309 VERBATIM: r'''@exampleindent 0
317 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
318 %%%% Options: [%(option_string)s]
319 #(set! toplevel-score-handler ly:parser-print-score)
320 #(set! toplevel-music-handler (lambda (p m)
321 (ly:parser-print-score
322 p (ly:music-scorify m))
325 \bookpaper {%(bookpaper_string)s
327 \paper { %(paper_string)s
338 texinfo_linewidths = {
339 '@afourpaper': '160 \\mm',
340 '@afourwide': '6.5 \\in',
341 '@afourlatex': '150 \\mm',
342 '@smallbook': '5 \\in' ,
343 '@letterpaper': '6\\in',
346 def classic_lilypond_book_compatibility (o):
347 if o == 'singleline':
349 m = re.search ('relative\s*([-0-9])', o)
351 return 'relative=%s' % m.group (1)
352 m = re.match ('([0-9]+)pt', o)
354 return 'staffsize=%s' % m.group (1)
355 m = re.match ('indent=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
357 f = float (m.group (1))
358 return 'indent=%f\\%s' % (f, m.group (2))
359 m = re.match ('linewidth=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
361 f = float (m.group (1))
362 return 'linewidth=%f\\%s' % (f, m.group (2))
365 def compose_ly (code, options):
367 for i in default_ly_options.keys ():
372 if QUOTE in options and LINEWIDTH in options:
373 options.remove (LINEWIDTH)
375 if FRAGMENT in options:
376 if RAGGEDRIGHT not in options:
377 options.append (RAGGEDRIGHT)
386 override.update (default_ly_options)
387 #FIXME: where to get sane value for exampleindent?
388 override[EXAMPLEINDENT] = r'9.0 \mm'
390 option_string = string.join (options, ',')
393 option_types = [NOTES, PREAMBLE, PAPER, BOOKPAPER]
394 for a in option_types:
398 c = classic_lilypond_book_compatibility (i)
400 ly.warning (_ ("deprecated ly-option used: %s" % i))
401 ly.warning (_ ("compatibility mode translation: %s" \
405 if string.find (i, '=') > 0:
406 key, value = string.split (i, '=')
407 override[key] = value
410 if not override.has_key (i):
414 for type in option_types:
415 if ly_options[type].has_key (key):
417 options_dict[type].append (ly_options[type][key])
421 if not found and key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
422 RELATIVE, VERBATIM, TEXIDOC):
423 ly.warning (_("ignoring unknown ly option: %s") % i)
426 if RELATIVE in override.keys () and override[RELATIVE]:
427 relative = string.atoi (override[RELATIVE])
433 relative_quotes += ',' * (- relative)
435 relative_quotes += "'" * relative
437 program_name = __main__.program_name
439 paper_string = string.join (options_dict[PAPER], '\n ') % override
440 bookpaper_string = string.join (options_dict[BOOKPAPER], '\n ') % override
441 notes_string = string.join (options_dict[NOTES], '\n ') % vars ()
442 preamble_string = string.join (options_dict[PREAMBLE], '\n ') % override
443 return (PREAMBLE_LY + body) % vars ()
447 # use lilypond for latex (.lytex) books,
448 # and lilypond --preview for html, texinfo books?
450 cmd = r'latex "\nonstopmode \input %s"' % file
451 # Ugh. (La)TeX writes progress and error messages on stdout
453 cmd = '(( %s >&2 ) >&- )' % cmd
455 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
459 # check if it really is EPS.
460 # Otherwise music glyphs disappear from 2nd and following pages.
462 # TODO: should run dvips -pp -E per page, then we get proper
465 f = open ('%s.eps' % file)
466 for x in range(0,10) :
467 if re.search ("^%%Pages: ", f.readline ()):
470 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
475 def find_file (name):
476 for i in include_path:
477 full = os.path.join (i, name)
478 if os.path.exists (full):
480 ly.error (_ ('file not found: %s') % name + '\n')
484 def verbatim_html (s):
485 return re.sub ('>', '>',
487 re.sub ('&', '&', s)))
489 def verbatim_texinfo (s):
490 return re.sub ('{', '@{',
492 re.sub ('@', '@@', s)))
494 def split_options (option_string):
495 return re.split (format_res[format]['option-sep'], option_string)
499 def replacement_text (self):
502 def filter_text (self):
503 return self.replacement_text ()
506 def is_outdated (self):
509 class Substring (Chunk):
510 def __init__ (self, source, start, end):
515 def replacement_text (self):
516 return self.source [self.start:self.end]
518 class Snippet (Chunk):
519 def __init__ (self, type, match, format):
526 def replacement_text (self):
527 return self.match.group (0)
529 def substring (self, s):
530 return self.match.group (s)
533 return `self.__class__` + " type = " + self.type
535 class Include_snippet (Snippet):
536 def processed_filename (self):
537 f = self.substring ('filename')
538 return os.path.splitext (f)[0] + format2ext[format]
540 def replacement_text (self):
541 s = self.match.group (0)
542 f = self.substring ('filename')
544 return re.sub (f, self.processed_filename (), s)
546 class Lilypond_snippet (Snippet):
547 def __init__ (self, type, match, format):
548 Snippet.__init__ (self, type, match, format)
549 os = match.group ('options')
551 self.options = split_options (os)
554 return self.substring ('code')
559 return compose_ly (s, self.options)
565 self.hash = abs (hash (self.full_ly ()))
570 return 'lily-%d' % self.get_hash ()
574 outf = open (self.basename () + '.ly', 'w')
575 outf.write (self.full_ly ())
577 open (self.basename() + '.txt', 'w').write("image of music")
580 def is_outdated (self):
581 base = self.basename ()
583 tex_file = '%s.tex' % base
584 ly_file = '%s.ly' % base
585 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
586 and os.stat (tex_file)[stat.ST_SIZE] \
587 and open (tex_file).readlines ()[-1][1:-1] \
590 if format == HTML or format == TEXINFO:
591 ok = ok and (os.path.exists (base + '.png')
592 or glob.glob (base + '-page*.png'))
594 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
595 # TODO: something smart with target formats
596 # (ps, png) and m/ctimes
600 def filter_text (self):
601 code = self.substring ('code')
602 s = run_filter (code)
604 'options': self.match.group ('options')
607 return output[self.format][FILTER] % d
609 def replacement_text (self):
610 func = Lilypond_snippet.__dict__ ['output_' + self.format]
613 def get_images (self):
614 base = self.basename ()
616 single = '%(base)s.png' % vars ()
617 multiple = '%(base)s-page1.png' % vars ()
619 if os.path.exists (multiple) \
620 and (not os.path.exists (single)\
621 or (os.stat (multiple)[stat.ST_MTIME] \
622 > os.stat (single)[stat.ST_MTIME])):
623 images = glob.glob ('%(base)s-page*.png' % vars ())
626 def output_html (self):
628 base = self.basename ()
630 str += self.output_print_filename (HTML)
631 if VERBATIM in self.options:
632 verb = verbatim_html (self.substring ('code'))
633 str += write (output[HTML][VERBATIM] % vars ())
634 if QUOTE in self.options:
635 str = output[HTML][QUOTE] % vars ()
637 str += output[HTML][BEFORE] % vars ()
638 for image in self.get_images ():
639 base, ext = os.path.splitext (image)
640 str += output[HTML][OUTPUT] % vars ()
641 str += output[HTML][AFTER] % vars ()
644 def output_info (self):
645 str = self.output_print_filename (HTML)
646 str = output[TEXINFO][BEFORE] % vars ()
647 for image in self.get_images ():
648 base, ext = os.path.splitext (image)
650 # URG, makeinfo implicitely prepends dot to ext
651 # specifying no extension is most robust
653 str += output[TEXINFO][OUTPUT] % vars ()
654 str += output[TEXINFO][AFTER] % vars ()
657 def output_latex (self):
659 base = self.basename ()
661 str += self.output_print_filename (LATEX)
662 if VERBATIM in self.options:
663 verb = self.substring ('code')
664 str += (output[LATEX][VERBATIM] % vars ())
665 if QUOTE in self.options:
666 str = output[LATEX][QUOTE] % vars ()
668 str += (output[LATEX][BEFORE]
669 + (output[LATEX][OUTPUT] % vars ())
670 + output[LATEX][AFTER])
673 def output_print_filename (self,format):
675 if PRINTFILENAME in self.options:
676 base = self.basename ()
677 filename = self.substring ('filename')
678 str = output[format][PRINTFILENAME] % vars ()
681 def output_texinfo (self):
683 # self.output_print_filename (TEXINFO)
684 str += ('@html\n' + self.output_print_filename (HTML)
686 str += ('@tex\n' + self.output_print_filename (LATEX)
688 base = self.basename ()
689 if TEXIDOC in self.options:
690 texidoc = base + '.texidoc'
691 if os.path.exists (texidoc):
692 str += '@include %(texidoc)s\n\n' % vars ()
694 if VERBATIM in self.options:
695 verb = verbatim_texinfo (self.substring ('code'))
696 str += (output[TEXINFO][VERBATIM] % vars ())
698 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
699 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
700 str += ('@html\n' + self.output_html () + '\n@end html\n')
702 if QUOTE in self.options:
703 str = output[TEXINFO][QUOTE] % vars ()
705 # need par after image
710 class Lilypond_file_snippet (Lilypond_snippet):
712 name = self.substring ('filename')
713 return '\\renameinput \"%s\"\n%s' % (name, open (find_file (name)).read ())
715 snippet_type_to_class = {
716 'lilypond_file' : Lilypond_file_snippet,
717 'lilypond_block' : Lilypond_snippet,
718 'lilypond' : Lilypond_snippet,
719 'include' : Include_snippet,
722 def find_toplevel_snippets (s, types):
725 res[i] = ly.re.compile (snippet_res[format][i])
729 ## found = dict (map (lambda x: (x, None), types))
732 map (lambda x, f=found: f.setdefault (x, None), types)
734 # We want to search for multiple regexes, without searching
735 # the string multiple times for one regex.
736 # Hence, we use earlier results to limit the string portion
738 # Since every part of the string is traversed at most once for
739 # every type of snippet, this is linear.
745 if not found[type] or found[type][0] < index:
747 m = res[type].search (s[index:endex])
752 if snippet_type_to_class.has_key (type):
753 cl = snippet_type_to_class[type]
754 snip = cl (type, m, format)
755 start = index + m.start (0)
756 found[type] = (start, snip)
759 and (not first or found[type][0] < found[first][0]):
764 # Limiting the search space is a cute
765 # idea, but this *requires* to search
766 # for possible containing blocks
767 # first, at least long as we do not
768 # search for the start of blocks, but
769 # always/directly for the entire
770 # @block ... @end block.
772 endex = found[first][0]
775 snippets.append (Substring (s, index, len (s)))
778 (start , snip) = found[first]
779 snippets.append (Substring (s, index, start))
780 snippets.append (snip)
782 index = start + len (snip.match.group (0))
786 def filter_pipe (input, cmd):
788 ly.progress (_ ("Opening filter `%s\'") % cmd)
790 stdin, stdout, stderr = os.popen3 (cmd)
792 status = stdin.close ()
796 output = stdout.read ()
797 status = stdout.close ()
798 error = stderr.read ()
802 signal = 0x0f & status
803 if status or (not output and error):
804 exit_status = status >> 8
805 ly.error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
806 ly.error (_ ("The error log is as follows:"))
807 sys.stderr.write (error)
808 sys.stderr.write (stderr.read ())
817 return filter_pipe (s, filter_cmd)
819 def is_derived_class (cl, baseclass):
822 for b in cl.__bases__:
823 if is_derived_class (b, baseclass):
828 def process_snippets (cmd, snippets):
829 names = filter (lambda x: x, map (Lilypond_snippet.basename, snippets))
831 ly.system (string.join ([cmd] + names))
833 if format == HTML or format == TEXINFO:
835 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
837 ly.make_ps_images (i + '.eps', resolution=110)
839 # elif os.path.exists (i + '.ps'):
840 # ly.make_ps_images (i + '.ps', resolution=110)
843 LATEX_DOCUMENT = r'''
846 \typeout{textwidth=\the\textwidth}
847 \typeout{columnsep=\the\columnsep}
848 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
851 #need anything else besides textwidth?
852 def get_latex_textwidth (source):
853 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
854 preamble = source[:m.start (0)]
855 latex_document = LATEX_DOCUMENT % vars ()
856 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
859 m = re.search ('columns=([0-9.]*)', parameter_string)
861 columns = string.atoi (m.group (1))
864 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
866 columnsep = string.atof (m.group (1))
869 m = re.search('textwidth=([0-9.]*)pt', parameter_string)
871 textwidth = string.atof (m.group (1))
873 textwidth = (textwidth - columnsep) / columns
884 '.texinfo' : TEXINFO,
890 #TEXINFO: '.texinfo',
895 def do_file (input_filename):
899 e = os.path.splitext (input_filename)[1]
900 if e in ext2format.keys ():
902 format = ext2format[e]
904 ly.error (_ ("cannot determine format for: %s" \
907 if not input_filename or input_filename == '-':
908 in_handle = sys.stdin
909 input_fullname = '<stdin>'
911 if os.path.exists (input_filename):
912 input_fullname = input_filename
913 elif format == LATEX:
914 # urg python interface to libkpathsea?
915 input_fullname = ly.read_pipe ('kpsewhich '
916 + input_filename)[:-1]
918 input_fullname = find_file (input_filename)
919 in_handle = open (input_fullname)
921 if input_filename == '-':
924 input_base = os.path.basename \
925 (os.path.splitext (input_filename)[0])
927 # only default to stdout when filtering
928 if output_name == '-' or (not output_name and filter_cmd):
929 output_filename = '-'
930 output_file = sys.stdout
933 output_filename = input_base + format2ext[format]
935 if not os.path.isdir (output_name):
936 os.mkdir (output_name, 0777)
937 output_filename = (output_name
939 + format2ext[format])
942 if (os.path.exists (input_filename) and
943 os.path.exists (output_filename) and
944 os.path.samefile (output_filename, input_fullname)):
945 ly.error (_("Output would overwrite input file; use --output."))
948 output_file = open (output_filename, 'w')
950 os.chdir (output_name)
952 ly.progress (_ ("Reading %s...") % input_fullname)
953 source = in_handle.read ()
956 # FIXME: containing blocks must be first, see find_toplevel_snippets
962 'singleline_comment',
966 ly.progress (_ ("Dissecting..."))
967 chunks = find_toplevel_snippets (source, snippet_types)
970 global default_ly_options
972 if not default_ly_options.has_key (LINEWIDTH):
974 textwidth = get_latex_textwidth (source)
975 default_ly_options[LINEWIDTH] = '''%.0f\\pt''' \
977 elif format == TEXINFO:
978 for (k, v) in texinfo_linewidths.items ():
979 # FIXME: @paper is usually not in chunk #0:
980 # \input texinfo @c -*-texinfo-*-
981 # bluntly search first K of source
982 # s = chunks[0].replacement_text ()
983 if re.search (k, source[:1024]):
984 default_ly_options[LINEWIDTH] = v
988 output_file.writelines ([c.filter_text () for c in chunks])
992 outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
993 and x.is_outdated (), chunks)
994 ly.progress (_ ("Writing snippets..."))
995 map (Lilypond_snippet.write_ly, outdated)
999 ly.progress (_ ("Processing..."))
1000 process_snippets (process_cmd, outdated)
1002 ly.progress (_ ("All snippets are up to date..."))
1005 ly.progress (_ ("Compiling %s...") % output_filename)
1006 output_file.writelines ([s.replacement_text () \
1010 def process_include (snippet):
1011 os.chdir (original_dir)
1012 name = snippet.substring ('filename')
1013 ly.progress (_ ('Processing include: %s') % name)
1017 map (process_include,
1018 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
1021 global format, output_name
1022 global filter_cmd, process_cmd, verbose_p
1024 (sh, long) = ly.getopt_args (option_definitions)
1026 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
1027 except getopt.error, s:
1028 sys.stderr.write ('\n')
1029 ly.error (_ ("getopt says: `%s\'" % s))
1030 sys.stderr.write ('\n')
1040 elif o == '--filter' or o == '-F':
1043 elif o == '--format' or o == '-f':
1045 if a == 'texi-html' or a == 'texi':
1047 elif o == '--help' or o == '-h':
1050 elif o == '--include' or o == '-I':
1051 include_path.append (os.path.join (original_dir,
1053 elif o == '--output' or o == '-o':
1055 elif o == '--outdir':
1057 elif o == '--process' or o == '-P':
1060 elif o == '--version' or o == '-v':
1061 ly.identify (sys.stdout)
1063 elif o == '--verbose' or o == '-V':
1065 elif o == '--warranty' or o == '-w':
1072 files = do_options ()
1074 if process_cmd == '':
1075 process_cmd = lilypond_binary + " -f tex "
1078 process_cmd += string.join ([(' -I %s' % p)
1079 for p in include_path])
1081 ly.identify (sys.stderr)
1082 ly.setup_environment ()
1086 if __name__ == '__main__':