mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2026-01-14 00:25:53 +01:00
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:
@@ -18197,3 +18197,6 @@
|
|||||||
in rdadmin(1).
|
in rdadmin(1).
|
||||||
* Added a 'ListPyPAD Instances' dialog in rdadmin(1).
|
* Added a 'ListPyPAD Instances' dialog in rdadmin(1).
|
||||||
* Added an 'Edit PyPAD' Instance' 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.
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import datetime
|
import datetime
|
||||||
|
import MySQLdb
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -715,6 +716,16 @@ class Receiver(object):
|
|||||||
def __PyPAD_Process(self,pad):
|
def __PyPAD_Process(self,pad):
|
||||||
self.__callback(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):
|
def setCallback(self,cb):
|
||||||
"""
|
"""
|
||||||
Set the processing callback.
|
Set the processing callback.
|
||||||
@@ -727,7 +738,24 @@ class Receiver(object):
|
|||||||
the 'PyPAD.Update::config()' method will return a parserconfig
|
the 'PyPAD.Update::config()' method will return a parserconfig
|
||||||
object created from the specified file. The file must be in INI
|
object created from the specified file. The file must be in INI
|
||||||
format.
|
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'.
|
||||||
"""
|
"""
|
||||||
|
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)
|
fp=open(filename)
|
||||||
self.__config_parser=configparser.ConfigParser(interpolation=None)
|
self.__config_parser=configparser.ConfigParser(interpolation=None)
|
||||||
self.__config_parser.readfp(fp)
|
self.__config_parser.readfp(fp)
|
||||||
|
|||||||
Reference in New Issue
Block a user