Add ability to specify table to SQL config
This commit is contained in:
parent
279185b0a2
commit
ca054d5cd6
@ -114,6 +114,7 @@ PASS: mypassword
|
|||||||
DB: hblink
|
DB: hblink
|
||||||
SERVER: 127.0.0.1
|
SERVER: 127.0.0.1
|
||||||
PORT: 3306
|
PORT: 3306
|
||||||
|
TABLE: repeaters
|
||||||
|
|
||||||
# OPENBRIDGE INSTANCES - DUPLICATE SECTION FOR MULTIPLE CONNECTIONS
|
# OPENBRIDGE INSTANCES - DUPLICATE SECTION FOR MULTIPLE CONNECTIONS
|
||||||
# OpenBridge is a protocol originall created by DMR+ for connection between an
|
# OpenBridge is a protocol originall created by DMR+ for connection between an
|
||||||
|
@ -1771,7 +1771,7 @@ if __name__ == '__main__':
|
|||||||
if CONFIG['MYSQL']['USE_MYSQL'] == True:
|
if CONFIG['MYSQL']['USE_MYSQL'] == True:
|
||||||
logger.debug('(MYSQL) MySQL config enabled')
|
logger.debug('(MYSQL) MySQL config enabled')
|
||||||
SQLCONFIG = {}
|
SQLCONFIG = {}
|
||||||
sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],logger)
|
sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger)
|
||||||
#Run it once immediately
|
#Run it once immediately
|
||||||
if sql.con():
|
if sql.con():
|
||||||
logger.debug('(MYSQL) reading config from database')
|
logger.debug('(MYSQL) reading config from database')
|
||||||
|
@ -162,7 +162,8 @@ def build_config(_config_file):
|
|||||||
'PASS': config.get(section, 'PASS'),
|
'PASS': config.get(section, 'PASS'),
|
||||||
'DB': config.get(section, 'DB'),
|
'DB': config.get(section, 'DB'),
|
||||||
'SERVER': config.get(section, 'SERVER'),
|
'SERVER': config.get(section, 'SERVER'),
|
||||||
'PORT': config.getint(section,'PORT')
|
'PORT': config.getint(section,'PORT'),
|
||||||
|
'TABLE': config.get(section, 'TABLE')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,11 +4,12 @@ from mysql.connector import errorcode
|
|||||||
|
|
||||||
class useMYSQL:
|
class useMYSQL:
|
||||||
#Init new object
|
#Init new object
|
||||||
def __init__(self, server,user,password,database,logger):
|
def __init__(self, server,user,password,database,table,logger):
|
||||||
self.server = server
|
self.server = server
|
||||||
self.user = user
|
self.user = user
|
||||||
self.password = password
|
self.password = password
|
||||||
self.database = database
|
self.database = database
|
||||||
|
self.table = table
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
|
||||||
#Connect
|
#Connect
|
||||||
@ -49,7 +50,7 @@ class useMYSQL:
|
|||||||
_cursor = self.db.cursor()
|
_cursor = self.db.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_cursor.execute("select * from repeaters where MODE='MASTER'")
|
_cursor.execute("select * from {} where MODE='MASTER'".format(self.table))
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
_cursor.close()
|
_cursor.close()
|
||||||
logger.info('(MYSQL) error, problem with cursor execute')
|
logger.info('(MYSQL) error, problem with cursor execute')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user