diff --git a/grim.py b/grim.py index 910056a02f69651f58c3c49b603516585ff2eebf..941ca09c9baf829d39a09bf019192cb590987f27 100755 --- a/grim.py +++ b/grim.py @@ -21,20 +21,31 @@ def type_selector(type): if 'single' in type: return 'SINGLE CHOICE QUESTION' + def file_exists(path): if not os.path.exists(path): msg = 'The script "{}" does not exist.'.format(path) raise argparse.ArgumentTypeError(msg) return path +def script_is_valid(script): + required = ['meta', 'task', 'choices', 'feedback'] + for field in required: + if not hasattr(script, field): + error("script does not export '{}' field.".format(field)) + if any(not hasattr(script, field) for field in required): + abort("Script is invalid (see above)") + def parseme(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest="command") - parser_new = subparsers.add_parser("new", help="The utility the generate new scripts.") + parser_new = subparsers.add_parser( + "new", help="The utility the generate new scripts.") parser_new.add_argument( "name", - help="The name of the new script" + help="The name of the new script", + metavar='NAME' ) parser_new.add_argument( "-t", @@ -58,7 +69,8 @@ def parseme(): metavar='POINTS', ) - parser_gen = subparsers.add_parser("gen", help="Subcommand to convert from script to xml.") + parser_gen = subparsers.add_parser( + "gen", help="Subcommand to convert from script to xml.") parser_gen.add_argument( '-o', '--out', @@ -90,6 +102,7 @@ def parseme(): def handle_choice_questions(output, script_name, instances): script = importlib.import_module(file_to_module(script_name)) + script_is_valid(script) data = { 'type': type_selector(script.meta['type']), 'description': "_description", @@ -107,6 +120,7 @@ def handle_choice_questions(output, script_name, instances): packer.convert_and_print(data, output, instances) info('Processed "{}" and wrote xml to "{}".'.format(script_name, output)) + def handle_new_script(name, type, author, points): raise NotImplementedError() diff --git a/hallgrim/IliasXMLCreator/gap.py b/hallgrim/IliasXMLCreator/gap.py new file mode 100644 index 0000000000000000000000000000000000000000..2c8e83e78093ed8ca67037d0714744dba0898714 --- /dev/null +++ b/hallgrim/IliasXMLCreator/gap.py @@ -0,0 +1,15 @@ +import xml.etree.ElementTree as et + +from hallgrim.IliasXMLCreator.xmlBuildingBlocks import * + +class GapQuestion: + """docstring for GapQuestion""" + def __init__(self, type, description, question_text, author, title, questions, feedback, gapLength): + self.type = type + self.description = description + self.question_text = question_text + self.author = author + self.title = title + self.questions = questions + self.feedback = feedback + self.gapLength = gapLength diff --git a/hallgrim/messages.py b/hallgrim/messages.py index 9f66c17a739612b9d81dc4555b47f1025bc8c488..e698bfd73bb7f51c7daa90b0ed31bd4b88c6add9 100644 --- a/hallgrim/messages.py +++ b/hallgrim/messages.py @@ -1,3 +1,5 @@ +import sys + def warn(msg): print('[WARN]', msg) @@ -5,4 +7,11 @@ def debug(msg): print('[DEBUG]', msg) def info(msg): - print('[INFO]', msg) \ No newline at end of file + print('[INFO]', msg) + +def error(msg): + print('[ERROR]', msg) + +def abort(msg): + print('[FATAL]', msg) + sys.exit('exiting...')