Ejemplo n.º 1
0
def create_thumbnail(exercise, tempdir):
    """Crée la vignette de l'exercice"""
    outfile = exercise.thumb()

    logging.info("Compilation de l'exercice.")
    random.seed(0)
    creation(parametres_exo(exercise, tempdir))

    logging.info("Extraction de la vignette.")
    call([
        "convert",
        "-density",
        "288",
        os.path.join(tempdir, "thumb.pdf"),
        "-resize",
        "25%",
        "-crop",
        "710x560+0+85",
        "-flatten",
        "-trim",
        os.path.join(tempdir, "thumb.png"),
    ])

    logging.info("Appel de `pngnq` sur la vignette.")
    call([
        "pngnq",
        "-f",
        "-s1",
        "-n32",
        os.path.join(tempdir, "thumb.png"),
    ])
    shutil.copyfile(os.path.join(tempdir, "thumb-nq8.png"), outfile)

    logging.info("Optimisation de la vignette.")
    call(args=["optipng", "-o7", outfile])
Ejemplo n.º 2
0
def _thumb(exercise, outfile=None):
    ''' Create a thumbnail for this 'exercise'. '''
    if outfile is None:
        outfile = os.path.join(os.path.dirname(exercise.thumb), 'tmp', os.path.basename(exercise.thumb))
    print outfile
    # create pdf
    _param['liste_exos'] = [exercise()]
    creation(_param)
    # extract optimized thumbnail
    call(["convert", "-density", "288", "/tmp/thumb.pdf",
          "-resize", "25%", "-crop", "710x560+0+85",
          "-flatten", "-trim", "/tmp/thumb.png"],
         stdout=log)
    call(["pngnq", "-f", "-s1", "-n32", "/tmp/thumb.png"], stdout=log)
    log.write(outfile)
    shutil.copyfile( "/tmp/thumb-nq8.png", outfile)
    call(args=["optipng", "-o7", outfile])
    md5check(exercise, os.path.dirname(exercise.thumb))
Ejemplo n.º 3
0
    "openpdf": 0,
}

if len(sys.argv) == 4:
    os.rmdir(dt)
    lst = []
    for j in range(int(sys.argv[3])):
        print("Test n° %03d" % (j + 1))
        lst.append(LESFICHES[int(sys.argv[1])][2][int(sys.argv[2])]())
    parametres["liste_exos"] = lst
    # dt = tempfile.mkdtemp(prefix='pyromaths_tests-', dir='/tmp')
    dt = "/tmp"
    parametres["chemin_fichier"] = "/tmp"
    parametres["fiche_exo"] = os.path.join(dt, "exercices.tex")
    parametres["fiche_cor"] = os.path.join(dt, "exercices-corrige.tex")
    creation(parametres)
#    nettoyage(dt)

elif len(sys.argv) == 1:
    os.rmdir(dt)
    for j in range(100):
        print("Test n° %03d" % (j + 1))
        dt = tempfile.mkdtemp(prefix="pyromaths_tests-", dir="/tmp")
        parametres["chemin_fichier"] = dt
        parametres["fiche_exo"] = os.path.join(dt, "exercices.tex")
        parametres["fiche_cor"] = os.path.join(dt, "exercices-corrige.tex")
        lst = []
        for n in range(len(LESFICHES)):
            for exo in LESFICHES[n][2]:
                lst.append(exo())
        parametres["liste_exos"] = lst
Ejemplo n.º 4
0
def main():
    """Fonction principale."""
    creation(PARAMETRES)
    logging.info("Le modèle de document est disponible dans le fichier `exercices.tex`.")