Solve feed bugs

This commit is contained in:
Benjamin Bertrand 2017-04-16 17:16:46 +03:00
parent 710928869d
commit 62b35274e9

View File

@ -42,20 +42,22 @@ def feed(template, data, output="", force=0):
if not output: if not output:
num = 1 num = 1
output_p = Path(template).replace('tpl', f'{num:02d}') output_p = Path(template.replace('tpl', f'{num:02d}'))
while output.exists() or not force: while output_p.exists() and not force:
logger.debug(f"{output_p} exists. Try next one") logger.debug(f"{output_p} exists. Try next one")
num += 1 num += 1
output_p = Path(template).replace('tpl', f'{num:02d}') output_p = Path(template.replace('tpl', f'{num:02d}'))
elif not force: else:
logger.error(f"{output} exists. Use force=1 do override it") output_p = Path(output)
raise ValueError(f"{output} exists. Use force=1 do override it") 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() output_dir = output_p.dirname()
if not output_dir.exists(): if output_dir and not output_dir.exists():
output_dir.mkdir() 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)) output_f.write(tpl.render(**EXPORT_DICT, **data))
logger.info(f"{template} has been rendered to {output}.") 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}") 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 """ """ Clean the directory from aux and log latex files """
cleanning = subprocess.Popen( cleanning = subprocess.Popen(
[f"rm {dirname}/*.aux {dirname}/*.log"], [f"rm {dirname}/*.aux {dirname}/*.log"],
@ -99,9 +101,6 @@ def clean(dirname):
logger.error(err) logger.error(err)
logger.info(out) logger.info(out)
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4: # vim:set autoindent expandtab tabstop=4 shiftwidth=4: