diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2022-04-26 18:08:15 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2022-04-26 18:08:15 +0100 |
commit | 1330ff9c1a8891913b5ef58cdfe64f8fd3751c75 (patch) | |
tree | e0d2639e5cc268bfa91dbe8b7da1d41ae227c19b /Smarker | |
parent | 12ac9bd354c664978523547ffac9bbebf0fcb577 (diff) | |
download | Smarker-1330ff9c1a8891913b5ef58cdfe64f8fd3751c75.tar.gz Smarker-1330ff9c1a8891913b5ef58cdfe64f8fd3751c75.zip |
Changed args ready for docker, started on Dockerfile
Diffstat (limited to 'Smarker')
-rw-r--r-- | Smarker/misc_classes.py | 14 | ||||
-rw-r--r-- | Smarker/smarker.py (renamed from Smarker/mark.py) | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Smarker/misc_classes.py b/Smarker/misc_classes.py index 09c3a7d..17ad36a 100644 --- a/Smarker/misc_classes.py +++ b/Smarker/misc_classes.py @@ -1,4 +1,5 @@ from dataclasses import dataclass
+import argparse
import tempfile
import zipfile
import shutil
@@ -19,6 +20,19 @@ latex_jinja_env = jinja2.Environment( loader = jinja2.FileSystemLoader(os.path.abspath(os.path.join(os.path.split(__file__)[0], "templates")))
)
+class EnvDefault(argparse.Action):
+ def __init__(self, envvar, required=True, default=None, **kwargs):
+ if not default and envvar:
+ if envvar in os.environ:
+ default = os.environ[envvar]
+ if required and default:
+ required = False
+ super(EnvDefault, self).__init__(default=default, required=required,
+ **kwargs)
+
+ def __call__(self, parser, namespace, values, option_string=None):
+ setattr(namespace, self.dest, values)
+
@dataclass
class ExtractZipToTempDir(tempfile.TemporaryDirectory):
zip_file:str
diff --git a/Smarker/mark.py b/Smarker/smarker.py index e8070f8..106d426 100644 --- a/Smarker/mark.py +++ b/Smarker/smarker.py @@ -69,18 +69,24 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "-a", "--assessment", + action = misc_classes.EnvDefault, + envvar = "assessment", help = "Path to an assessment .yml file", type = os.path.abspath, required = True ) parser.add_argument( "-s", "--submission", + action = misc_classes.EnvDefault, + envvar = "submission", help = "Path to a zip of a student's code", type = os.path.abspath, required = True ) parser.add_argument( "-f", "--format", + action = misc_classes.EnvDefault, + 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"))], @@ -88,6 +94,8 @@ if __name__ == "__main__": ) 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", ) @@ -96,6 +104,8 @@ if __name__ == "__main__": for option in config.options(section): parser.add_argument( "--%s_%s" % (section, option), + action = misc_classes.EnvDefault, + envvar = "--%s_%s" % (section, option), default = config.get(section, option), help = "Optional argument inherited from config file. Read smarker.conf for details." ) |