databaseconnection
This commit is contained in:
@@ -6,6 +6,7 @@ from PySide6.QtCore import QObject, Slot
|
||||
from .Vermasseln import Vermasseln
|
||||
import shutil
|
||||
from urllib.parse import urlparse
|
||||
import os
|
||||
|
||||
class ConfigLoader(QObject):
|
||||
__config = None
|
||||
@@ -22,12 +23,13 @@ class ConfigLoader(QObject):
|
||||
|
||||
@Slot(str, str)
|
||||
def importConfig(self, confile, password):
|
||||
print(password)
|
||||
|
||||
confile = urlparse(confile)
|
||||
print(confile.path)
|
||||
#confile= confile.replace('file://','')
|
||||
shutil.copyfile(confile.path, self.config_dir+ '/pyqcrm.toml')
|
||||
confile = confile.path
|
||||
|
||||
if os.name == "nt":
|
||||
confile = confile[1:]
|
||||
shutil.copyfile(confile, self.config_dir+ '/pyqcrm.toml')
|
||||
|
||||
@Slot(dict)
|
||||
def setConfig(self, app_config):
|
||||
@@ -50,7 +52,7 @@ class ConfigLoader(QObject):
|
||||
|
||||
|
||||
def getConfig(self):
|
||||
|
||||
print(self.__config['database'])
|
||||
return self.__config
|
||||
|
||||
def createConfig(self):
|
||||
|
||||
22
lib/DB/DbManager.py
Normal file
22
lib/DB/DbManager.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import toml
|
||||
import mysql.connector
|
||||
|
||||
|
||||
class DbManager(object):
|
||||
__connection = None
|
||||
__con_param = None
|
||||
def __new__ (cls):
|
||||
if not hasattr(cls, "__instance"):
|
||||
cls.__instance = super().__new__(cls)
|
||||
return cls.__instance
|
||||
|
||||
def __init__ (self, dbconf):
|
||||
__con_param = __initializeConfig(dbconf)
|
||||
self.__connection = mysql.connector.connect(__con_param)
|
||||
return self.__connection
|
||||
|
||||
def __initializeConfig(self, dbconf):
|
||||
__con_param = {'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'], 'port': dbconf['DB_PORT'], 'host': dbconf['DB_HOST'], 'name': dbconf['DB_NAME']}
|
||||
return __con_param
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from .ConfigLoader import ConfigLoader
|
||||
from .BusinessModel import BusinessModel
|
||||
from .DB.BusinessModel import BusinessModel
|
||||
|
||||
Reference in New Issue
Block a user