diff options
| author | jc0b <j.burley@vu.nl> | 2020-06-09 14:20:36 +0200 |
|---|---|---|
| committer | jc0b <j.burley@vu.nl> | 2020-06-09 14:42:56 +0200 |
| commit | 6e6ba6fff737f9dd4baf03c72b9f2e7efd89b3d0 (patch) | |
| tree | 5bbe4e401f0ed25319e6e2fa8e9aa5e673d5fc1b /opendc | |
| parent | d49328f321362bb410775e9c520a6f0024489416 (diff) | |
python3 progress
Diffstat (limited to 'opendc')
| -rw-r--r-- | opendc/models/model.py | 2 | ||||
| -rw-r--r-- | opendc/util/database.py | 30 |
2 files changed, 27 insertions, 5 deletions
diff --git a/opendc/models/model.py b/opendc/models/model.py index 44e4faf8..8ab410d4 100644 --- a/opendc/models/model.py +++ b/opendc/models/model.py @@ -291,7 +291,7 @@ class Model(object): try: last_row_id = database.execute(statement, values) except Exception as e: - print e + print(e) raise exceptions.ForeignKeyError(e.message) if 'id' in self.COLUMNS_PRIMARY_KEY: diff --git a/opendc/util/database.py b/opendc/util/database.py index ebb62bde..7ae7b82b 100644 --- a/opendc/util/database.py +++ b/opendc/util/database.py @@ -1,8 +1,12 @@ import json import sys + from datetime import datetime +from pymongo import MongoClient +from bson.json_util import loads, dumps, RELAXED_JSON_OPTIONS, CANONICAL_JSON_OPTIONS + -from mysql.connector.pooling import MySQLConnectionPool +#from mysql.connector.pooling import MySQLConnectionPool # Get keys from config file with open(sys.argv[1]) as f: @@ -13,9 +17,27 @@ CONNECTION_POOL = None def init_connection_pool(user, password, database, host, port): - global CONNECTION_POOL - CONNECTION_POOL = MySQLConnectionPool(pool_name="opendcpool", pool_size=5, - user=user, password=password, database=database, host=host, port=port) + user = urllib.parse.quote_plus(user) #TODO: replace this with environment variable + password = urllib.parse.quote_plus(password) #TODO: same as above + database = urllib.parse.quote_plus(database) + host = urllib.parse.quote_plus(host) + + global client + global opendcdb + global prefabs_collection + global user_collection + global topologies_collection + + client = MongoClient('mongodb://%s:%s@%s/default_db?authSource=%s' % (user, password, host, database)) + opendcdb = client.opendc + prefabs_collection = opendcdb.prefabs + topologies_collection = opendcdb.topologies + user_collection = opendcdb.users + + + #global CONNECTION_POOL + #CONNECTION_POOL = MySQLConnectionPool(pool_name="opendcpool", pool_size=5, + #user=user, password=password, database=database, host=host, port=port) def execute(statement, t): |
