Example #1
0
 def dump (self, indent = ''):
     ly.debug_output ('%s<%s%s>' % (indent, self._name, ''.join ([' %s=%s' % item for item in self._attribute_dict.items ()])))
     non_text_children = [c for c in self._children if not isinstance (c, Hash_text)]
     if non_text_children:
         ly.debug_output ('\n')
     for c in self._children:
         c.dump (indent + "    ")
     if non_text_children:
         ly.debug_output (indent)
     ly.debug_output ('</%s>\n' % self._name)
Example #2
0
    def filter_pipe(self, input: bytes, cmd: str) -> bytes:
        """Pass input through cmd, and return the result.

        Args:
          input: the input
          cmd: a shell command

        Returns:
          the filtered result
        """
        ly.debug_output(_("Running through filter `%s'") % cmd, True)

        closefds = True
        if sys.platform == "mingw32":
            closefds = False

        p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=closefds)
        (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
        stdin.write(input)
        status = stdin.close()

        if not status:
            status = 0
            output = stdout.read()
            status = stdout.close()

        # assume stderr always is text
        err = stderr.read().decode('utf-8')

        if not status:
            status = 0
        signal = 0x0f & status
        if status or (not output and err):
            exit_status = status >> 8
            ly.error(_("`%s' failed (%d)") % (cmd, exit_status))
            ly.error(_("The ly.error log is as follows:"))
            sys.stderr.write(err)
            exit(status)

        ly.debug_output('\n')

        return output
Example #3
0
 def dump(self, indent=""):
     ly.debug_output(
         "%s<%s%s>" % (indent, self._name, "".join([" %s=%s" % item for item in self._attribute_dict.items()]))
     )
     non_text_children = [c for c in self._children if not isinstance(c, Hash_text)]
     if non_text_children:
         ly.debug_output("\n")
     for c in self._children:
         c.dump(indent + "    ")
     if non_text_children:
         ly.debug_output(indent)
     ly.debug_output("</%s>\n" % self._name)
Example #4
0
 def dump(self, indent=''):
     ly.debug_output('%s<%s%s>' % (indent, self._name, ''.join(
         [' %s=%s' % item for item in self._attribute_dict.items()])))
     non_text_children = [
         c for c in self._children if not isinstance(c, Hash_text)
     ]
     if non_text_children:
         ly.debug_output('\n')
     for c in self._children:
         c.dump(indent + "    ")
     if non_text_children:
         ly.debug_output(indent)
     ly.debug_output('</%s>\n' % self._name)
Example #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)))
Example #6
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)))
Example #7
0
 def dump(self, indent=''):
     ly.debug_output('%s' % string.strip(self._data))
Example #8
0
    def parse(self):
        pitches = {}
        notes = []
        music = []
        last_lyric = 0
        last_time = 0
        end_of_track_time = None
        for e in self.events:
            t = e[0]

            if start_quant_clocks:
                t = quantise_clocks(t, start_quant_clocks)

            if (e[1][0] == midi.NOTE_OFF
                    or (e[1][0] == midi.NOTE_ON and e[1][2] == 0)):
                ly.debug_output('%d: NOTE OFF: %s' % (t, e[1][1]))
                if not e[1][2]:
                    ly.debug_output('   ...treated as OFF')
                end_note(pitches, notes, t, e[1][1])

            elif e[1][0] == midi.NOTE_ON:
                if e[1][1] not in pitches:
                    ly.debug_output('%d: NOTE ON: %s' % (t, e[1][1]))
                    pitches[e[1][1]] = (t, e[1][2])
                else:
                    ly.debug_output('...ignored')

            # all include ALL_NOTES_OFF
            elif (e[1][0] >= midi.ALL_SOUND_OFF
                  and e[1][0] <= midi.POLY_MODE_ON):
                for i in pitches:
                    end_note(pitches, notes, t, i)

            elif e[1][0] == midi.META_EVENT:
                if e[1][1] == midi.END_OF_TRACK:
                    for i in pitches:
                        end_note(pitches, notes, t, i)
                    end_of_track_time = t
                    break

                elif e[1][1] == midi.SET_TEMPO:
                    (u0, u1, u2) = list(map(ord, e[1][2]))
                    us_per_4 = u2 + 256 * (u1 + 256 * u0)
                    seconds_per_1 = us_per_4 * 4 / 1e6
                    music.append((t, Tempo(seconds_per_1)))
                elif e[1][1] == midi.TIME_SIGNATURE:
                    (num, dur, clocks4, count32) = list(map(ord, e[1][2]))
                    den = 2 ** dur
                    music.append((t, Time(num, den)))
                elif e[1][1] == midi.KEY_SIGNATURE:
                    (alterations, minor) = list(map(ord, e[1][2]))
                    sharps = 0
                    flats = 0
                    if alterations < 127:
                        sharps = alterations
                    else:
                        flats = 256 - alterations

                    k = Key(sharps, flats, minor)
                    if not t and global_options.key:
                        # At t == 0, a set --key overrides us
                        k = global_options.key
                    music.append((t, k))

                    # ugh, must set key while parsing
                    # because Note init uses key
                    # Better do Note.calc () at dump time?
                    global_options.key = k

                elif (e[1][1] == midi.LYRIC
                      or (global_options.text_lyrics
                          and e[1][1] == midi.TEXT_EVENT)):
                    self.lyrics_p_ = True
                    if last_lyric:
                        last_lyric.clocks = t - last_time
                        music.append((last_time, last_lyric))
                    last_time = t
                    last_lyric = Text(midi.LYRIC, e[1][2])

                elif (e[1][1] >= midi.SEQUENCE_NUMBER
                      and e[1][1] <= midi.CUE_POINT):
                    text = Text(e[1][1], e[1][2])
                    text.track = self
                    music.append((t, text))
                    if text.type == midi.SEQUENCE_TRACK_NAME:
                        self.name = text.text
                else:
                    if global_options.verbose:
                        sys.stderr.write("SKIP: %s\n" % repr(e))
            else:
                if global_options.verbose:
                    sys.stderr.write("SKIP: %s\n" % repr(e))

        if last_lyric:
            # last_lyric.clocks = t - last_time
            # hmm
            last_lyric.clocks = clocks_per_4
            music.append((last_time, last_lyric))
            last_lyric = 0

        i = 0
        while len(notes):
            if i < len(music) and notes[0][0] >= music[i][0]:
                i = i + 1
            else:
                music.insert(i, notes[0])
                del notes[0]

        if end_of_track_time is not None:
            music.append((end_of_track_time, EndOfTrack()))

        return music
Example #9
0
def get_voice(channel, music):
    ly.debug_output('channel: ' + str(channel) + '\n')
    return unthread_notes(music)
Example #10
0
def get_texinfo_width_indent(source, global_options):
    #TODO: Check for end of header command "@c %**end of header"
    #      only use material before that comment ?

    # extract all relevant papter settings from the input:
    pagesize = None
    texinfo_paper_size_regexp = r'''(@(?:afourpaper|afourwide|afourlatex|afivepaper|smallbook|letterpaper))'''
    m = re.search(texinfo_paper_size_regexp, source)
    if m:
        pagesize = m.group(1)

    relevant_settings_regexp = r'''(@(?:fonttextsize|pagesizes|cropmarks|exampleindent).*)\n'''
    m = re.findall(relevant_settings_regexp, source)
    if pagesize:
        m.insert(0, pagesize)
    # all relevant options to insert into the test document:
    preamble = "\n".join(m)

    texinfo_document = TEXINFO_INSPECTION_DOCUMENT % {'preamble': preamble}

    (handle, tmpfile) = tempfile.mkstemp('.texi')
    outfile = os.path.splitext(tmpfile)[0] + '.pdf'

    tmp_handle = os.fdopen(handle, 'w')
    tmp_handle.write(texinfo_document)
    tmp_handle.close()

    # Work around a texi2pdf bug: if LANG=C is not given, a broken regexp is
    # used to detect relative/absolute paths, so the absolute path is not
    # detected as such and this command fails:
    progress(
        _("Running texi2pdf on file %s to detect default page settings.\n") %
        tmpfile)

    # execute the command and pipe stdout to the parameter_string:
    cmd = '%s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile)
    ly.debug_output("Executing: %s\n" % cmd)
    run_env = os.environ.copy()
    run_env['LC_ALL'] = 'C'

    ### unknown why this is necessary
    universal_newlines = True
    if sys.platform == 'mingw32':
        universal_newlines = False
        ### use os.system to avoid weird sleep() problems on
        ### GUB's python 2.4.2 on mingw
        # make file to write to
        output_dir = tempfile.mkdtemp()
        output_filename = os.path.join(output_dir, 'output.txt')
        # call command
        cmd += " > %s" % output_filename
        returncode = os.system(cmd)
        parameter_string = open(output_filename).read()
        if returncode != 0:
            warning(_("Unable to auto-detect default settings:\n"))
        # clean up
        os.remove(output_filename)
        os.rmdir(output_dir)
    else:
        proc = subprocess.Popen(cmd,
                                env=run_env,
                                universal_newlines=universal_newlines,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (parameter_string, error_string) = proc.communicate()
        if proc.returncode != 0:
            warning(
                _("Unable to auto-detect default settings:\n%s") %
                error_string)
    os.unlink(tmpfile)
    if os.path.exists(outfile):
        os.unlink(outfile)

    # Find textwidth and exampleindent and format it as \\mm or \\in
    # Use defaults if they cannot be extracted
    textwidth = 0
    m = re.search('textwidth=([0-9.]+)pt', parameter_string)
    if m:
        val = float(m.group(1)) / 72.27
        if pagesize and pagesize.startswith("@afour"):
            textwidth = "%g\\mm" % round(val * 25.4, 3)
        else:
            textwidth = "%g\\in" % round(val, 3)
    else:
        textwidth = texinfo_line_widths.get(pagesize, "6\\in")

    exampleindent = 0
    m = re.search('exampleindent=([0-9.]+)pt', parameter_string)
    if m:
        val = float(m.group(1)) / 72.27
        if pagesize and pagesize.startswith("@afour"):
            exampleindent = "%g\\mm" % round(val * 25.4, 3)
        else:
            exampleindent = "%g\\in" % round(val, 3)
    else:
        exampleindent = "0.4\\in"

    retval = {LINE_WIDTH: textwidth, EXAMPLEINDENT: exampleindent}
    ly.debug_output("Auto-detected values are: %s\n" % retval)
    return retval
Example #11
0
def get_texinfo_width_indent (source, global_options):
    #TODO: Check for end of header command "@c %**end of header"
    #      only use material before that comment ?

    # extract all relevant papter settings from the input:
    pagesize = None
    texinfo_paper_size_regexp = r'''(@(?:afourpaper|afourwide|afourlatex|afivepaper|smallbook|letterpaper))''';
    m = re.search (texinfo_paper_size_regexp, source);
    if m:
        pagesize = m.group (1)

    relevant_settings_regexp = r'''(@(?:fonttextsize|pagesizes|cropmarks|exampleindent).*)\n''';
    m = re.findall (relevant_settings_regexp, source);
    if pagesize:
        m.insert (0, pagesize);
    # all relevant options to insert into the test document:
    preamble = "\n".join (m);

    texinfo_document = TEXINFO_INSPECTION_DOCUMENT % {'preamble': preamble}

    (handle, tmpfile) = tempfile.mkstemp('.texi')
    outfile = os.path.splitext (tmpfile)[0] + '.pdf'

    tmp_handle = os.fdopen (handle,'w')
    tmp_handle.write (texinfo_document)
    tmp_handle.close ()

    # Work around a texi2pdf bug: if LANG=C is not given, a broken regexp is
    # used to detect relative/absolute pathes, so the absolute path is not
    # detected as such and this command fails:
    progress (_ ("Running texi2pdf on file %s to detect default page settings.\n") % tmpfile);

    # execute the command and pipe stdout to the parameter_string:
    cmd = 'LC_ALL=C %s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile);
    ly.debug_output ("Executing: %s\n" % cmd);

    proc = subprocess.Popen (cmd,
        universal_newlines=True, shell=True,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (parameter_string, error_string) = proc.communicate ()
    if proc.returncode != 0:
        warning (_ ("Unable to auto-detect default settings:\n%s")
                 % error_string)
    os.unlink (tmpfile)
    if os.path.exists(outfile):
        os.unlink (outfile)

    # Find textwidth and exampleindent and format it as \\mm or \\in
    # Use defaults if they cannot be extracted
    textwidth = 0
    m = re.search ('textwidth=([0-9.]+)pt', parameter_string)
    if m:
        val = float (m.group (1))/72.27
        if pagesize and pagesize.startswith ("@afour"):
            textwidth = "%g\\mm" % round (val*25.4, 3);
        else:
            textwidth = "%g\\in" % round (val, 3);
    else:
        textwidth = texinfo_line_widths.get(pagesize, "6\\in")

    exampleindent = 0
    m = re.search ('exampleindent=([0-9.]+)pt', parameter_string)
    if m:
        val = float (m.group (1))/72.27
        if pagesize and pagesize.startswith ("@afour"):
            exampleindent = "%g\\mm" % round (val*25.4, 3);
        else:
            exampleindent = "%g\\in" % round (val, 3);
    else:
        exampleindent = "0.4\\in"

    retval = {LINE_WIDTH: textwidth, EXAMPLEINDENT: exampleindent}
    ly.debug_output ("Auto-detected values are: %s\n" % retval);
    return retval;
Example #12
0
 def dump (self, indent = ''):
     ly.debug_output ('%s' % string.strip (self._data))
Example #13
0
def get_latex_textwidth (source, global_options):
    m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
    if m == None:
        warning (_ ("cannot find \\begin{document} in LaTeX document"))

        ## what's a sensible default?
        return 550.0

    preamble = source[:m.start (0)]
    latex_document = LATEX_INSPECTION_DOCUMENT % {'preamble': preamble}

    (handle, tmpfile) = tempfile.mkstemp('.tex')
    tmpfileroot = os.path.splitext (tmpfile)[0]
    tmpfileroot = os.path.split (tmpfileroot)[1]
    auxfile = tmpfileroot + '.aux'
    logfile = tmpfileroot + '.log'

    tmp_handle = os.fdopen (handle,'w')
    tmp_handle.write (latex_document)
    tmp_handle.close ()

    progress (_ ("Running `%s' on file `%s' to detect default page settings.\n")
              % (global_options.latex_program, tmpfile));
    cmd = '%s %s' % (global_options.latex_program, tmpfile);
    ly.debug_output ("Executing: %s\n" % cmd);
    run_env = os.environ.copy()
    run_env['LC_ALL'] = 'C'

    ### unknown why this is necessary
    universal_newlines = True
    if sys.platform == 'mingw32':
        universal_newlines = False
        ### use os.system to avoid weird sleep() problems on
        ### GUB's python 2.4.2 on mingw
        # make file to write to
        output_dir = tempfile.mkdtemp()
        output_filename = os.path.join(output_dir, 'output.txt')
        # call command
        cmd += " > %s" % output_filename
        returncode = os.system(cmd)
        parameter_string = open(output_filename).read()
        if returncode != 0:
            warning (_ ("Unable to auto-detect default settings:\n"))
        # clean up
        os.remove(output_filename)
        os.rmdir(output_dir)
    else:
        proc = subprocess.Popen (cmd,
            env=run_env,
            universal_newlines=universal_newlines,
            shell=True,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (parameter_string, error_string) = proc.communicate ()
        if proc.returncode != 0:
            warning (_ ("Unable to auto-detect default settings:\n%s")
                    % error_string)
    os.unlink (tmpfile)
    if os.path.exists (auxfile):
        os.unlink (auxfile)
    if os.path.exists (logfile):
        parameter_string = file (logfile).read()
        os.unlink (logfile)

    columns = 0
    m = re.search ('columns=([0-9.]+)', parameter_string)
    if m:
        columns = int (m.group (1))

    columnsep = 0
    m = re.search ('columnsep=([0-9.]+)pt', parameter_string)
    if m:
        columnsep = float (m.group (1))

    textwidth = 0
    m = re.search ('textwidth=([0-9.]+)pt', parameter_string)
    if m:
        textwidth = float (m.group (1))
        if columns:
            textwidth = (textwidth - columnsep) / columns

    return textwidth
Example #14
0
 def dump(self, indent=""):
     ly.debug_output("%s" % string.strip(self._data))
Example #15
0
def get_latex_textwidth(source, global_options):
    m = re.search(r'''(?P<preamble>\\begin\s*{document})''', source)
    if m == None:
        warning(_("cannot find \\begin{document} in LaTeX document"))

        ## what's a sensible default?
        return 550.0

    preamble = source[:m.start(0)]
    latex_document = LATEX_INSPECTION_DOCUMENT % {'preamble': preamble}

    (handle, tmpfile) = tempfile.mkstemp('.tex')
    tmpfileroot = os.path.splitext(tmpfile)[0]
    tmpfileroot = os.path.split(tmpfileroot)[1]
    auxfile = tmpfileroot + '.aux'
    logfile = tmpfileroot + '.log'

    tmp_handle = os.fdopen(handle, 'w')
    tmp_handle.write(latex_document)
    tmp_handle.close()

    progress(
        _("Running `%s' on file `%s' to detect default page settings.\n") %
        (global_options.latex_program, tmpfile))
    cmd = '%s %s' % (global_options.latex_program, tmpfile)
    ly.debug_output("Executing: %s\n" % cmd)
    run_env = os.environ.copy()
    run_env['LC_ALL'] = 'C'

    ### unknown why this is necessary
    universal_newlines = True
    if sys.platform == 'mingw32':
        universal_newlines = False
        ### use os.system to avoid weird sleep() problems on
        ### GUB's python 2.4.2 on mingw
        # make file to write to
        output_dir = tempfile.mkdtemp()
        output_filename = os.path.join(output_dir, 'output.txt')
        # call command
        cmd += " > %s" % output_filename
        returncode = os.system(cmd)
        parameter_string = open(output_filename).read()
        if returncode != 0:
            warning(_("Unable to auto-detect default settings:\n"))
        # clean up
        os.remove(output_filename)
        os.rmdir(output_dir)
    else:
        proc = subprocess.Popen(cmd,
                                env=run_env,
                                universal_newlines=universal_newlines,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (parameter_string, error_string) = proc.communicate()
        if proc.returncode != 0:
            warning(
                _("Unable to auto-detect default settings:\n%s") %
                error_string)
    os.unlink(tmpfile)
    if os.path.exists(auxfile):
        os.unlink(auxfile)
    if os.path.exists(logfile):
        parameter_string = file(logfile).read()
        os.unlink(logfile)

    columns = 0
    m = re.search('columns=([0-9.]+)', parameter_string)
    if m:
        columns = int(m.group(1))

    columnsep = 0
    m = re.search('columnsep=([0-9.]+)pt', parameter_string)
    if m:
        columnsep = float(m.group(1))

    textwidth = 0
    m = re.search('textwidth=([0-9.]+)pt', parameter_string)
    if m:
        textwidth = float(m.group(1))
        if columns:
            textwidth = (textwidth - columnsep) / columns

    return textwidth