diff options
author | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-08-14 22:47:35 +0200 |
---|---|---|
committer | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-08-14 22:51:49 +0200 |
commit | f1296adad2be6ead46cf380eeeb2f4c8684cc97a (patch) | |
tree | 3f13c0d6b34c39ecd04c48f0d9ac7717c5a2129c | |
parent | 4486c6d1a591ad08e47f1d14aa381fb1fe2037a4 (diff) | |
download | klausuren-f1296adad2be6ead46cf380eeeb2f4c8684cc97a.tar.gz klausuren-f1296adad2be6ead46cf380eeeb2f4c8684cc97a.tar.bz2 klausuren-f1296adad2be6ead46cf380eeeb2f4c8684cc97a.zip |
added README, requirements.txt and sample nginx config
-rw-r--r-- | README | 62 | ||||
-rw-r--r-- | app.py | 20 | ||||
-rw-r--r-- | nginx.cfg | 36 | ||||
-rw-r--r-- | requirements.txt | 8 | ||||
-rw-r--r-- | settings.py.sample | 4 |
5 files changed, 119 insertions, 11 deletions
@@ -0,0 +1,62 @@ +Fit +=== + +Fit ist das Klausurenarchiv von Spline an der Freien Universität Berlin. +Jegliche daten werden in einem Git-Repository (vom Typ 'bare') verwaltet. +Klausuren können über ein Webinterface einfach hoch- und heruntergezuladen +werden. Fit ist in Python2 mit Hilfe von Flask und pygit2 geschrieben. + + +Setup +------- + + $ git clone .../fit.git # Source-Code herunterladen + $ cd fit + $ cp settings.py.sample settings.py # Konfigurationsdatei erstellen + $ nano settings.py + $ pip install -r requirements.txt # Abhängikeiten installieren + $ export LD_LIBRARY_PATH=/usr/local/lib/ # libgit2.so zum LD Path hinzufügen + $ python app.py # Test-Server starten + + +Config +------ + +* MAX_CONTENT_LENGTH - Maximale Größe von Dateien beim Upload (in Bytes) +* DEBUG +* FORM_START_YEAR - Startjahr für Upload-Formular +* ALLOWD_EXTENSIONS - Erlaubte Dateien beim Upload +* STUDIES - Dictionary von Studiengängen. Die Liste von Tuples sind Basismodule + eines Studienganges. Sie werden bei der Modul-Auswahl beim + Upload-Formular immer angezeigt. + + +Nginx +----- + +Um das Klausurenarchiv hinter einem Nginx laufen zu lassen, sollte dieser +erstmal konfiguriert werden. Hierzu am besten die nginx.cfg benutzen und die +DOMAIN_URL, sowie INSTALL_PATH mit den korrekten Werten ersetzten. Danach kann +das Klausurenarchiv mit Hilfe von uwsgi gestartet werden: + + $ LD_LIBRARY_PATH=/usr/local/lib/ uwsgi -s /tmp/uwsgi.sock -w app:app & + $ chmod 777 /tmp/uwsgi.sock + +Damit die Zip- und Tar-Gz-Archive korrekt erstellt werden, sollten noch Cronjobs +für jeden Studiengang eingerichtet werden: + +$ cronjob -e +0 * * * * cd INSTALL_PATH/static/studies/informatik.git && /usr/bin/git archive -o ../informatik.zip HEAD + + +Munin +----- + +Für das Munin-Plugin sollte unter /etc/munin/plugins folgendes Skript hinterlegt +werden: + + #!/bin/bash + + cd INSTALL_PATH + LD_LIBRARY_PATH=/usr/local/lib/ python munin.py $1 + @@ -16,17 +16,17 @@ app.config.from_pyfile('settings.py') # populate Module-List fit = {} -for i, study in enumerate(app.config['MODULES'].items()): +for i, study in enumerate(app.config['STUDIES'].items()): abbr = study[0] fit[abbr] = Fit(os.path.join('static','studies',abbr + '.git')) - modules = app.config['MODULES'][study[0]] + modules = app.config['STUDIES'][study[0]] # extend module list with git values for module in fit[abbr].get_modules(): # check if module is already listed if all(map(lambda (k,v): v != module, modules)): slug = module.encode('ascii', errors='ignore') - app.config['MODULES'][study[0]].append((slug, module)) + app.config['STUDIES'][study[0]].append((slug, module)) class UploadForm(Form): """ Upload Form class for validation """ @@ -38,7 +38,9 @@ class UploadForm(Form): year = SelectField( 'Jahr', validators=[validators.Required()], - choices = [(str(x),x) for x in xrange(date.today().year, app.config['FORM_START_YEAR'], -1)] + choices = [ (str(x),x) for x in + xrange(date.today().year, app.config['FORM_START_YEAR']+1, -1) + ] ) def validate_exam(form, field): @@ -52,7 +54,7 @@ class UploadForm(Form): raise ValidationError(u'Zu große Datei') def validate_module(form, field): - modules = dict(app.config['MODULES'][form.study.data]) + modules = dict(app.config['STUDIES'][form.study.data]) data = form.module.data if data not in modules or data == '': raise ValidationError(u'Bitte wähle ein Modul!') @@ -65,7 +67,7 @@ def upload(study): form = UploadForm() form.study.data = study - form.module.choices = app.config['MODULES'][study] + form.module.choices = app.config['STUDIES'][study] if 'new' not in dict(form.module.choices): if len(form.module.choices) > 0: form.module.choices.append(('', u'---')) @@ -76,9 +78,9 @@ def upload(study): if form.module.data == 'new': module = form.module_new.data slug = module.encode('ascii', errors='ignore') - app.config['MODULES'][study].append((slug,module)) + app.config['STUDIES'][study].append((slug,module)) else: - module = dict(app.config['MODULES'][study])[form.module.data] + module = dict(app.config['STUDIES'][study])[form.module.data] year = form.year.data filename = secure_filename(form.exam.data.filename) @@ -121,7 +123,7 @@ def study_index(study, module=None): @app.route('/') def index(): get_img_path = lambda x: os.path.join('images', x +'.png') - studies = [(name,get_img_path(name)) for name,m in app.config['MODULES'].items()] + studies = [(name,get_img_path(name)) for name,m in app.config['STUDIES'].items()] return render_template( 'index.html', diff --git a/nginx.cfg b/nginx.cfg new file mode 100644 index 0000000..d2c98b9 --- /dev/null +++ b/nginx.cfg @@ -0,0 +1,36 @@ +server { + listen 80; + server_name DOMAIN_URL; + + client_max_body_size 10m; + + location /static { + root INSTALL_PATH; + } + + location /static/studies/ { + error_page 403 http://DOMAIN_URL/403; + root INSTALL_PATH; + + #allow 192.168.0.0/16; + #deny all; + } + + location /403 { + try_files $uri @fit; + } + + location / { + error_page 403 http://DOMAIN_URL/403; + + #allow 192.168.0.0/16; + #deny all; + + try_files $uri @fit; + } + + location @fit { + include uwsgi_params; + uwsgi_pass unix:/tmp/uwsgi.sock; + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7906cc2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +Flask==0.9 +Flask-WTF==0.8 +Jinja2==2.6 +WTForms==1.0.1 +Werkzeug==0.8.3 +pygit2==0.17.2 +python-magic==0.4.2 +wsgiref==0.1.2 diff --git a/settings.py.sample b/settings.py.sample index 0d54a70..212c524 100644 --- a/settings.py.sample +++ b/settings.py.sample @@ -5,10 +5,10 @@ SECRET_KEY = 'secret_key_to_fill_in' MAX_CONTENT_LENGTH = 10 * 1024 * 1024 DEBUG = False -FORM_START_YEAR = 1999 +FORM_START_YEAR = 2000 ALLOWED_EXTENSIONS = ['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'zip', 'gs', 'gz' ] -MODULES = { +STUDIES = { 'informatik' : [ ('alp1', u'ALP1 - Funktionale Programmierung'), ] |