From 62b35274e9bbd8d6991d54da7b1edabdbaa30f3a Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sun, 16 Apr 2017 17:16:46 +0300 Subject: [PATCH] Solve feed bugs --- pytex/pytex.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pytex/pytex.py b/pytex/pytex.py index 93759a0..2fcfb2a 100644 --- a/pytex/pytex.py +++ b/pytex/pytex.py @@ -42,20 +42,22 @@ def feed(template, data, output="", force=0): if not output: num = 1 - output_p = Path(template).replace('tpl', f'{num:02d}') - while output.exists() or not force: + output_p = Path(template.replace('tpl', f'{num:02d}')) + while output_p.exists() and not force: logger.debug(f"{output_p} exists. Try next one") num += 1 - output_p = Path(template).replace('tpl', f'{num:02d}') - elif not force: - logger.error(f"{output} exists. Use force=1 do override it") - raise ValueError(f"{output} exists. Use force=1 do override it") + output_p = Path(template.replace('tpl', f'{num:02d}')) + else: + output_p = Path(output) + if not force and output_p.exists(): + logger.error(f"{output} exists. Use force=1 do override it") + raise ValueError(f"{output} exists. Use force=1 do override it") output_dir = output_p.dirname() - if not output_dir.exists(): - output_dir.mkdir() + if output_dir and not output_dir.exists(): + output_dir.mkdir_p() - with open(output, "w") as output_f: + with open(output_p, "w") as output_f: output_f.write(tpl.render(**EXPORT_DICT, **data)) logger.info(f"{template} has been rendered to {output}.") @@ -87,7 +89,7 @@ def pdflatex(latex_file, output_dir=""): logger.debug(f"{latex_file} has been compiled in {output_dir}") -def clean(dirname): +def clean(dirname="."): """ Clean the directory from aux and log latex files """ cleanning = subprocess.Popen( [f"rm {dirname}/*.aux {dirname}/*.log"], @@ -99,9 +101,6 @@ def clean(dirname): logger.error(err) logger.info(out) - - - # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: