Commit f4c5115a authored by Michael Völske's avatar Michael Völske

tools/exams: cleanup, remove dataclass dependency for older Pythons

parent 9e2e9264
......@@ -2,10 +2,14 @@
import click
import csv
import hashlib
import io
import logging
import os
import tempfile
import shutil
import subprocess
import tarfile
import tempfile
from tqdm import tqdm
......@@ -14,11 +18,15 @@ from tqdm import tqdm
def exams():
"""Commands for generating exam variants and importing into Moodle."""
########################################################################
def compile(frame_file, output_dir, output_name, env, verbose):
tmp = tempfile.mkdtemp()
cmd = ['pdflatex', f'-output-directory={tmp}', f'{frame_file}']
subenv = os.environ.copy()
env = {k:v.encode('latin1') for k, v in env.items()}
env = {k: v.encode('latin1') for k, v in env.items()}
subenv.update(env)
if verbose:
cmd.append('-interaction=nonstopmode')
......@@ -46,7 +54,8 @@ def compile(frame_file, output_dir, output_name, env, verbose):
show_default=True)
@click.option('--verbose', '-v', help='Run pdflatex in nonstopmode.',
is_flag=True, default=False)
def compile_variants(frame_file, output_dir, variant_list_file, name_column, verbose=False):
def compile_variants(frame_file, output_dir, variant_list_file, name_column,
verbose=False):
"""Compile variants of a LaTeX frame file using variables define in a list.
Arguments:
......@@ -75,7 +84,7 @@ def compile_variants(frame_file, output_dir, variant_list_file, name_column, ver
file.
An Example variant-list-file may look like this:
\b
STUDENT_NAME\tSTUDENT_EMAIL\tMY_VAR
Donald Duck\tdonald@example.com\thard-question
......@@ -91,25 +100,15 @@ def compile_variants(frame_file, output_dir, variant_list_file, name_column, ver
for env in tqdm(items, desc='compiling variants'):
compile(frame_file, output_dir, env[name_column], env, verbose)
#!/usr/bin/env python3
import click
import csv
import tarfile
import shutil
import io
import os
import hashlib
import logging
from dataclasses import dataclass
########################################################################
@dataclass
class Student:
name: str
email: str
salt: str = '42024'
class Student(object):
def __init__(self, name, email, salt='42024'):
self.name = name
self.email = email
self.salt = salt
@property
def generated_filename(self):
......@@ -117,14 +116,12 @@ class Student:
return f'{hashlib.sha1(data.encode()).hexdigest()}.pdf'
@dataclass
class Students(object):
list_file: str
input_pdf_dir: str
output_pdf_dir: str
url_prefix: str
def __post_init__(self):
def __init__(self, list_file, input_pdf_dir, output_pdf_dir, url_prefix):
self.list_file = list_file
self.input_pdf_dir = input_pdf_dir
self.output_pdf_dir = output_pdf_dir
self.url_prefix = url_prefix
dialect = csv.Sniffer().sniff(
next(open(self.list_file, encoding='latin1')))
with open(self.list_file, encoding='latin1') as f:
......@@ -171,7 +168,6 @@ class Students(object):
return ti, io.BytesIO(buf)
@exams.command()
@click.option('--backup-file', '-b', help='Moodle backup file (.mbz)',
required=True)
......@@ -191,9 +187,8 @@ class Students(object):
' Moodle Backup file.', show_default=True,
default='https://files.webis.de/teaching/'
'machine-learning-ws20/problem-sheets')
def insert_moodle(backup_file, student_list,
input_pdf_dir, output_pdf_dir,
url_prefix):
def insert_moodle(backup_file, student_list, input_pdf_dir, output_pdf_dir,
url_prefix):
"""Update a Moodle backup file with individual students' exam variants.
\b
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment