paths cleaning

This commit is contained in:
Bertrand Benjamin 2018-05-19 11:08:29 +03:00
parent a3b8711fbf
commit 36d182c860
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,7 @@
Pytex Pytex
===== =====
Pytex is a simple package which make aa bridge between Latex and Python. Pytex is a simple package which make a bridge between Latex and Python.
texenv: Bring Python inside latex texenv: Bring Python inside latex
--------------------------------- ---------------------------------

View File

@ -38,6 +38,8 @@ def feed(template, data, output="", force=0):
:param output: name of the output file :param output: name of the output file
(by default: tpl is replaced by a 2 digits number) (by default: tpl is replaced by a 2 digits number)
:param force: Override is the output already exists :param force: Override is the output already exists
:return: name of fed template
""" """
logger.info(f"Getting template {template}") logger.info(f"Getting template {template}")
tpl = texenv.get_template(str(template)) tpl = texenv.get_template(str(template))
@ -57,21 +59,23 @@ def feed(template, data, output="", force=0):
output_dir = output_p.dirname() output_dir = output_p.dirname()
if output_dir and not output_dir.exists(): if output_dir and not output_dir.exists():
logger.debug(f"Creating output dir {output_dir}")
output_dir.mkdir_p() output_dir.mkdir_p()
with open(output_p, "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}.")
return output_p
def pdflatex(latex_file, output_dir=""): def pdflatex(latex_file, output_dir=""):
""" Compile latex file """ Compile a latex file with pdflatex
If output_dir is not set, it produce it next to the latex file. If output_dir is not set, it produce it next to the latex file.
""" """
if not output_dir: if not output_dir:
output_dir = Path(latex_file).dirname().abspath() output_dir = Path(latex_file).dirname().abspath()
logger.debug(f"output_dir for dflatex is {output_dir}") logger.debug(f"output_dir for pdflatex is {output_dir}")
pwd = Path('./').abspath() pwd = Path('./').abspath()
Path(output_dir).cd() Path(output_dir).cd()
@ -96,7 +100,7 @@ def pdflatex(latex_file, output_dir=""):
pwd.cd() pwd.cd()
def clean(dirname=".", garbages=["*.aux", "*.log"]): def clean(dirname="", garbages=["*.aux", "*.log"]):
""" Clean the directory from aux and log latex files """ """ Clean the directory from aux and log latex files """
if not dirname: if not dirname:
dirname = Path("./") dirname = Path("./")