2018-12-13 Fred Gleason <fredg@paravelsystems.com>

* Added support in 'PyPAD.Receiver::setConfigFile()' to load
	configuration information from a Rivendell database.
This commit is contained in:
Fred Gleason
2018-12-14 17:37:06 -05:00
parent dfa8ed93b2
commit 7a04111228
2 changed files with 35 additions and 4 deletions

View File

@@ -18197,3 +18197,6 @@
in rdadmin(1).
* Added a 'ListPyPAD Instances' dialog in rdadmin(1).
* Added an 'Edit PyPAD' Instance' dialog in rdadmin(1).
2018-12-13 Fred Gleason <fredg@paravelsystems.com>
* Added support in 'PyPAD.Receiver::setConfigFile()' to load
configuration information from a Rivendell database.

View File

@@ -20,6 +20,7 @@
import configparser
import datetime
import MySQLdb
import socket
import json
@@ -715,6 +716,16 @@ class Receiver(object):
def __PyPAD_Process(self,pad):
self.__callback(pad)
def __getDbCredentials(self):
config=configparser.ConfigParser()
config.readfp(open('/etc/rd.conf'))
return (config.get('mySQL','Loginname'),config.get('mySQL','Password'),
config.get('mySQL','Hostname'),config.get('mySQL','Database'))
def __openDb(self):
creds=self.__getDbCredentials()
return MySQLdb.connect(creds[2],creds[0],creds[1],creds[3])
def setCallback(self,cb):
"""
Set the processing callback.
@@ -727,11 +738,28 @@ class Receiver(object):
the 'PyPAD.Update::config()' method will return a parserconfig
object created from the specified file. The file must be in INI
format.
A special case is if the supplied filename string begins with
the '$' character. If so, the remainder of the string is assumed
to be an unsigned integer ID that is used to retrieve the
configuration from the 'PYPAD_INSTANCES' table in the database
pointed to by '/etc/rd.conf'.
"""
fp=open(filename)
self.__config_parser=configparser.ConfigParser(interpolation=None)
self.__config_parser.readfp(fp)
fp.close()
if filename[0]=='$': # Get the config from the DB
db=self.__openDb()
cursor=db.cursor()
cursor.execute('select CONFIG from PYPAD_INSTANCES where ID='+
filename[1::])
config=cursor.fetchone()
self.__config_parser=configparser.ConfigParser(interpolation=None)
self.__config_parser.read_string(config[0])
db.close()
else: # Get the config from a file
fp=open(filename)
self.__config_parser=configparser.ConfigParser(interpolation=None)
self.__config_parser.readfp(fp)
fp.close()
def start(self,hostname,port):
"""