Skip to content

Commit

Permalink
Fix boolean value handling in rc parser. Add --debug option.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuchenb committed May 23, 2020
1 parent fe3e4d9 commit 61b563a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/assignmenttool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

####################################################################################################

Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion src/assignmenttool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 61b563a

Please sign in to comment.