]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
Loglevels in our python scripts (lilypond-book, musicxml2ly, convert-ly)
[lilypond.git] / scripts / lilypond-book.py
index 9617f3666d3a4c878325a089b3d898def9771a8d..4d2b000fbd80252d9a3776244f6ad7a26aebdf5f 100644 (file)
@@ -91,7 +91,7 @@ authors = ('Jan Nieuwenhuizen <janneke@gnu.org>',
 
 ################################################################
 def exit (i):
-    if global_options.verbose:
+    if ly.is_verbose ():
         raise Exception (_ ('Exiting (%d)...') % i)
     else:
         sys.exit (i)
@@ -118,6 +118,7 @@ def warranty ():
         _ ("Distributed under terms of the GNU General Public License."),
         _ ("It comes with NO WARRANTY.")))
 
+
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'lilypond-book',
                               description=help_summary,
@@ -158,6 +159,12 @@ def get_option_parser ():
                   type="float",
                   default=3.0)
 
+    p.add_option ('--lily-loglevel',
+                  help=_ ("Print lilypond log messages according to LOGLEVEL"),
+                  metavar=_ ("LOGLEVEL"),
+                  action='store', dest='lily_loglevel',
+                  default=os.environ.get ("LILYPOND_LOGLEVEL", None))
+
     p.add_option ('--lily-output-dir',
                   help=_ ("write lily-XXX files to DIR, link into --output dir"),
                   metavar=_ ("DIR"),
@@ -169,6 +176,14 @@ def get_option_parser ():
                   action='append', dest='custom_packages',
                   default=[])
 
+    p.add_option ("-l", "--loglevel",
+                  help=_ ("Print log messages according to LOGLEVEL "
+                          "(NONE, ERROR, WARNING, PROGRESS (default), DEBUG)"),
+                  metavar=_ ("LOGLEVEL"),
+                  action='callback',
+                  callback=ly.handle_loglevel_option,
+                  type='string')
+
     p.add_option ("-o", '--output', help=_ ("write output to DIR"),
                   metavar=_ ("DIR"),
                   action='store', dest='output_dir',
@@ -179,6 +194,11 @@ def get_option_parser ():
                   action='store',
                   dest='process_cmd', default='')
 
+    p.add_option ('--redirect-lilypond-output',
+                  help = _ ("Redirect the lilypond output"),
+                  action='store_true',
+                  dest='redirect_output', default=False)
+
     p.add_option ('-s', '--safe', help=_ ("Compile snippets in safe mode"),
                   action="store_true",
                   default=False,
@@ -202,9 +222,9 @@ def get_option_parser ():
                   default=False)
 
     p.add_option ('-V', '--verbose', help=_ ("be verbose"),
-                  action="store_true",
-                  default=False,
-                  dest="verbose")
+                  action="callback",
+                  callback=ly.handle_loglevel_option,
+                  callback_args=("DEBUG",))
 
     p.version = "@TOPLEVEL_VERSION@"
     p.add_option("--version",
@@ -222,6 +242,11 @@ case --pdf option is set instead of pdflatex"),
               metavar=_ ("PROG"),
               action='store', dest='latex_program',
               default='latex')
+    group.add_option ('--texinfo-program',
+              help=_ ("run executable PROG instead of texi2pdf"),
+              metavar=_ ("PROG"),
+              action='store', dest='texinfo_program',
+              default='texi2pdf')
     group.add_option ('--pdf',
               action="store_true",
               dest="create_pdf",
@@ -347,7 +372,7 @@ def find_toplevel_snippets (input_string, formatter):
 
     return snippets
 
-def system_in_directory (cmd, directory):
+def system_in_directory (cmd, directory, logfile):
     """Execute a command in a different directory.
 
     Because of win32 compatibility, we can't simply use subprocess.
@@ -355,7 +380,10 @@ def system_in_directory (cmd, directory):
 
     current = os.getcwd()
     os.chdir (directory)
-    ly.system(cmd, be_verbose=global_options.verbose,
+    ly.system(cmd,
+              be_verbose=ly.is_verbose (),
+              redirect_output=global_options.redirect_output,
+              log_file=logfile,
               progress_p=1)
     os.chdir (current)
 
@@ -374,11 +402,12 @@ def process_snippets (cmd, snippets,
                           + list (set ([snip.basename() + '.ly' for snip in snippets])))
     name = os.path.join (lily_output_dir,
                          'snippet-names-%d.ly' % checksum)
+    logfile = name.replace('.ly', '')
     file (name, 'wb').write (contents)
 
     system_in_directory (' '.join ([cmd, ly.mkarg (name)]),
-                         lily_output_dir)
-
+                         lily_output_dir,
+                         logfile)
 
 def snippet_list_checksum (snippets):
     return hash (' '.join([l.basename() for l in snippets]))
@@ -612,6 +641,8 @@ def do_options ():
 
 def main ():
     # FIXME: 85 lines of `main' macramee??
+    if (os.environ.has_key ("LILYPOND_BOOK_LOGLEVEL")):
+        ly.set_loglevel (os.environ["LILYPOND_BOOK_LOGLEVEL"])
     files = do_options ()
 
     basename = os.path.splitext (files[0])[0]
@@ -645,8 +676,16 @@ def main ():
 
     global_options.formatter.process_options (global_options)
 
-    if global_options.verbose:
-        global_options.process_cmd += " --verbose "
+    if global_options.lily_loglevel:
+        ly.debug_output (_ ("Setting LilyPond's loglevel to %s") % global_options.lily_loglevel, True)
+        global_options.process_cmd += " --loglevel=%s" % global_options.lily_loglevel
+    elif ly.is_verbose ():
+        if os.environ.get ("LILYPOND_LOGLEVEL", None):
+            ly.debug_output (_ ("Setting LilyPond's loglevel to %s (from environment variable LILYPOND_LOGLEVEL)") % os.environ.get ("LILYPOND_LOGLEVEL", None), True)
+            global_options.process_cmd += " --loglevel=%s" % os.environ.get ("LILYPOND_LOGLEVEL", None)
+        else:
+            ly.debug_output (_ ("Setting LilyPond's output to --verbose, implied by lilypond-book's setting"), True)
+            global_options.process_cmd += " --verbose"
 
     if global_options.padding_mm:
         global_options.process_cmd += " -deps-box-padding=%f " % global_options.padding_mm
@@ -660,6 +699,7 @@ def main ():
     else:
         global_options.lily_output_dir = os.path.abspath(global_options.output_dir)
 
+    relative_output_dir = global_options.output_dir
 
     identify ()
     try:
@@ -672,9 +712,8 @@ def main ():
 
     base_file_name = os.path.splitext (os.path.basename (files[0]))[0]
     dep_file = os.path.join (global_options.output_dir, base_file_name + '.dep')
-    final_output_file = os.path.join (global_options.output_dir,
-                     base_file_name
-                     + '.%s' % global_options.format)
+    final_output_file = os.path.join (relative_output_dir,
+                     base_file_name + global_options.formatter.default_extension)
 
     os.chdir (original_dir)
     file (dep_file, 'w').write ('%s: %s'