Skip to content

Commit 61b563a

Browse files
committed
Fix boolean value handling in rc parser. Add --debug option.
1 parent fe3e4d9 commit 61b563a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/assignmenttool/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
####################################################################################################
3636

37-
def compileLaTeX(tex, pdflatex):
37+
def compileLaTeX(tex, pdflatex, keepdir = False):
3838
""" Compile the 'hmm.tex' file in the given directory """
3939
tdir = tempfile.mkdtemp()
4040
out = open(tdir + '/out.tex', 'w')
@@ -48,8 +48,10 @@ def compileLaTeX(tex, pdflatex):
4848
raise AToolError('An error occurred during LaTeX execution')
4949
with open(os.path.join(tdir, 'out.pdf'), 'rb') as infile:
5050
pdf = infile.read()
51+
if keepdir:
52+
return tdir, pdf
5153
shutil.rmtree(tdir)
52-
return pdf
54+
return None, pdf
5355

5456
####################################################################################################
5557

@@ -213,7 +215,7 @@ def process(config):
213215
tex = tex.replace('§§global§§', '\n'.join(global_))
214216
tex = tex.replace('§§body§§', '\n'.join(body))
215217
tex = tex.replace('§§tasks§§', '\n'.join(body))
216-
pdf = compileLaTeX(tex, config.pdflatex)
218+
tdir, pdf = compileLaTeX(tex, config.pdflatex, config.debug)
217219

218220
# Move output file in place
219221
outpath = config.pdf_filename.replace('§§username§§', user).replace('§§name§§', realname).replace('§§sheetnr§§', str(config.sheet))
@@ -224,7 +226,10 @@ def process(config):
224226
raise AToolError(f"Output path '{outpath}' exists! Aborting!")
225227
with open(outpath, 'wb') as outfile:
226228
outfile.write(pdf)
227-
print(f'[OK]\t{user}')
229+
if config.debug:
230+
print(f"[OK]\t{user} [temp dir '{tdir}']")
231+
else:
232+
print(f"[OK]\t{user}")
228233

229234
# Prepare email if requested to do so
230235
if config.mail:

src/assignmenttool/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def config_from_cli():
5151
mail.add_argument('--mail-bcc', type = str, nargs = '+', help = 'BCC recipient to add to every sent out email.')
5252
mail.add_argument('--mail-subject', type = str, help = 'Subject for outgoing emails to participants. May contain variables §§username§§, §§name§§ and §§sheetnr§§.')
5353
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§§.')
54+
55+
dev = parser.add_argument_group('developer settings')
56+
dev.add_argument('--debug', action = 'store_true', help = 'Do not remove temporary LaTeX build folder. Print path instead.')
57+
5458
parser.add_argument_group(mail)
5559
config = parser.parse_args()
5660

@@ -88,9 +92,10 @@ def read_rc(config):
8892
# Boolean arguments
8993
for cli_arg, conf_group, conf_key in [
9094
('no_local_file', 'General', 'NoLocalFile'),
95+
('debug', 'General', 'Debug'),
9196
('mail_smtp_no_tls', 'Mail', 'NoTLS'),
9297
]:
93-
if vars(config)[cli_arg] is None:
98+
if vars(config)[cli_arg] is False:
9499
try:
95100
vars(config)[cli_arg] = True if configfile[conf_group][conf_key] in ['yes', 'y', 'Yes', 'YES', 'True', 'TRUE', 'true', '1'] else False
96101
except KeyError:

0 commit comments

Comments
 (0)