From 6e6ba6fff737f9dd4baf03c72b9f2e7efd89b3d0 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 9 Jun 2020 14:20:36 +0200 Subject: python3 progress --- opendc/models/model.py | 2 +- opendc/util/database.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'opendc') 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): -- cgit v1.2.3