def run_single(inpfname, incremental=False, fastfork=None, updatemd5=None):
    use_sphinx = 'sphinx' in inpfname and os.path.isdir(inpfname)
    if use_sphinx:
        sphinxdir = inpfname
        if sphinxdir.endswith('Makefile'):
            sphinxdir = dirname(sphinxdir)
        basename = os.path.basename(sphinxdir)
        if not basename:
            sphinxdir = os.path.dirname(sphinxdir)
            basename = os.path.basename(sphinxdir)
        if os.path.exists(sphinxdir + '.ignore'):
            return 'ignored', 0
    else:
        iprefix = os.path.splitext(inpfname)[0]
        basename = os.path.basename(iprefix)
        if os.path.exists(iprefix + '.ignore'):
            return 'ignored', 0

    oprefix = os.path.join(PathInfo.outdir, basename)
    mprefix = os.path.join(PathInfo.md5dir, basename)
    outpdf = oprefix + '.pdf'
    outtext = oprefix + '.log'
    md5file = mprefix + '.json'

    if incremental and os.path.exists(outpdf):
        return 'preexisting', 0

    for fname in (outtext, outpdf):
        if os.path.exists(fname):
            if os.path.isdir(fname):
                shutil.rmtree(fname)
            else:
                os.remove(fname)

    if use_sphinx:
        errcode, result = build_sphinx(sphinxdir, outpdf)
        checkinfo = checkmd5(outpdf, md5file, result, updatemd5, errcode)
    else:
        errcode, result = build_txt(iprefix, outpdf, fastfork)
        checkinfo = checkmd5(outpdf, md5file, result, updatemd5, errcode, iprefix)
    log(result, '')
    outf = open(outtext, 'wb')
    outf.write('\n'.join(result))
    outf.close()
    return checkinfo, errcode
Exemple #2
0
def run_single(inpfname, incremental=False, fastfork=None, updatemd5=None):
    use_sphinx = 'sphinx' in inpfname and os.path.isdir(inpfname)
    if use_sphinx:
        sphinxdir = inpfname
        if sphinxdir.endswith('Makefile'):
            sphinxdir = dirname(sphinxdir)
        basename = os.path.basename(sphinxdir)
        if not basename:
            sphinxdir = os.path.dirname(sphinxdir)
            basename = os.path.basename(sphinxdir)
    else:
        iprefix = os.path.splitext(inpfname)[0]
        basename = os.path.basename(iprefix)
        if os.path.exists(iprefix + '.ignore'):
            return 'ignored', 0

    oprefix = os.path.join(PathInfo.outdir, basename)
    mprefix = os.path.join(PathInfo.md5dir, basename)
    outpdf = oprefix + '.pdf'
    outtext = oprefix + '.log'
    md5file = mprefix + '.json'

    if incremental and os.path.exists(outpdf):
        return 'preexisting', 0

    for fname in (outtext, outpdf):
        if os.path.exists(fname):
            if os.path.isdir(fname):
                shutil.rmtree(fname)
            else:
                os.remove(fname)

    if use_sphinx:
        errcode, result = build_sphinx(sphinxdir, outpdf)
        checkinfo = checkmd5(outpdf, md5file, result, updatemd5, errcode)
    else:
        errcode, result = build_txt(iprefix, outpdf, fastfork)
        checkinfo = checkmd5(outpdf, md5file, result, updatemd5, errcode,
                             iprefix)
    log(result, '')
    outf = open(outtext, 'wb')
    outf.write('\n'.join(result))
    outf.close()
    return checkinfo, errcode
Exemple #3
0
def checkmd5(pdfpath, md5path, resultlist, updatemd5, failcode=1, iprefix=None):
    ''' checkmd5 validates the checksum of a generated PDF
        against the database, both reporting the results,
        and updating the database to add this MD5 into the
        unknown category if this checksum is not currently
        in the database.

        It updates the resultlist with information to be
        printed and added to the log file, and returns
        a result of 'good', 'bad', 'fail', or 'unknown'
        and an errcode of 0 for success, 1 for bad, 2 for fail and 3 for unknown
    '''
    if not os.path.exists(pdfpath):
        if not failcode and os.path.exists(iprefix + '.nopdf'):
            log(resultlist, "Validity of file %s checksum '(none generated)' is good." % os.path.basename(pdfpath))
            return ('good', 0)
        log(resultlist, 'File %s not generated' % os.path.basename(pdfpath))
        return ('fail', 2)
    if os.path.isdir(pdfpath):
        pdffiles = globjoin(pdfpath, '*.pdf')
    else:
        pdffiles = [pdfpath]

    # Read the database
    info = MD5Info()
    if os.path.exists(md5path):
        f = open(md5path, 'rb')
        exec f in info
        f.close()

    # Generate the current MD5
    md5s = []
    for pdfpath in pdffiles:
        cleanfile(pdfpath)
        f = open(pdfpath, 'rb')
        data = f.read()
        f.close()
        m = hashlib.md5()
        m.update(data)
        md5s.append(m.hexdigest())
    m = ' '.join(md5s)

    new_category = (updatemd5 and isinstance(updatemd5, str)
                        and updatemd5 or info.new_category)
    # Check MD5 against database and update if necessary
    resulttype = info.find(m, new_category)
    log(resultlist, "Validity of file %s checksum '%s' is %s." % (os.path.basename(pdfpath), m, resulttype))
    if info.changed and updatemd5:
        print "Updating MD5 file"
        f = open(md5path, 'wb')
        f.write(str(info))
        f.close()

    errorCodes = ['good', 'bad', 'fail', 'unknown']
    try:
        errcode = errorCodes.index(resulttype)
    except ValueError:
        errcode = 4

    return (resulttype, errcode)
Exemple #4
0
def build_sphinx(sphinxdir, outpdf):
    def getbuilddirs():
        return globjoin(sphinxdir, '*build*')

    for builddir in getbuilddirs():
        shutil.rmtree(builddir)
    errcode, result = textexec('make clean pdf', cwd=sphinxdir)
    builddirs = getbuilddirs()
    if len(builddirs) != 1:
        log(result, 'Cannot determine build directory')
        return 1, result
    builddir, = builddirs
    pdfdir = os.path.join(builddir, 'pdf')
    pdffiles = globjoin(pdfdir, '*.pdf')
    if len(pdffiles) == 1:
        shutil.copyfile(pdffiles[0], outpdf)
    elif not pdffiles:
        log(result, 'Output PDF apparently not generated')
        errcode = 1
    else:
        shutil.copytree(pdfdir, outpdf)
    return errcode, result
Exemple #5
0
def build_sphinx(sphinxdir, outpdf):
    def getbuilddirs():
        return globjoin(sphinxdir, '*build*')

    for builddir in getbuilddirs():
        shutil.rmtree(builddir)
    errcode, result = textexec('make clean pdf', cwd=sphinxdir)
    builddirs = getbuilddirs()
    if len(builddirs) != 1:
        log(result, 'Cannot determine build directory')
        return 1, result
    builddir, = builddirs
    pdfdir = os.path.join(builddir, 'pdf')
    pdffiles = globjoin(pdfdir, '*.pdf')
    if len(pdffiles) == 1:
        shutil.copyfile(pdffiles[0], outpdf)
    elif not pdffiles:
        log(result, 'Output PDF apparently not generated')
        errcode = 1
    else:
        shutil.copytree(pdfdir, outpdf)
    return errcode, result
Exemple #6
0
def run_installed_single(inpfname):
    """Like run_single, but runs the test using the installed version
    of rst2pdf"""

    iprefix = os.path.splitext(inpfname)[0]
    basename = os.path.basename(iprefix)
    if os.path.exists(iprefix + '.ignore'):
        return 'ignored', 0

    oprefix = os.path.join(PathInfo.outdir, basename)
    mprefix = os.path.join(PathInfo.md5dir, basename)
    outpdf = oprefix + '.pdf'
    outtext = oprefix + '.log'
    md5file = mprefix + '.json'

    inpfname = iprefix + '.txt'
    style = iprefix + '.style'
    cli = iprefix + '.cli'
    if os.path.isfile(cli):
        f = open(cli)
        extraargs = shlex.split(f.read())
        f.close()
    else:
        extraargs = []
    args = ['rst2pdf'
            ] + ['--date-invariant', '-v',
                 os.path.basename(inpfname)] + extraargs
    if os.path.exists(style):
        args.extend(('-s', os.path.basename(style)))
    args.extend(('-o', outpdf))
    errcode, result = textexec(args, cwd=dirname(inpfname), python_proc=None)

    checkinfo = checkmd5(outpdf, md5file, result, None, errcode, iprefix)
    log(result, '')
    outf = open(outtext, 'wb')
    outf.write('\n'.join(result))
    outf.close()
    return checkinfo, errcode
def run_installed_single(inpfname):
    """Like run_single, but runs the test using the installed version
    of rst2pdf"""

    iprefix = os.path.splitext(inpfname)[0]
    basename = os.path.basename(iprefix)
    if os.path.exists(iprefix + ".ignore"):
        return "ignored", 0

    oprefix = os.path.join(PathInfo.outdir, basename)
    mprefix = os.path.join(PathInfo.md5dir, basename)
    outpdf = oprefix + ".pdf"
    outtext = oprefix + ".log"
    md5file = mprefix + ".json"

    inpfname = iprefix + ".txt"
    style = iprefix + ".style"
    cli = iprefix + ".cli"
    if os.path.isfile(cli):
        f = open(cli)
        extraargs = shlex.split(f.read())
        f.close()
    else:
        extraargs = []
    args = ["rst2pdf"] + ["--date-invariant", "-v", os.path.basename(inpfname)] + extraargs
    if os.path.exists(style):
        args.extend(("-s", os.path.basename(style)))
    args.extend(("-o", outpdf))
    errcode, result = textexec(args, cwd=dirname(inpfname), python_proc=None)

    checkinfo = checkmd5(outpdf, md5file, result, None, errcode, iprefix)
    log(result, "")
    outf = open(outtext, "wb")
    outf.write("\n".join(result))
    outf.close()
    return checkinfo, errcode
Exemple #8
0
def run_installed_single(inpfname):
    """Like run_single, but runs the test using the installed version
    of rst2pdf"""

    iprefix = os.path.splitext(inpfname)[0]
    basename = os.path.basename(iprefix)
    if os.path.exists(iprefix + '.ignore'):
        return 'ignored', 0
        
    oprefix = os.path.join(PathInfo.outdir, basename)
    mprefix = os.path.join(PathInfo.md5dir, basename)
    outpdf = oprefix + '.pdf'
    outtext = oprefix + '.log'
    md5file = mprefix + '.json'
    
    inpfname = iprefix + '.txt'
    style = iprefix + '.style'
    cli = iprefix + '.cli'
    if os.path.isfile(cli):
        f = open(cli)
        extraargs=shlex.split(f.read())
        f.close()
    else:
        extraargs=[]
    args = ['rst2pdf'] + ['--date-invariant', '-v', os.path.basename(inpfname)]+extraargs
    if os.path.exists(style):
        args.extend(('-s', os.path.basename(style)))
    args.extend(('-o', outpdf))
    errcode, result = textexec(args, cwd=dirname(inpfname), python_proc=None)

    checkinfo = checkmd5(outpdf, md5file, result, None, errcode, iprefix)
    log(result, '')
    outf = open(outtext, 'wb')
    outf.write('\n'.join(result))
    outf.close()
    return checkinfo, errcode
Exemple #9
0
def checkmd5(pdfpath, md5path, resultlist, updatemd5, failcode=1, iprefix=None):
    ''' checkmd5 validates the checksum of a generated PDF
        against the database, both reporting the results,
        and updating the database to add this MD5 into the
        unknown category if this checksum is not currently
        in the database.

        It updates the resultlist with information to be
        printed and added to the log file, and returns
        a result of 'good', 'bad', 'fail', or 'unknown'
    '''
    if not os.path.exists(pdfpath):
        if not failcode and os.path.exists(iprefix + '.nopdf'):
            log(resultlist, "Validity of file %s checksum '(none generated)' is good." % os.path.basename(pdfpath))
            return 'good'
        log(resultlist, 'File %s not generated' % os.path.basename(pdfpath))
        return 'fail'
    if os.path.isdir(pdfpath):
        pdffiles = globjoin(pdfpath, '*.pdf')
    else:
        pdffiles = [pdfpath]

    # Read the database
    info = MD5Info()
    if os.path.exists(md5path):
        f = open(md5path, 'rb')
        exec(f, info)
        f.close()

    # Generate the current MD5
    md5s = []
    for pdfpath in pdffiles:
        f = open(pdfpath, 'rb')
        data = f.read()
        f.close()
        m = hashlib.md5()
        m.update(data)
        md5s.append(m.hexdigest())
    m = ' '.join(md5s)

    new_category = (updatemd5 and isinstance(updatemd5, str)
                        and updatemd5 or info.new_category)
    # Check MD5 against database and update if necessary
    resulttype = info.find(m, new_category)
    log(resultlist, "Validity of file %s checksum '%s' is %s." % (os.path.basename(pdfpath), m, resulttype))
    if info.changed and updatemd5:
        print("Updating MD5 file")
        f = open(md5path, 'wb')
        f.write(str(info))
        f.close()
    return resulttype