From c1095648a180e124cff1bf31b31ba8e3c6a23b8d Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Thu, 10 Jun 2010 14:47:31 +0200 Subject: [PATCH] Lilypond-book: Add cmd line option to load additional python files 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index aafce6d2be..674878c3fa 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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) -- 2.39.5