From f90deb15fa2551eb8592693b3426bd466c06be96 Mon Sep 17 00:00:00 2001
From: Jan Maximilian Michal <j.michal@stud.uni-goettingen.de>
Date: Mon, 12 Dec 2016 16:03:32 +0000
Subject: [PATCH] moved config out of repo and provided sample config instead

---
 .gitignore                      |  1 +
 README.md                       | 38 ++++++++++++++++-----------------
 config.ini => config.sample.ini |  2 +-
 grim.py                         | 20 ++++++++---------
 4 files changed, 30 insertions(+), 31 deletions(-)
 rename config.ini => config.sample.ini (79%)

diff --git a/.gitignore b/.gitignore
index 1b2e91b..7bd1165 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 f27e52d..fa1d614 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 b15f3de..cfe9d54 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 25c063d..516c261 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'],
-- 
GitLab