Example #1
0
def run_bibtex(filename, verbose=False):
    """Run bibtex for a certain file.

    Run bibtex for ``filename`` and return the following values:

    - The return value of the bibtex runs done by this function: This value
      will be ``0`` after a successful run. Any other value indicates that
      there were some kind of problems.

    - Fatal error: Specifies if there was a fatal error while processing the
      bibliography.

    - Errors: The number of non-fatal errors encountered while processing the
      bibliography

    - Warnings: The number of warnings found while running this function

    Arguments:

        filename

            Specifies the name of the tex file without its extension. This
            information will be used to find the bibliography.

        verbose

            Specifies if the output by this function should be verbose.


    Returns: ``(int, bool, int, int)``

    Examples:

        >>> chdir('Tests/TeX')
        >>> run_bibtex('external_bibliography') # doctest:+ELLIPSIS
        <h4>Processing: ...
        ...
        (0, False, 0, 0)
        >>> chdir('../..')

    """
    directory = dirname(filename) if dirname(filename) else '.'
    regex_auxfiles = (r'.*/({}|bu\d+)\.aux$'.format(filename))
    auxfiles = [f for f in glob("{}/*.aux".format(directory))
                if match(regex_auxfiles, f)]

    stat, fatal, errors, warnings = 0, False, 0, 0
    for bib in auxfiles:
        print('<h4>Processing: {} </h4>'.format(bib))
        run_object = Popen("bibtex {}".format(shellquote(bib)), shell=True,
                           stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                           close_fds=True, universal_newlines=True)
        bp = BibTexParser(run_object.stdout, verbose)
        f, e, w = bp.parse_stream()
        fatal |= f
        errors += e
        warnings += w
        stat |= run_object.wait()
    return stat, fatal, errors, warnings
Example #2
0
def run_bibtex(filename, verbose=False):
    """Run bibtex for a certain file.

    Run bibtex for ``filename`` and return the following values:

    - The return value of the bibtex runs done by this function: This value
      will be ``0`` after a successful run. Any other value indicates that
      there were some kind of problems.

    - Fatal error: Specifies if there was a fatal error while processing the
      bibliography.

    - Errors: The number of non-fatal errors encountered while processing the
      bibliography

    - Warnings: The number of warnings found while running this function

    Arguments:

        filename

            Specifies the name of the tex file without its extension. This
            information will be used to find the bibliography.

        verbose

            Specifies if the output by this function should be verbose.


    Returns: ``(int, bool, int, int)``

    Examples:

        >>> chdir('Tests/TeX')
        >>> run_bibtex('external_bibliography') # doctest:+ELLIPSIS
        <h4>Processing: ...
        ...
        (0, False, 0, 0)
        >>> chdir('../..')

    """
    directory = dirname(filename) if dirname(filename) else '.'
    regex_auxfiles = (r'.*/({}|bu\d+)\.aux$'.format(filename))
    auxfiles = [f for f in glob("{}/*.aux".format(directory))
                if match(regex_auxfiles, f)]

    stat, fatal, errors, warnings = 0, False, 0, 0
    for bib in auxfiles:
        print('<h4>Processing: {} </h4>'.format(bib))
        run_object = Popen("bibtex {}".format(shellquote(bib)), shell=True,
                           stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                           close_fds=True, universal_newlines=True)
        bp = BibTexParser(run_object.stdout, verbose)
        f, e, w = bp.parse_stream()
        fatal |= f
        errors += e
        warnings += w
        stat |= run_object.wait()
    return stat, fatal, errors, warnings