]> git.donarmstrong.com Git - lilypond.git/commitdiff
Lilypond-book: Add cmd line option to load additional python files
authorReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 10 Jun 2010 12:47:31 +0000 (14:47 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 11 Jun 2010 11:14:26 +0000 (13:14 +0200)
To customize the output of lilypond-book, a --load-custom-package=file
cmd line option has been added. The passed file can e.g. contain a custom
output formatter class (derived from some book_base.BookOutputFormat
derived class and registered via BookBase.register_format).

scripts/lilypond-book.py

index aafce6d2be78224d11faccf890e95b4a9ca2c828..674878c3fa60a20c9091d65ffd2014a180bbb607 100644 (file)
@@ -51,6 +51,7 @@ import re
 import stat
 import sys
 import tempfile
+import imp
 from optparse import OptionGroup
 
 
@@ -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',
@@ -577,6 +583,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)