Adding MYSQL support
This commit is contained in:
parent
2560c34257
commit
cf5d7495f0
5 changed files with 23 additions and 6 deletions
|
@ -11,6 +11,7 @@ nose==1.3.7
|
||||||
pbr==2.0.0
|
pbr==2.0.0
|
||||||
pycodestyle==2.3.1
|
pycodestyle==2.3.1
|
||||||
pyflakes==1.5.0
|
pyflakes==1.5.0
|
||||||
|
PyMySQL==0.7.11
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
SQLAlchemy==1.1.9
|
SQLAlchemy==1.1.9
|
||||||
visitor==0.1.3
|
visitor==0.1.3
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -27,7 +27,8 @@ setup(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'flask',
|
'flask',
|
||||||
'flask-bootstrap',
|
'flask-bootstrap',
|
||||||
'flask-sqlalchemy'
|
'flask-sqlalchemy',
|
||||||
|
'pymysql'
|
||||||
],
|
],
|
||||||
author="Denis Nutiu",
|
author="Denis Nutiu",
|
||||||
author_email="denis.nutiu@gmail.com",
|
author_email="denis.nutiu@gmail.com",
|
||||||
|
|
|
@ -19,6 +19,7 @@ from src.models import db
|
||||||
from src.views.errors import error_pages
|
from src.views.errors import error_pages
|
||||||
from src.views.scoreboard import scoreboard
|
from src.views.scoreboard import scoreboard
|
||||||
from src.config import config
|
from src.config import config
|
||||||
|
import sys
|
||||||
import flask_bootstrap
|
import flask_bootstrap
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
@ -35,7 +36,10 @@ def create_app(config_name):
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
try:
|
||||||
|
app = create_app(sys.argv[1])
|
||||||
|
except (IndexError, KeyError):
|
||||||
|
print("Using default configuration.")
|
||||||
app = create_app('default')
|
app = create_app('default')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,18 @@ class DevelopmentConfig(Config):
|
||||||
|
|
||||||
class ProductionConfig(Config):
|
class ProductionConfig(Config):
|
||||||
BOOTSTRAP_USE_MINIFIED = True
|
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):
|
class TestingConfig(Config):
|
||||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'test_database.sqlite')
|
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'test_database.sqlite')
|
||||||
|
|
|
@ -39,9 +39,9 @@ def upload():
|
||||||
content = flask.request.get_json()
|
content = flask.request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gpu = flask.escape(content['gpu'])
|
gpu = content['gpu']
|
||||||
cpu = flask.escape(content['cpu'])
|
cpu = content['cpu']
|
||||||
log = flask.escape(content['log'])
|
log = content['log']
|
||||||
score = int(content['score'])
|
score = int(content['score'])
|
||||||
except KeyError: # Json doesn't contain the keys we need.
|
except KeyError: # Json doesn't contain the keys we need.
|
||||||
error = "invalid json keys: gpu, cpu, log, score"
|
error = "invalid json keys: gpu, cpu, log, score"
|
||||||
|
|
Loading…
Reference in a new issue