Exemple #1
0
def system_in_directory(cmd_str, directory, log_file):
    """Execute a command in a different directory."""

    if global_options.redirect_output:
        ly.progress(_("Processing %s.ly") % log_file)
    else:
        if ly.is_verbose():
            ly.progress(_("Invoking `%s\'") % cmd_str)
        else:
            name = command_name(cmd_str)
            ly.progress(_("Running %s...") % name)

    output_location = None
    if global_options.redirect_output:
        output_location = open(log_file + '.log', 'w')

    try:
        subprocess.run(cmd_str,
                       stdout=output_location,
                       stderr=output_location,
                       cwd=directory,
                       shell=True,
                       check=True)
    except subprocess.CalledProcessError as e:
        sys.stderr.write("%s\n" % e)
        sys.exit(1)
def system_in_directory (cmd, directory, logfile):
    """Execute a command in a different directory.

    Because of win32 compatibility, we can't simply use subprocess.
    """

    current = os.getcwd()
    os.chdir (directory)
    ly.system(cmd,
              be_verbose=ly.is_verbose (),
              redirect_output=global_options.redirect_output,
              log_file=logfile,
              progress_p=1)
    os.chdir (current)
Exemple #3
0
def system_in_directory (cmd, directory, logfile):
    """Execute a command in a different directory.

    Because of win32 compatibility, we can't simply use subprocess.
    """

    current = os.getcwd()
    os.chdir (directory)
    """NB - ignore_error is deliberately set to the same value
    as redirect_output - this is not a typo."""
    retval = ly.system(cmd,
              be_verbose=ly.is_verbose (),
              redirect_output=global_options.redirect_output,
              log_file=logfile,
              progress_p=1,
              ignore_error=global_options.redirect_output)
    if retval != 0:
        print ("Error trapped by lilypond-book")
        print ("\nPlease see " + logfile + ".log\n")
        sys.exit(1)

    os.chdir (current)
Exemple #4
0
def system_in_directory (cmd, directory, logfile):
    """Execute a command in a different directory.

    Because of win32 compatibility, we can't simply use subprocess.
    """

    current = os.getcwd()
    os.chdir (directory)
    """NB - ignore_error is deliberately set to the same value
    as redirect_output - this is not a typo."""
    retval = ly.system(cmd,
              be_verbose=ly.is_verbose (),
              redirect_output=global_options.redirect_output,
              log_file=logfile,
              progress_p=1,
              ignore_error=global_options.redirect_output)
    if retval != 0:
        print ("Error trapped by lilypond-book")
        print(("\nPlease see " + logfile + ".log\n"))
        sys.exit(1)

    os.chdir (current)
Exemple #5
0
def main():
    if "LILYPOND_BOOK_LOGLEVEL" in os.environ:
        ly.set_loglevel(os.environ["LILYPOND_BOOK_LOGLEVEL"])
    files = do_options()

    basename = os.path.splitext(files[0])[0]
    basename = os.path.split(basename)[1]

    if global_options.format:
        # Retrieve the formatter for the given format
        for formatter in book_base.all_formats:
            if formatter.can_handle_format(global_options.format):
                global_options.formatter = formatter
    else:
        global_options.formatter = guess_format(files[0])
        global_options.format = global_options.formatter.format

    # make the global options available to the formatters:
    global_options.formatter.global_options = global_options
    formats = global_options.formatter.image_formats

    if global_options.process_cmd == '':
        global_options.process_cmd = (lilypond_binary +
                                      ' --formats=%s -dbackend=eps ' % formats)

    if global_options.process_cmd:
        includes = global_options.include_path
        global_options.process_cmd += ' '.join(
            [' -I %s' % mkarg(p) for p in includes])

    global_options.formatter.process_options(global_options)

    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

    global_options.process_cmd += " -dread-file-list -dno-strip-output-dir"

    if global_options.lily_output_dir:
        global_options.lily_output_dir = os.path.abspath(
            global_options.lily_output_dir)
    else:
        global_options.lily_output_dir = os.path.abspath(
            global_options.output_dir)

    relative_output_dir = global_options.output_dir

    identify()
    try:
        chunks = do_file(files[0])
    except book_snippets.CompileError:
        exit(1)

    inputs = note_input_file('')
    inputs.pop()

    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(
        relative_output_dir,
        base_file_name + global_options.formatter.default_extension)

    os.chdir(original_dir)
    open(dep_file,
         'w').write('%s: %s\n' % (final_output_file, ' '.join(inputs)))
Exemple #6
0
def exit(i):
    if ly.is_verbose():
        raise Exception(_('Exiting (%d)...') % i)
    else:
        sys.exit(i)
Exemple #7
0
def exit (i):
    if ly.is_verbose ():
        raise Exception (_ ('Exiting (%d)...') % i)
    else:
        sys.exit (i)
Exemple #8
0
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]
    basename = os.path.split (basename)[1]

    if global_options.format:
      # Retrieve the formatter for the given format
      for formatter in BookBase.all_formats:
        if formatter.can_handle_format (global_options.format):
          global_options.formatter = formatter
    else:
        global_options.formatter = guess_format (files[0])
        global_options.format = global_options.formatter.format

    # make the global options available to the formatters:
    global_options.formatter.global_options = global_options
    formats = global_options.formatter.image_formats

    if global_options.process_cmd == '':
        global_options.process_cmd = (lilypond_binary
                                      + ' --formats=%s -dbackend=eps ' % formats)

    if global_options.process_cmd:
        includes = global_options.include_path
        if global_options.lily_output_dir:
            # This must be first, so lilypond prefers to read .ly
            # files in the other lybookdb dir.
            includes = [global_options.lily_output_dir] + includes
        global_options.process_cmd += ' '.join ([' -I %s' % ly.mkarg (p)
                                                 for p in includes])

    global_options.formatter.process_options (global_options)

    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

    global_options.process_cmd += " -dread-file-list -dno-strip-output-dir"

    if global_options.lily_output_dir:
        global_options.lily_output_dir = os.path.abspath(global_options.lily_output_dir)
        if not os.path.isdir (global_options.lily_output_dir):
            os.makedirs (global_options.lily_output_dir)
    else:
        global_options.lily_output_dir = os.path.abspath(global_options.output_dir)

    relative_output_dir = global_options.output_dir

    identify ()
    try:
        chunks = do_file (files[0])
    except BookSnippet.CompileError:
        exit (1)

    inputs = note_input_file ('')
    inputs.pop ()

    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 (relative_output_dir,
                     base_file_name + global_options.formatter.default_extension)

    os.chdir (original_dir)
    file (dep_file, 'w').write ('%s: %s\n'
                                % (final_output_file, ' '.join (inputs)))