]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
MIDI: add partcombine test.
[lilypond.git] / scripts / lilypond-book.py
index aafce6d2be78224d11faccf890e95b4a9ca2c828..9617f3666d3a4c878325a089b3d898def9771a8d 100644 (file)
@@ -51,6 +51,7 @@ import re
 import stat
 import sys
 import tempfile
+import imp
 from optparse import OptionGroup
 
 
@@ -112,7 +113,7 @@ def warranty ():
 
 %s
 %s
-''' % ( _ ('Copyright (c) %s by') % '2001--2010',
+''' % ( _ ('Copyright (c) %s by') % '2001--2011',
         '\n  '.join (authors),
         _ ("Distributed under terms of the GNU General Public License."),
         _ ("It comes with NO WARRANTY.")))
@@ -163,6 +164,11 @@ def get_option_parser ():
                   action='store', dest='lily_output_dir',
                   default=None)
 
+    p.add_option ('--load-custom-package', help=_ ("Load the additional python PACKAGE (containing e.g. a custom output format)"),
+                  metavar=_ ("PACKAGE"),
+                  action='append', dest='custom_packages',
+                  default=[])
+
     p.add_option ("-o", '--output', help=_ ("write output to DIR"),
                   metavar=_ ("DIR"),
                   action='store', dest='output_dir',
@@ -173,6 +179,11 @@ def get_option_parser ():
                   action='store',
                   dest='process_cmd', default='')
 
+    p.add_option ('-s', '--safe', help=_ ("Compile snippets in safe mode"),
+                  action="store_true",
+                  default=False,
+                  dest="safe_mode")
+
     p.add_option ('--skip-lily-check',
                   help=_ ("do not fail if no lilypond output is found"),
                   metavar=_ ("DIR"),
@@ -481,6 +492,7 @@ def samefile (f1, f2):
 
 def do_file (input_filename, included=False):
     # Ugh.
+    input_absname = input_filename
     if not input_filename or input_filename == '-':
         in_handle = sys.stdin
         input_fullname = '<stdin>'
@@ -490,7 +502,10 @@ def do_file (input_filename, included=False):
         else:
             input_fullname = global_options.formatter.input_fullname (input_filename)
         # Normalize path to absolute path, since we will change cwd to the output dir!
-        input_fullname = os.path.abspath (input_fullname)
+        # Otherwise, "lilypond-book -o out test.tex" will complain that it is
+        # overwriting the input file (which it is actually not), since the
+        # input filename is relative to the CWD...
+        input_absname = os.path.abspath (input_fullname)
 
         note_input_file (input_fullname)
         in_handle = file (input_fullname)
@@ -517,7 +532,7 @@ def do_file (input_filename, included=False):
                                    input_base + global_options.formatter.default_extension)
     if (os.path.exists (input_filename)
         and os.path.exists (output_filename)
-        and samefile (output_filename, input_fullname)):
+        and samefile (output_filename, input_absname)):
      error (
      _ ("Output would overwrite input file; use --output."))
      exit (2)
@@ -527,7 +542,8 @@ def do_file (input_filename, included=False):
         source = in_handle.read ()
         progress ('\n')
 
-        global_options.formatter.init_default_snippet_options (source)
+        if not included:
+            global_options.formatter.init_default_snippet_options (source)
 
 
         progress (_ ("Dissecting..."))
@@ -577,6 +593,14 @@ def do_options ():
 
     global_options.include_path =  map (os.path.abspath, global_options.include_path)
 
+    # Load the python packages (containing e.g. custom formatter classes)
+    # passed on the command line
+    nr = 0
+    for i in global_options.custom_packages:
+        nr += 1
+        print imp.load_source ("book_custom_package%s" % nr, i)
+
+
     if global_options.warranty:
         warranty ()
         exit (0)