From 28e8774d4d3f3e0da950a43fdbceae5993bc0f74 Mon Sep 17 00:00:00 2001 From: Jan Maximilian Michal <j.michal@stud.uni-goettingen.de> Date: Tue, 13 Dec 2016 02:56:18 +0000 Subject: [PATCH] Minor changes and typos. Can now upload multiple scripts at once --- README.md | 2 +- hallgrim/IliasXMLCreator/packer.py | 1 + hallgrim/IliasXMLCreator/xmlBuildingBlocks.py | 18 ++++++++---- hallgrim/hallgrim.py | 29 ++++++++++--------- setup.py | 8 ++--- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8584eb4..e970bc1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ replace requests with the native urllib3 - you are welcome to help. ### TODO * Add a more description / documentation. -* Add more functionality (numeric gap, multiple answers per gap, alignment) +* Add more functionality (multiple answers per gap, alignment) * Make parsers more robust. * Create whole test object with questions for direct import. Create two versions (one for internal use and one for the test.) diff --git a/hallgrim/IliasXMLCreator/packer.py b/hallgrim/IliasXMLCreator/packer.py index f82504c..d010c5c 100644 --- a/hallgrim/IliasXMLCreator/packer.py +++ b/hallgrim/IliasXMLCreator/packer.py @@ -2,6 +2,7 @@ import xml.etree.ElementTree as et from . import multi, single, gap + def create_xml_tree(item_list): root = et.Element('questestinterop') tree = et.ElementTree(root) diff --git a/hallgrim/IliasXMLCreator/xmlBuildingBlocks.py b/hallgrim/IliasXMLCreator/xmlBuildingBlocks.py index dd9a9a2..3352283 100644 --- a/hallgrim/IliasXMLCreator/xmlBuildingBlocks.py +++ b/hallgrim/IliasXMLCreator/xmlBuildingBlocks.py @@ -8,12 +8,13 @@ import xml.etree.ElementTree as et # ########################################################################## -########################################################################## def xml_print(element, **kwargs): import xml.dom.minidom - xml = xml.dom.minidom.parseString(et.tostring(element, encoding='utf8', method='xml')) # or xml.dom.minidom.parseString(xml_string) + # or xml.dom.minidom.parseString(xml_string) + xml = xml.dom.minidom.parseString( + et.tostring(element, encoding='utf8', method='xml')) print(xml.toprettyxml(), **kwargs) @@ -47,8 +48,6 @@ def response_label(content, count): response_label.append(material(content)) return response_label -def displayfeedback(gap=False): - pass def respcondition(points, respident, count, correct=True): root = et.Element('respcondition', attrib={'continue': 'Yes'}) @@ -83,6 +82,7 @@ def respcondition(points, respident, count, correct=True): root.append(displayfeedback) return root + def itemfeedback(ident, content='NONE'): root = et.Element( 'itemfeedback', @@ -94,6 +94,8 @@ def itemfeedback(ident, content='NONE'): return root ### gap specific ######################################################### + + def respcondition_gap(points, resp_count, answer, count=0): root = et.Element('respcondition', attrib={'continue': 'Yes'}) conditionvar = et.Element('conditionvar') @@ -129,12 +131,15 @@ def material_raw(content): )) return material + def response_str(ident, columns): - response_str = et.Element('response_str', attrib={'ident': ident, 'rcardinality': 'Single'}) - render_fib = et.Element('render_fib', attrib={'columns': str(columns), 'fibtype': "String", 'prompt': "Box"}) + response_str = et.Element( + 'response_str', attrib={'ident': ident, 'rcardinality': 'Single'}) + render_fib = et.Element('render_fib', attrib={'columns': str(columns), 'fibtype': "String", 'prompt': "Box"}) response_str.append(render_fib) return response_str + def response_choice(ident, answers): response_str = et.Element('response_str', attrib={'ident': str(ident), 'rcardinality': 'Single'}) render_choice = et.Element('render_choice', attrib={'shuffle': 'Yes'}) @@ -145,6 +150,7 @@ def response_choice(ident, answers): render_choice.append(response_label) return response_str + def response_num(ident, columns, _min, _max, numtype='Decimal'): response_num = et.Element('response_num', attrib={'ident': ident, 'numtype': numtype, 'rcardinality': 'Single'}) render_fib = et.Element('render_fib', attrib={'columns': str(columns), 'fibtype': numtype, 'maxnumber': _max, 'minnumber': _min, 'prompt': "Box"}) diff --git a/hallgrim/hallgrim.py b/hallgrim/hallgrim.py index a8b520d..35be647 100755 --- a/hallgrim/hallgrim.py +++ b/hallgrim/hallgrim.py @@ -20,7 +20,6 @@ import importlib.util import argparse import os -import sys import configparser # local import @@ -140,8 +139,9 @@ def parseme(): parser_gen = subparsers.add_parser( "upload", help="Subcommand to upload created xml instances.") parser_gen.add_argument( - 'script', - help='The script that should be uploaded', + 'script_list', + help='The scripts that should be uploaded', + nargs='+', type=file_exists, metavar='FILE') @@ -151,7 +151,7 @@ def parseme(): look_for_output() delegator(args.out, args.input, args.instances) if args.command == 'upload': - handle_upload(args.script, config) + handle_upload(args.script_list, config) if args.command == 'new': handle_new_script(args.name, args.type, args.author, args.points) if args.command == None: @@ -277,7 +277,7 @@ def handle_new_script(name, qtype, author, points): info('Generated new script "{}."'.format(new_script.name)) -def handle_upload(script_path, config): +def handle_upload(script_list, config): """ Passes data to the upload script. The status code should be 500, since ILIAS always replies with that error @@ -288,12 +288,13 @@ def handle_upload(script_path, config): script_path {str} -- path to the file that should be uploaded config {config object} -- the loaded configuration """ - r = send_script( - script_path, - config['UPLAODER']['host'], - config['UPLAODER']['user'], - config['UPLAODER']['pass'], - config['UPLAODER']['rtoken'], - ) - info("Uploaded %s. Status code looks %s." % - (script_path, "good" if r else "bad")) + for script in script_list: + r = send_script( + script, + config['UPLAODER']['host'], + config['UPLAODER']['user'], + config['UPLAODER']['pass'], + config['UPLAODER']['rtoken'], + ) + info("Uploaded %s. Status code looks %s." % + (script, "good" if r else "bad")) diff --git a/setup.py b/setup.py index 5c6e829..4c79eac 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- -from setuptools import setup, find_packages - +from setuptools import setup with open('README.md') as f: readme = f.read() -with open('LICENSE') as f: - license = f.read() - setup( name='hallgrim', version='0.1', @@ -17,7 +13,7 @@ setup( author='Jan Maximilian Michal', author_email='mail-github@jmx.io', url='https://gitlab.gwdg.de/j.michal/ilias-generator', - license=license, + license='MIT', scripts=['hallgrim/bin/hallgrim'], install_requires=['mistune', 'pygments', 'requests', 'requests_toolbelt'], packages=['hallgrim'] -- GitLab