diff --git a/.gitignore b/.gitignore index 1b2e91b5e3c1aec6f2daf0f3df69ebc163352390..7bd1165a32fb31075471368e925f415581b1d296 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ notes.html README.html .DS_Store *.sublime-workspace +config.ini diff --git a/README.md b/README.md index f27e52ddde2d1fca78daadbdf2ef416e3f841f2b..fa1d614cdc7e2b4d8e9503e5f1e0917e35d171c0 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ implemented. - `pip install mistune` - `pip install pygments` +- `pip install requests` +- `pip install requests_toolbelt` ### TODO @@ -57,32 +59,28 @@ Hallgrim uses pygments and the customized mistune parser to highlight different programming language syntaxes. To highlight a code block just put the language name right after the delimiters -```` -```java -class Car { - private float price; - private String manufacturer; - public void cheeseCake(int withCream) { - return () -> (); + ```java + class Car { + private float price; + private String manufacturer; + public void cheeseCake(int withCream) { + return () -> (); + } } -} -``` -```` + ``` It is not possible to copy code by default, but `_copy` can be appended to the language's name if copyable code is desired. -```` -```java_copy -class Car { - private float price; - private String manufacturer; - public void cheeseCake(int withCream) { - return () -> (); + ```java_copy + class Car { + private float price; + private String manufacturer; + public void cheeseCake(int withCream) { + return () -> (); + } } -} -``` -```` + ``` It is possible to include gaps withing code blocks. diff --git a/config.ini b/config.sample.ini similarity index 79% rename from config.ini rename to config.sample.ini index b15f3dedfc99572c2ba896d032554808a78a96f9..cfe9d5401aa5ad856a600c28388889c1df047167 100644 --- a/config.ini +++ b/config.sample.ini @@ -1,5 +1,5 @@ [META] -author = Jan Maximilian Michal +author = your name [UPLAODER] diff --git a/grim.py b/grim.py index 25c063d2625194e61b62a119bd9fe28d011245e2..516c26160bbd02903270e697d26baed11b86f421 100755 --- a/grim.py +++ b/grim.py @@ -34,9 +34,13 @@ from hallgrim.uploader import send_script def get_config(): config = configparser.ConfigParser() config.read('config.ini') + if not config.sections(): + error('Could not find config file.') + error('Please edit config.sample.ini and move it to config.ini') + error('Continue with default values. Script might fail.') + config.read('config.sample.ini') return config - def file_to_module(name): return name.rstrip('.py').replace('/', '.') @@ -66,6 +70,7 @@ def script_is_valid(script, required): def parseme(): + config = get_config() parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest="command") @@ -87,6 +92,7 @@ def parseme(): "-a", "--author", help="Name of the scripts author", + default=config['META']['author'], metavar='AUTHOR' ) parser_new.add_argument( @@ -133,7 +139,7 @@ def parseme(): if args.command == 'gen': delegator(args.out, args.input, args.instances) if args.command == 'upload': - handle_upload(args.script, args.host) + handle_upload(args.script, config) if args.command == 'new': handle_new_script(args.name, args.type, args.author, args.points) if args.command == None: @@ -233,8 +239,6 @@ def handle_new_script(name, qtype, author, points): Takes in some meta information from the command line of if not present takes it from the config.ini or uses default values. - TODO: put the configuration before the parser and use as default values - Arguments: name {str} -- name of the script, will also become filename qtype {str} -- question type (choice, gap, alignment) @@ -242,10 +246,6 @@ def handle_new_script(name, qtype, author, points): points {float} -- number of points for the task """ from hallgrim.templates import scaffolding - config = get_config() - - if not author: - author = config['META']['author'] with open('scripts/' + name + '.py', 'w') as new_script: choice = '' @@ -257,7 +257,7 @@ def handle_new_script(name, qtype, author, points): info('Generated new script "{}."'.format(new_script.name)) -def handle_upload(script_path): +def handle_upload(script_path, config): """ Passes data to the upload script. The status code should be 500, since ILIAS always replies with that error @@ -266,8 +266,8 @@ def handle_upload(script_path): Arguments: script_path {str} -- path to the file that should be uploaded + config {config object} -- the loaded configuration """ - config = get_config() r = send_script( script_path, config['UPLAODER']['host'],