From 61b563abefda919d1a177b23f850d1a2bd679665 Mon Sep 17 00:00:00 2001 From: Leon Kuchenbecker Date: Sat, 23 May 2020 12:02:49 +0200 Subject: [PATCH] Fix boolean value handling in rc parser. Add --debug option. --- src/assignmenttool/__init__.py | 13 +++++++++---- src/assignmenttool/config.py | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/assignmenttool/__init__.py b/src/assignmenttool/__init__.py index a458a4e..6c548cf 100755 --- a/src/assignmenttool/__init__.py +++ b/src/assignmenttool/__init__.py @@ -34,7 +34,7 @@ #################################################################################################### -def compileLaTeX(tex, pdflatex): +def compileLaTeX(tex, pdflatex, keepdir = False): """ Compile the 'hmm.tex' file in the given directory """ tdir = tempfile.mkdtemp() out = open(tdir + '/out.tex', 'w') @@ -48,8 +48,10 @@ def compileLaTeX(tex, pdflatex): raise AToolError('An error occurred during LaTeX execution') with open(os.path.join(tdir, 'out.pdf'), 'rb') as infile: pdf = infile.read() + if keepdir: + return tdir, pdf shutil.rmtree(tdir) - return pdf + return None, pdf #################################################################################################### @@ -213,7 +215,7 @@ def process(config): tex = tex.replace('§§global§§', '\n'.join(global_)) tex = tex.replace('§§body§§', '\n'.join(body)) tex = tex.replace('§§tasks§§', '\n'.join(body)) - pdf = compileLaTeX(tex, config.pdflatex) + tdir, pdf = compileLaTeX(tex, config.pdflatex, config.debug) # Move output file in place outpath = config.pdf_filename.replace('§§username§§', user).replace('§§name§§', realname).replace('§§sheetnr§§', str(config.sheet)) @@ -224,7 +226,10 @@ def process(config): raise AToolError(f"Output path '{outpath}' exists! Aborting!") with open(outpath, 'wb') as outfile: outfile.write(pdf) - print(f'[OK]\t{user}') + if config.debug: + print(f"[OK]\t{user} [temp dir '{tdir}']") + else: + print(f"[OK]\t{user}") # Prepare email if requested to do so if config.mail: diff --git a/src/assignmenttool/config.py b/src/assignmenttool/config.py index 0d6dc34..8ebf44b 100644 --- a/src/assignmenttool/config.py +++ b/src/assignmenttool/config.py @@ -51,6 +51,10 @@ def config_from_cli(): mail.add_argument('--mail-bcc', type = str, nargs = '+', help = 'BCC recipient to add to every sent out email.') mail.add_argument('--mail-subject', type = str, help = 'Subject for outgoing emails to participants. May contain variables §§username§§, §§name§§ and §§sheetnr§§.') mail.add_argument('--mail-template', type = str, help = 'Path to the email body template for outgoing emails to participants. The template itself may contain variables §§username§§, §§name§§, §§sheetnr§§ and §§tutorname§§.') + + dev = parser.add_argument_group('developer settings') + dev.add_argument('--debug', action = 'store_true', help = 'Do not remove temporary LaTeX build folder. Print path instead.') + parser.add_argument_group(mail) config = parser.parse_args() @@ -88,9 +92,10 @@ def read_rc(config): # Boolean arguments for cli_arg, conf_group, conf_key in [ ('no_local_file', 'General', 'NoLocalFile'), + ('debug', 'General', 'Debug'), ('mail_smtp_no_tls', 'Mail', 'NoTLS'), ]: - if vars(config)[cli_arg] is None: + if vars(config)[cli_arg] is False: try: vars(config)[cli_arg] = True if configfile[conf_group][conf_key] in ['yes', 'y', 'Yes', 'YES', 'True', 'TRUE', 'true', '1'] else False except KeyError: