X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Flilypond-book.py;h=82238647060af470765d2cd8273d394e0a8fabf8;hb=6060fd44fd273e8c138454350103876467decee3;hp=2564aea75ffb98e0b50fc5ceb60c7c5325e6f50e;hpb=aa6727cbb07c814266f95297dbc8a32ed584a5aa;p=lilypond.git diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 2564aea75f..8223864706 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -29,7 +29,6 @@ TODO: ''' import glob -import md5 import os import re import stat @@ -108,12 +107,12 @@ def warranty (): ly.encoded_write (sys.stdout, ''' %s -%s + %s %s %s -''' % ( _ ('Copyright (c) %s by') % '2001--2008', - ' '.join (authors), +''' % ( _ ('Copyright (c) %s by') % '2001--2009', + '\n '.join (authors), _ ("Distributed under terms of the GNU General Public License."), _ ("It comes with NO WARRANTY."))) @@ -273,7 +272,6 @@ TEXIDOC = 'texidoc' TEXINFO = 'texinfo' VERBATIM = 'verbatim' VERSION = 'lilypondversion' -FONTLOAD = 'fontload' FILENAME = 'filename' ALT = 'alt' @@ -601,7 +599,6 @@ simple_options = [ TEXIDOC, LANG, VERBATIM, - FONTLOAD, FILENAME, ALT, ADDVERSION @@ -719,27 +716,27 @@ output = { OUTPUT: r'''{%% \parindent 0pt \ifx\preLilyPondExample \undefined - \relax \else - \preLilyPondExample + \expandafter\preLilyPondExample \fi \def\lilypondbook{}%% \input %(base)s-systems.tex \ifx\postLilyPondExample \undefined - \relax \else - \postLilyPondExample + \expandafter\postLilyPondExample \fi }''', PRINTFILENAME: '''\\texttt{%(filename)s} ''', - QUOTE: r'''\begin{quotation}%(str)s + QUOTE: r'''\begin{quotation} +%(str)s \end{quotation}''', VERBATIM: r'''\noindent -\begin{verbatim}%(verb)s\end{verbatim}''', +\begin{verbatim}%(verb)s\end{verbatim} +''', VERSION: program_version, @@ -831,8 +828,6 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s %(preamble_string)s \paper { - #(define dump-extents #t) - %(font_dump_setting)s %(paper_string)s force-assignment = #"" line-width = #(- line-width (* mm %(padding_mm)f)) @@ -936,14 +931,15 @@ def verb_ly_gettext (s): s = ly_comment_re.sub (lambda m: ly_comment_gettext (t, m), s) - for v in ly_var_def_re.findall (s): - s = re.sub (r"(?m)(^|[' \\#])%s([^a-zA-Z])" % v, - "\\1" + t (v) + "\\2", - s) - for id in ly_context_id_re.findall (s): - s = re.sub (r'(\s+|")%s(\s+|")' % id, - "\\1" + t (id) + "\\2", - s) + if langdefs.LANGDICT[document_language].enable_ly_identifier_l10n: + for v in ly_var_def_re.findall (s): + s = re.sub (r"(?m)(^|[' \\#])%s([^a-zA-Z])" % v, + "\\1" + t (v) + "\\2", + s) + for id in ly_context_id_re.findall (s): + s = re.sub (r'(\s+|")%s(\s+|")' % id, + "\\1" + t (id) + "\\2", + s) return s texinfo_lang_re = re.compile ('(?m)^@documentlanguage (.*?)( |$)') @@ -1036,10 +1032,12 @@ class LilypondSnippet (Snippet): self.do_options (os, self.type) def verb_ly (self): - if NOGETTEXT in self.option_dict: - return self.substring ('code') - else: - return verb_ly_gettext (self.substring ('code')) + verb_text = self.substring ('code') + if not NOGETTEXT in self.option_dict: + verb_text = verb_ly_gettext (verb_text) + if not verb_text.endswith ('\n'): + verb_text += '\n' + return verb_text def ly (self): contents = self.substring ('code') @@ -1118,14 +1116,6 @@ class LilypondSnippet (Snippet): if not INDENT in self.option_dict: self.option_dict[INDENT] = '0\\mm' - # The QUOTE pattern from ly_options only emits the `line-width' - # keyword. - if has_line_width and QUOTE in self.option_dict: - if no_line_width_value: - del self.option_dict[LINE_WIDTH] - else: - del self.option_dict[QUOTE] - def compose_ly (self, code): if FRAGMENT in self.option_dict: body = FRAGMENT_LY @@ -1224,9 +1214,6 @@ class LilypondSnippet (Snippet): notes_string = '\n '.join (compose_dict[NOTES]) % vars () preamble_string = '\n '.join (compose_dict[PREAMBLE]) % override padding_mm = global_options.padding_mm - font_dump_setting = '' - if FONTLOAD in self.option_dict: - font_dump_setting = '#(define-public force-eps-font-include #t)\n' d = globals().copy() d.update (locals()) @@ -1234,7 +1221,13 @@ class LilypondSnippet (Snippet): def get_checksum (self): if not self.checksum: - hash = md5.md5 (self.relevant_contents (self.full_ly ())) + # Work-around for md5 module deprecation warning in python 2.5+: + try: + from hashlib import md5 + except ImportError: + from md5 import md5 + + hash = md5 (self.relevant_contents (self.full_ly ())) ## let's not create too long names. self.checksum = hash.hexdigest ()[:10] @@ -1475,9 +1468,9 @@ class LilypondSnippet (Snippet): doctitle = base + '.doctitle' translated_doctitle = doctitle + document_language if os.path.exists (translated_doctitle): - str += '@lydoctitle %s\n' % open (translated_doctitle).read () + str += '@lydoctitle %s\n\n' % open (translated_doctitle).read () elif os.path.exists (doctitle): - str += '@lydoctitle %s\n' % open (doctitle).read () + str += '@lydoctitle %s\n\n' % open (doctitle).read () if TEXIDOC in self.option_dict: texidoc = base + '.texidoc' translated_texidoc = texidoc + document_language @@ -1522,7 +1515,11 @@ class LilypondFileSnippet (LilypondSnippet): s = self.contents s = re_begin_verbatim.split (s)[-1] s = re_end_verbatim.split (s)[0] - return verb_ly_gettext (s) + if not NOGETTEXT in self.option_dict: + s = verb_ly_gettext (s) + if not s.endswith ('\n'): + s += '\n' + return s def ly (self): name = self.substring ('filename')