summaryrefslogtreecommitdiffstats
path: root/Smarker/smarker.py
diff options
context:
space:
mode:
Diffstat (limited to 'Smarker/smarker.py')
-rw-r--r--Smarker/smarker.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/Smarker/smarker.py b/Smarker/smarker.py
index 46feb5f..8b8527e 100644
--- a/Smarker/smarker.py
+++ b/Smarker/smarker.py
@@ -3,6 +3,7 @@ import jinja_helpers
import configparser
import misc_classes
import subprocess
+import database
import argparse
import tempfile
import zipfile
@@ -17,8 +18,11 @@ def main(**kwargs):
student_no = os.path.splitext(os.path.split(args["submission"])[-1])[0]
with misc_classes.ExtractZipToTempDir(args["submission"]) as submission_files:
- with open(kwargs["assessment"], "r") as f:
- assessment_struct = yaml.safe_load(f)
+ with database.SmarkerDatabase(
+ kwargs["mysql_host"], kwargs["mysql_user"], kwargs["mysql_passwd"],
+ "Smarker", int(kwargs["mysql_port"])) as db:
+
+ assessment_struct = db.get_assessment_yaml(kwargs["assessment"])
with misc_classes.FileDependencies(assessment_struct):
output = reflect.gen_reflection_report(submission_files, assessment_struct, student_no, kwargs, args["submission"])
@@ -46,19 +50,26 @@ def main(**kwargs):
if output_file == "auto":
output_file = "%s_report.%s" % (student_no, kwargs["format"])
- with open(output_file, "w") as f:
- f.write(strout)
-
if kwargs["format"] == "pdf":
os.environ["TEXINPUTS"] = os.path.join(os.path.split(__file__)[0], "python-latex-highlighting") + ":"
- os.rename(output_file, os.path.splitext(output_file)[0] + ".tex")
+
output_file = os.path.splitext(output_file)[0] + ".tex"
+ with open(output_file, "w") as f:
+ f.write(strout)
subprocess.run(["pdflatex", output_file])
-
- os.remove(os.path.splitext(output_file)[0] + ".tex")
- os.remove(os.path.splitext(output_file)[0] + ".log")
- os.remove(os.path.splitext(output_file)[0] + ".aux")
+ subprocess.run(["mv", os.path.splitext(os.path.split(output_file)[-1])[0] + ".pdf", os.path.split(output_file)[0]])
+
+ if os.path.exists(os.path.splitext(output_file)[0] + ".tex"):
+ os.remove(os.path.splitext(output_file)[0] + ".tex")
+ if os.path.exists(os.path.splitext(output_file)[0] + ".log"):
+ os.remove(os.path.splitext(output_file)[0] + ".log")
+ if os.path.exists(os.path.splitext(output_file)[0] + ".aux"):
+ os.remove(os.path.splitext(output_file)[0] + ".aux")
+
+ else:
+ with open(output_file, "w") as f:
+ f.write(strout)
# input("\n\n[tempdir: %s] Press any key to close..." % tempdir)
@@ -71,7 +82,7 @@ if __name__ == "__main__":
"-a", "--assessment",
action = misc_classes.EnvDefault,
envvar = "assessment",
- help = "Path to an assessment .yml file",
+ help = "Name of the assessment",
# type = os.path.abspath,
required = True
)
@@ -86,18 +97,18 @@ if __name__ == "__main__":
parser.add_argument(
"-f", "--format",
action = misc_classes.EnvDefault,
+ default = "txt",
envvar = "format",
help = "Output format type",
type = str,
choices = ["yaml", "json", "pdf"] + [os.path.splitext(f)[0] for f in os.listdir(os.path.join(os.path.split(__file__)[0], "templates"))],
- default = "txt"
)
parser.add_argument(
"-o", "--out",
action = misc_classes.EnvDefault,
- envvar = "out",
- help = "Path to write the output to, or, by default write to stdout. 'auto' automatically generates a file name.",
default = "stdout",
+ envvar = "output",
+ help = "Path to write the output to, or, by default write to stdout. 'auto' automatically generates a file name.",
)
for section in config.sections():