From cf5d7495f01d4eaca0ff3e2e7ab27cadcf1f759d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Mon, 17 Apr 2017 02:18:18 +0300 Subject: [PATCH] Adding MYSQL support --- requirements.txt | 1 + setup.py | 3 ++- src/application.py | 8 ++++++-- src/config.lock.py | 11 +++++++++++ src/views/scoreboard.py | 6 +++--- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4bd412f..054b5c8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ nose==1.3.7 pbr==2.0.0 pycodestyle==2.3.1 pyflakes==1.5.0 +PyMySQL==0.7.11 six==1.10.0 SQLAlchemy==1.1.9 visitor==0.1.3 diff --git a/setup.py b/setup.py index 538ae15..95e9314 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,8 @@ setup( install_requires=[ 'flask', 'flask-bootstrap', - 'flask-sqlalchemy' + 'flask-sqlalchemy', + 'pymysql' ], author="Denis Nutiu", author_email="denis.nutiu@gmail.com", diff --git a/src/application.py b/src/application.py index 48be18c..a349766 100644 --- a/src/application.py +++ b/src/application.py @@ -19,6 +19,7 @@ from src.models import db from src.views.errors import error_pages from src.views.scoreboard import scoreboard from src.config import config +import sys import flask_bootstrap import flask @@ -35,8 +36,11 @@ def create_app(config_name): return app - -app = create_app('default') +try: + app = create_app(sys.argv[1]) +except (IndexError, KeyError): + print("Using default configuration.") + app = create_app('default') if __name__ == "__main__": diff --git a/src/config.lock.py b/src/config.lock.py index 968ca53..09dfce6 100644 --- a/src/config.lock.py +++ b/src/config.lock.py @@ -40,7 +40,18 @@ class DevelopmentConfig(Config): class ProductionConfig(Config): BOOTSTRAP_USE_MINIFIED = True + MYSQL_USERNAME = "" + MYSQL_PASSWORD = "" + MYSQL_HOSTNAME = "" + MYSQL_DATABASE = "" + SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{username}:{password}@{hostname}/{database}'\ + .format(username = MYSQL_USERNAME, password = MYSQL_PASSWORD, + hostname = MYSQL_HOSTNAME, database = MYSQL_DATABASE) + @staticmethod + def init_app(app): + with app.app_context(): + db.create_all() class TestingConfig(Config): SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'test_database.sqlite') diff --git a/src/views/scoreboard.py b/src/views/scoreboard.py index 9e6f622..1147b87 100644 --- a/src/views/scoreboard.py +++ b/src/views/scoreboard.py @@ -39,9 +39,9 @@ def upload(): content = flask.request.get_json() try: - gpu = flask.escape(content['gpu']) - cpu = flask.escape(content['cpu']) - log = flask.escape(content['log']) + gpu = content['gpu'] + cpu = content['cpu'] + log = content['log'] score = int(content['score']) except KeyError: # Json doesn't contain the keys we need. error = "invalid json keys: gpu, cpu, log, score"