Commit 775e2baa authored by Louis's avatar Louis
Browse files

[pyromaths-cli] Add option --dirty

Closes #17
parent fb9b1610
......@@ -103,6 +103,15 @@ def argument_parser():
"of the string."
)
)
generate_parser.add_argument(
'-d', '--dirty',
action='store_const',
const=True,
default=False,
help=(
"Do not clean temporary directory after compilation."
)
)
generate_parser.add_argument(
'-o', '--output',
type=str,
......@@ -161,7 +170,7 @@ def do_generate(options):
'corrige': True,
'exercices': exercise_list,
}
with Fiche(parametres) as fiche:
with Fiche(parametres, dirty=options.dirty) as fiche:
fiche.write_tex()
for command in options.pipe:
formatted = command.format(fiche.texname)
......
......@@ -23,8 +23,10 @@
import codecs
import contextlib
import functools
import logging
import os
import subprocess
import shutil
import sys
import tempfile
import textwrap
......@@ -54,20 +56,20 @@ def supprime_extension(filename, ext):
class Fiche(contextlib.AbstractContextManager):
basename = "exercise"
def __init__(self, context, *, template="pyromaths.tex"):
def __init__(self, context, *, template="pyromaths.tex", dirty=False):
self.context = context
self.template = template
self.dirty = dirty
def __enter__(self):
self.tempdir = tempfile.TemporaryDirectory(prefix="pyromaths-")
self.workingdir = tempfile.mkdtemp(prefix="pyromaths-")
return self
@property
def workingdir(self):
return self.tempdir.name
def __exit__(self, exc_type, exc_value, traceback):
self.tempdir.cleanup()
if self.dirty:
logging.info("Temporary directory '%s' not removed (as requested).", self.workingdir)
else:
shutil.rmtree(self.workingdir)
def tempfile(self, ext=None):
if ext is None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment