X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Flilypond-book.py;h=5b9adede20ab5c287f8a4aca7141a243fa5141ef;hb=025561ede5347bc7f5c7975dac96ae71741497ed;hp=14604ea8278f51b3963816bb2ebbd45f2c9e7ac6;hpb=1423508c355989fa26a8cfe5985b0d6e1ab0a538;p=lilypond.git
diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py
index 14604ea827..5b9adede20 100644
--- a/scripts/lilypond-book.py
+++ b/scripts/lilypond-book.py
@@ -1,5 +1,20 @@
#!@TARGET_PYTHON@
+# This file is part of LilyPond, the GNU music typesetter.
+#
+# LilyPond is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# LilyPond is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LilyPond. If not, see .
+
'''
Example usage:
@@ -111,7 +126,7 @@ def warranty ():
%s
%s
-''' % ( _ ('Copyright (c) %s by') % '2001--2009',
+''' % ( _ ('Copyright (c) %s by') % '2001--2010',
'\n '.join (authors),
_ ("Distributed under terms of the GNU General Public License."),
_ ("It comes with NO WARRANTY.")))
@@ -149,7 +164,8 @@ def get_option_parser ():
default='')
p.add_option ('--latex-program',
- help=_ ("run executable PROG instead of latex"),
+ help=_ ("run executable PROG instead of latex, or in\n\
+case --pdf option is set instead of pdflatex"),
metavar=_ ("PROG"),
action='store', dest='latex_program',
default='latex')
@@ -161,11 +177,28 @@ def get_option_parser ():
type="float",
default=3.0)
+ p.add_option ('--lily-output-dir',
+ help=_ ("write lily-XXX files to DIR, link into --output dir"),
+ metavar=_ ("DIR"),
+ action='store', dest='lily_output_dir',
+ default=None)
+
p.add_option ("-o", '--output', help=_ ("write output to DIR"),
metavar=_ ("DIR"),
action='store', dest='output_dir',
default='')
+ p.add_option ('--pdf',
+ action="store_true",
+ dest="create_pdf",
+ help=_ ("create PDF files for use with PDFTeX"),
+ default=False)
+
+ p.add_option ('-P', '--process', metavar=_ ("COMMAND"),
+ help = _ ("process ly_files using COMMAND FILE..."),
+ action='store',
+ dest='process_cmd', default='')
+
p.add_option ('--skip-lily-check',
help=_ ("do not fail if no lilypond output is found"),
metavar=_ ("DIR"),
@@ -178,21 +211,9 @@ def get_option_parser ():
action='store_true', dest='skip_png_check',
default=False)
- p.add_option ('--lily-output-dir',
- help=_ ("write lily-XXX files to DIR, link into --output dir"),
- metavar=_ ("DIR"),
- action='store', dest='lily_output_dir',
- default=None)
-
- p.add_option ('-P', '--process', metavar=_ ("COMMAND"),
- help = _ ("process ly_files using COMMAND FILE..."),
- action='store',
- dest='process_cmd', default='')
-
- p.add_option ('--pdf',
- action="store_true",
- dest="create_pdf",
- help=_ ("create PDF files for use with PDFTeX"),
+ p.add_option ('--use-source-file-names',
+ help=_ ("write snippet output files with the same base name as their source file"),
+ action='store_true', dest='use_source_file_names',
default=False)
p.add_option ('-V', '--verbose', help=_ ("be verbose"),
@@ -272,18 +293,23 @@ TEXIDOC = 'texidoc'
TEXINFO = 'texinfo'
VERBATIM = 'verbatim'
VERSION = 'lilypondversion'
-FONTLOAD = 'fontload'
FILENAME = 'filename'
ALT = 'alt'
-# NOTIME has no opposite so it isn't part of this dictionary.
+# NOTIME and NOGETTEXT have no opposite so they aren't part of this
+# dictionary.
# NOQUOTE is used internally only.
no_options = {
NOFRAGMENT: FRAGMENT,
NOINDENT: INDENT,
}
+# Options that have no impact on processing by lilypond (or --process
+# argument)
+PROCESSING_INDEPENDENT_OPTIONS = (
+ ALT, NOGETTEXT, VERBATIM, ADDVERSION,
+ TEXIDOC, DOCTITLE, VERSION, PRINTFILENAME)
# Recognize special sequences in the input.
#
@@ -364,9 +390,9 @@ snippet_res = {
r'''(?mx)
(?P
.*?)\s*:)?\s*
+ (\s+(?P.*?))?\s*:\s*
(?P.*?)
- />)''',
+ \s*/>)''',
'lilypond_block':
r'''(?msx)
@@ -375,7 +401,7 @@ snippet_res = {
\s*(?P.*?)\s*
>
(?P.*?)
-
)''',
+ )''',
'lilypond_file':
r'''(?mx)
@@ -384,7 +410,7 @@ snippet_res = {
\s*(?P.*?)\s*
>
\s*(?P.*?)\s*
- )''',
+ )''',
'multiline_comment':
r'''(?smx)
@@ -438,10 +464,10 @@ snippet_res = {
r'''(?smx)
^[^%\n]*?
(?P
- \\begin\s*(
+ \\begin\s*(?P{lilypond}\s*)?(
\[
\s*(?P.*?)\s*
- \])?\s*{lilypond}
+ \])?(?(env)|\s*{lilypond})
(?P.*?)
^[^%\n]*?
\\end\s*{lilypond})''',
@@ -600,7 +626,6 @@ simple_options = [
TEXIDOC,
LANG,
VERBATIM,
- FONTLOAD,
FILENAME,
ALT,
ADDVERSION
@@ -830,8 +855,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))
@@ -937,7 +960,7 @@ def verb_ly_gettext (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,
+ s = re.sub (r"(?m)(? 2:
+ base_suffix = '-' + components[-1]
+ else:
+ base_suffix = ''
+ final_name = self.final_basename () + base_suffix + ext
+ else:
+ final_name = name
try:
- os.unlink (os.path.join (destination, name))
+ os.unlink (os.path.join (destination, final_name))
except OSError:
pass
src = os.path.join (output_dir, name)
- dst = os.path.join (destination, name)
+ dst = os.path.join (destination, final_name)
dst_path = os.path.split(dst)[0]
if not os.path.isdir (dst_path):
os.makedirs (dst_path)
@@ -1381,7 +1449,7 @@ class LilypondSnippet (Snippet):
return func (self)
def get_images (self):
- base = self.basename ()
+ base = self.final_basename ()
single = '%(base)s.png' % vars ()
multiple = '%(base)s-page1.png' % vars ()
@@ -1398,7 +1466,7 @@ class LilypondSnippet (Snippet):
def output_docbook (self):
str = ''
- base = self.basename ()
+ base = self.final_basename ()
for image in self.get_images ():
(base, ext) = os.path.splitext (image)
str += output[DOCBOOK][OUTPUT] % vars ()
@@ -1414,7 +1482,7 @@ class LilypondSnippet (Snippet):
def output_html (self):
str = ''
- base = self.basename ()
+ base = self.final_basename ()
if self.format == HTML:
str += self.output_print_filename (HTML)
if VERBATIM in self.option_dict:
@@ -1443,13 +1511,13 @@ class LilypondSnippet (Snippet):
info_image_path = os.path.join (global_options.info_images_dir, base)
str += output[TEXINFO][OUTPUTIMAGE] % vars ()
- base = self.basename ()
+ base = self.final_basename ()
str += output[self.format][OUTPUT] % vars ()
return str
def output_latex (self):
str = ''
- base = self.basename ()
+ base = self.final_basename ()
if self.format == LATEX:
str += self.output_print_filename (LATEX)
if VERBATIM in self.option_dict:
@@ -1470,7 +1538,7 @@ class LilypondSnippet (Snippet):
def output_print_filename (self, format):
str = ''
if PRINTFILENAME in self.option_dict:
- base = self.basename ()
+ base = self.final_basename ()
filename = os.path.basename (self.substring ('filename'))
str = output[format][PRINTFILENAME] % vars ()
@@ -1478,7 +1546,7 @@ class LilypondSnippet (Snippet):
def output_texinfo (self):
str = self.output_print_filename (TEXINFO)
- base = self.basename ()
+ base = self.final_basename ()
if DOCTITLE in self.option_dict:
doctitle = base + '.doctitle'
translated_doctitle = doctitle + document_language
@@ -1541,6 +1609,13 @@ class LilypondFileSnippet (LilypondSnippet):
return ('\\sourcefilename \"%s\"\n\\sourcefileline 0\n%s'
% (name, self.contents))
+ def final_basename (self):
+ if global_options.use_source_file_names:
+ base = os.path.splitext (os.path.basename (self.substring ('filename')))[0]
+ return base
+ else:
+ return self.basename ()
+
class LilyPondVersionString (Snippet):
"""A string that does not require extra memory."""
@@ -1709,7 +1784,7 @@ def process_snippets (cmd, snippets,
checksum = snippet_list_checksum (snippets)
contents = '\n'.join (['snippet-map-%d.ly' % checksum]
- + [snip.basename() + '.ly' for snip in snippets])
+ + list (set ([snip.basename() + '.ly' for snip in snippets])))
name = os.path.join (lily_output_dir,
'snippet-names-%d.ly' % checksum)
file (name, 'wb').write (contents)
@@ -1758,17 +1833,17 @@ def get_latex_textwidth (source):
os.unlink (logfile)
columns = 0
- m = re.search ('columns=([0-9.]*)', parameter_string)
+ m = re.search ('columns=([0-9.]+)', parameter_string)
if m:
columns = int (m.group (1))
columnsep = 0
- m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
+ m = re.search ('columnsep=([0-9.]+)pt', parameter_string)
if m:
columnsep = float (m.group (1))
textwidth = 0
- m = re.search ('textwidth=([0-9.]*)pt', parameter_string)
+ m = re.search ('textwidth=([0-9.]+)pt', parameter_string)
if m:
textwidth = float (m.group (1))
if columns:
@@ -2079,6 +2154,8 @@ def main ():
global_options.process_cmd += ' --formats=eps '
if global_options.create_pdf:
global_options.process_cmd += "--pdf -dinclude-eps-fonts -dgs-load-fonts "
+ if global_options.latex_program == 'latex':
+ global_options.latex_program = 'pdflatex'
if global_options.verbose:
global_options.process_cmd += " --verbose "