2019-08-11 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in the 'pypad.update.shouldBeProcessed()' method
	that caused log selection directives to be ignored.
	* Refactored the 'pypad_icecast2.py' script to work properly with
	the fixed 'pypad.update.shouldBeProcessed()' method.
	* Refactored the 'pypad_shoutcast2.py' script to work properly with
	the fixed 'pypad.update.shouldBeProcessed()' method.
This commit is contained in:
Fred Gleason
2019-08-11 17:44:44 -04:00
parent 987090c46f
commit 56feb08896
4 changed files with 63 additions and 33 deletions

View File

@@ -18918,3 +18918,10 @@
2019-08-09 Fred Gleason <fredg@paravelsystems.com> 2019-08-09 Fred Gleason <fredg@paravelsystems.com>
* Refactored 'RDClock' to store events on the heap rather than * Refactored 'RDClock' to store events on the heap rather than
on the stack. on the stack.
2019-08-11 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in the 'pypad.update.shouldBeProcessed()' method
that caused log selection directives to be ignored.
* Refactored the 'pypad_icecast2.py' script to work properly with
the fixed 'pypad.update.shouldBeProcessed()' method.
* Refactored the 'pypad_shoutcast2.py' script to work properly with
the fixed 'pypad.update.shouldBeProcessed()' method.

View File

@@ -84,7 +84,6 @@ PAD_TCP_PORT=34289
class Update(object): class Update(object):
def __init__(self,pad_data,config,rd_config): def __init__(self,pad_data,config,rd_config):
self.__fields=pad_data self.__fields=pad_data
#print('PAD: '+str(self.__fields))
self.__config=config self.__config=config
self.__rd_config=rd_config self.__rd_config=rd_config
@@ -726,17 +725,20 @@ class Update(object):
section - The '[<section>]' of the INI configuration from which section - The '[<section>]' of the INI configuration from which
to take the parameters. to take the parameters.
""" """
result=True
try: try:
if self.__config.get(section,'ProcessNullUpdates')=='0': if self.__config.get(section,'ProcessNullUpdates')=='0':
return True result=result and True
if self.__config.get(section,'ProcessNullUpdates')=='1': if self.__config.get(section,'ProcessNullUpdates')=='1':
return self.hasPadType(pypad.TYPE_NOW) result=result and self.hasPadType(pypad.TYPE_NOW)
if self.__config.get(section,'ProcessNullUpdates')=='2': if self.__config.get(section,'ProcessNullUpdates')=='2':
return self.hasPadType(pypad.TYPE_NEXT) result=result and self.hasPadType(pypad.TYPE_NEXT)
if self.__config.get(section,'ProcessNullUpdates')=='3': if self.__config.get(section,'ProcessNullUpdates')=='3':
return self.hasPadType(pypad.TYPE_NOW) and self.hasPadType(pypad.TYPE_NEXT) result=result and self.hasPadType(pypad.TYPE_NOW) and self.hasPadType(pypad.TYPE_NEXT)
except configparser.NoOptionError: except configparser.NoOptionError:
return True result=result and True
except configparser.NoSectionError:
result=result and True
log_dict={1: 'MasterLog',2: 'Aux1Log',3: 'Aux2Log', log_dict={1: 'MasterLog',2: 'Aux1Log',3: 'Aux2Log',
101: 'VLog101',102: 'VLog102',103: 'VLog103',104: 'VLog104', 101: 'VLog101',102: 'VLog102',103: 'VLog103',104: 'VLog104',
@@ -744,12 +746,21 @@ class Update(object):
109: 'VLog109',110: 'VLog110',111: 'VLog111',112: 'VLog112', 109: 'VLog109',110: 'VLog110',111: 'VLog111',112: 'VLog112',
113: 'VLog113',114: 'VLog114',115: 'VLog115',116: 'VLog116', 113: 'VLog113',114: 'VLog114',115: 'VLog115',116: 'VLog116',
117: 'VLog117',118: 'VLog118',119: 'VLog119',120: 'VLog120'} 117: 'VLog117',118: 'VLog118',119: 'VLog119',120: 'VLog120'}
try:
#print('machine(): '+str(self.machine()))
if self.__config.get(section,log_dict[self.machine()]).lower()=='yes': if self.__config.get(section,log_dict[self.machine()]).lower()=='yes':
return True result=result and True
if self.__config.get(section,log_dict[self.machine()]).lower()=='no': if self.__config.get(section,log_dict[self.machine()]).lower()=='no':
return False result=result and False
if self.__config.get(section,log_dict[self.machine()]).lower()=='onair': if self.__config.get(section,log_dict[self.machine()]).lower()=='onair':
return self.onairFlag() result=result and self.onairFlag()
except configparser.NoOptionError:
result=result and False
except configparser.NoSectionError:
result=result and False
#print('result: '+str(result))
return result
def syslog(self,priority,msg): def syslog(self,priority,msg):
""" """

View File

@@ -34,25 +34,37 @@ def ProcessPad(update):
if update.hasPadType(pypad.TYPE_NOW): if update.hasPadType(pypad.TYPE_NOW):
n=1 n=1
while(True): while(True):
#
# First, get all of our configuration values
#
section='Icecast'+str(n) section='Icecast'+str(n)
try: try:
values={} values={}
values['mount']=update.config().get(section,'Mountpoint') values['mount']=update.config().get(section,'Mountpoint')
values['song']=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE) values['song']=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE)
values['mode']='updinfo' values['mode']='updinfo'
update.syslog(syslog.LOG_INFO,'Updating '+update.config().get(section,'Hostname')+': song='+values['song']) hostname=update.config().get(section,'Hostname')
url="http://%s:%s/admin/metadata" % (update.config().get(section,'Hostname'),update.config().get(section,'Tcpport')) tcpport=update.config().get(section,'Tcpport')
try: username=update.config().get(section,'Username')
response=requests.get(url,auth=HTTPBasicAuth(update.config().get(section,'Username'),update.config().get(section,'Password')),params=values) password=update.config().get(section,'Password')
response.raise_for_status() url="http://%s:%s/admin/metadata" % (hostname,tcpport)
except requests.exceptions.RequestException as e:
update.syslog(syslog.LOG_WARNING,str(e))
n=n+1
except configparser.NoSectionError: except configparser.NoSectionError:
if(n==1): if(n==1):
update.syslog(syslog.LOG_WARNING,'No icecast config found') update.syslog(syslog.LOG_WARNING,'No icecast config found')
return return
#
# Now, send the update
#
if update.shouldBeProcessed(section):
try:
response=requests.get(url,auth=HTTPBasicAuth(username,password),params=values)
response.raise_for_status()
update.syslog(syslog.LOG_INFO,'Updating '+hostname+': song='+values['song'])
except requests.exceptions.RequestException as e:
update.syslog(syslog.LOG_WARNING,str(e))
n=n+1
# #
# Program Name # Program Name
# #

View File

@@ -27,23 +27,18 @@ import pycurl
import pypad import pypad
from io import BytesIO from io import BytesIO
last_updates={}
def eprint(*args,**kwargs): def eprint(*args,**kwargs):
print(*args,file=sys.stderr,**kwargs) print(*args,file=sys.stderr,**kwargs)
def ProcessPad(update): def ProcessPad(update):
try: if update.hasPadType(pypad.TYPE_NOW):
last_updates[update.machine()]
except KeyError:
last_updates[update.machine()]=None
n=1 n=1
try:
while(True): while(True):
#
# First, get all of our configuration values
#
section='Shoutcast'+str(n) section='Shoutcast'+str(n)
if update.shouldBeProcessed(section) and update.hasPadType(pypad.TYPE_NOW) and (last_updates[update.machine()] != update.startDateTimeString(pypad.TYPE_NOW)): try:
last_updates[update.machine()]=update.startDateTimeString(pypad.TYPE_NOW)
song=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_URL) song=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_URL)
url='http://'+update.config().get(section,'Hostname')+':'+str(update.config().get(section,'Tcpport'))+'/admin.cgi?pass='+update.escape(update.config().get(section,'Password'),pypad.ESCAPE_URL)+'&mode=updinfo&song='+song url='http://'+update.config().get(section,'Hostname')+':'+str(update.config().get(section,'Tcpport'))+'/admin.cgi?pass='+update.escape(update.config().get(section,'Password'),pypad.ESCAPE_URL)+'&mode=updinfo&song='+song
curl=pycurl.Curl() curl=pycurl.Curl()
@@ -55,6 +50,13 @@ def ProcessPad(update):
# #
headers.append('User-Agent: '+'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2') headers.append('User-Agent: '+'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2')
curl.setopt(curl.HTTPHEADER,headers); curl.setopt(curl.HTTPHEADER,headers);
except configparser.NoSectionError:
return
#
# Now, send the update
#
if update.shouldBeProcessed(section):
try: try:
curl.perform() curl.perform()
code=curl.getinfo(pycurl.RESPONSE_CODE) code=curl.getinfo(pycurl.RESPONSE_CODE)
@@ -65,8 +67,6 @@ def ProcessPad(update):
curl.close() curl.close()
n=n+1 n=n+1
except configparser.NoSectionError:
return
# #
# 'Main' function # 'Main' function