summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-08-16 13:48:28 +0200
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-08-16 13:48:28 +0200
commit170264047e2f313e8c1395bdc8b5a08bbe21b1bf (patch)
tree106ef81ce7b764326933e4bb73e85ddd4ce9778b
parent4ce5efbe6fe4373b80b206c2dda5881e15e50cfe (diff)
downloadklausuren-170264047e2f313e8c1395bdc8b5a08bbe21b1bf.tar.gz
klausuren-170264047e2f313e8c1395bdc8b5a08bbe21b1bf.tar.bz2
klausuren-170264047e2f313e8c1395bdc8b5a08bbe21b1bf.zip
force defaultencoding to be utf8
-rw-r--r--app.py10
-rw-r--r--fit.py36
2 files changed, 11 insertions, 35 deletions
diff --git a/app.py b/app.py
index 304b843..9e38105 100644
--- a/app.py
+++ b/app.py
@@ -1,7 +1,7 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
-import magic, os
+import magic, os, sys
from fit import Fit
from flask import Flask, render_template, request, flash, redirect, url_for
@@ -11,6 +11,10 @@ from werkzeug import secure_filename
from datetime import date
+# set default encoding to utf-8, otherwise pygit2 can not handle umlauts
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
app = Flask(__name__)
app.config.from_pyfile('settings.py')
@@ -25,7 +29,7 @@ for i, study in enumerate(app.config['STUDIES'].items()):
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')
+ slug = module.decode('ascii', errors='ignore')
app.config['STUDIES'][study[0]].append((slug, module))
class UploadForm(Form):
@@ -85,7 +89,7 @@ def upload(study, module = None):
year = form.year.data
filename = secure_filename(form.exam.data.filename)
- path = os.path.join(module,year,filename).encode('ascii', errors='ignore')
+ path = os.path.join(module,year,filename)
try:
oid = fit[study].add_file(form.exam.data.stream.getvalue(), path)
diff --git a/fit.py b/fit.py
index c81fb06..9c9ccae 100644
--- a/fit.py
+++ b/fit.py
@@ -1,3 +1,6 @@
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+
import os, time
import collections
@@ -75,7 +78,7 @@ class Fit:
existing_builders = [(os.sep, root)]
for dir_entry in dir_path:
try:
- new_oid = current_node[str(dir_entry)].oid
+ new_oid = current_node[dir_entry].oid
current_node = self.repo[new_oid]
existing_builders.append((
@@ -137,34 +140,3 @@ class Fit:
except:
return []
-
-
-#fit = Fit('static/fit.git')
-#fit.add_file('main.c', 'alp3/2007/main.c')
-#fit.add_file('main.c', 'alp3/2008/main.c')
-#fit.add_file('main.c', 'alp3/2009/main.c')
-#
-#print('All modules')
-#for name in fit.get_modules():
-# print('\t' + name)
-#
-#print('Module: alp4')
-#for (year,items) in fit.get_module('alp4'):
-# print('\t' + year)
-# for name in items:
-# print('\t\t' + name)
-#
-#for name, oid in fit.list('tags/aws'):
-# print(name)
-#
-#print("All files")
-#for name, oid in fit.list_directories():
-# print(name)
- #tags = ','.join(map(lambda x: x[0], fit.get_file_with_tags(oid)))
- #print("* %s (%s)" % (name, tags))
- #print(fit.get_file(oid) + "\n")
-#
-#print("\nAll tags")
-#for name, oid in fit.get_all_tags():
-# files = ','.join(map(lambda x: x[0], fit.get_files_for_tags([name])))
-# print("* %s (%s)" % (name, files))