mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-27 14:12:34 +02:00
2021-12-12 Fred Gleason <fredg@paravelsystems.com>
* Added an 'SaveLog()' method to the 'rivwebpyapi' API. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
parent
b519674128
commit
9104070ba8
@ -22759,3 +22759,5 @@
|
||||
2021-12-12 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Fixed a bug in rdxport(8) that caused the 'SaveLog' WebAPI call
|
||||
to fail if the target log didn't exist.
|
||||
2021-12-12 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added an 'SaveLog()' method to the 'rivwebpyapi' API.
|
||||
|
@ -168,6 +168,7 @@ LOGLINE_FIELDS={
|
||||
'source': 'string',
|
||||
'timeType': 'string',
|
||||
'startTime': 'time',
|
||||
'graceTime': 'integer',
|
||||
'transitionType': 'string',
|
||||
'cutQuantity': 'integer',
|
||||
'lastCutPlayed': 'integer',
|
||||
@ -204,6 +205,7 @@ LOGLINE_FIELDS={
|
||||
'hookEndPoint': 'integer',
|
||||
'eventLength': 'integer',
|
||||
'linkEventName': 'string',
|
||||
'linkLength': 'integer',
|
||||
'linkStartTime': 'time',
|
||||
'linkStartSlop': 'integer',
|
||||
'linkEndSlop': 'integer',
|
||||
@ -2081,6 +2083,155 @@ class rivwebpyapi(object):
|
||||
if(r.status_code!=requests.codes.ok):
|
||||
self.__throwError(response=r)
|
||||
|
||||
def SaveLog(self,log_name,header_values,line_values,guid=None):
|
||||
"""
|
||||
Save a log into the database. If the specified log does not
|
||||
exist, it will be created automatically.
|
||||
|
||||
Takes the following arguments:
|
||||
|
||||
log_name - The log name to save to (string).
|
||||
|
||||
header_values - Log header data (rivwebpyapi.Log object).
|
||||
|
||||
line_values - Log line data (List of rivwebpyapi.LogLine objects).
|
||||
|
||||
guid - The lock ID, provided by rivwebpyapi.LockLog() (string).
|
||||
"""
|
||||
|
||||
if(not log_name):
|
||||
raise ValueError('invalid log name')
|
||||
|
||||
#
|
||||
# Build the WebAPI header arguments
|
||||
#
|
||||
postdata={
|
||||
'COMMAND': '28',
|
||||
'LOGIN_NAME': self.__connection_username,
|
||||
'PASSWORD': self.__connection_password,
|
||||
'LOG_NAME': str(log_name),
|
||||
'LINE_QUANTITY': str(len(line_values)),
|
||||
'SERVICE_NAME': header_values.values()['serviceName'],
|
||||
'DESCRIPTION': header_values.values()['description'],
|
||||
'PURGE_DATE': header_values.values()['purgeDate']
|
||||
}
|
||||
if(header_values.values()['autoRefresh']):
|
||||
postdata['AUTO_REFRESH']=1
|
||||
else:
|
||||
postdata['AUTO_REFRESH']=0
|
||||
if(header_values.values()['startDate']==None):
|
||||
postdata['START_DATE']=''
|
||||
else:
|
||||
postdata['START_DATE']=header_values.values()['startDate']
|
||||
if(header_values.values()['endDate']==None):
|
||||
postdata['END_DATE']=''
|
||||
else:
|
||||
postdata['END_DATE']=header_values.values()['endDate']
|
||||
if(header_values.values()['purgeDate']==None):
|
||||
postdata['PURGE_DATE']=''
|
||||
else:
|
||||
postdata['PURGE_DATE']=header_values.values()['purgeDate']
|
||||
if(guid):
|
||||
postdata['LOCK_GUID']=guid
|
||||
|
||||
#
|
||||
# Log Lines
|
||||
#
|
||||
line_postnames={
|
||||
'id': 'ID',
|
||||
'type': 'TYPE',
|
||||
'cartNumber': 'CART_NUMBER',
|
||||
'timeType': 'TIME_TYPE',
|
||||
'startTime': 'START_TIME',
|
||||
'graceTime': 'GRACE_TIME',
|
||||
'transitionType': 'TRANS_TYPE',
|
||||
'originUser': 'ORIGIN_USER',
|
||||
'originDateTime': 'ORIGIN_DATETIME',
|
||||
'markerComment': 'COMMENT',
|
||||
'markerLabel': 'LABEL',
|
||||
'startPointLog': 'START_POINT',
|
||||
'endPointLog': 'END_POINT',
|
||||
'segueStartPointLog': 'SEGUE_START_POINT',
|
||||
'segueEndPointLog': 'SEGUE_END_POINT',
|
||||
'fadeupPointLog': 'FADEUP_POINT',
|
||||
'fadeupGain': 'FADEUP_GAIN',
|
||||
'fadedownPointLog': 'FADEDOWN_POINT',
|
||||
'fadedownGain': 'FADEDOWN_GAIN',
|
||||
'duckUpGain': 'DUCK_UP_GAIN',
|
||||
'duckDownGain': 'DUCK_DOWN_GAIN',
|
||||
'eventLength': 'EVENT_LENGTH',
|
||||
'linkLength': 'LINK_LENGTH',
|
||||
'linkEventName': 'LINK_EVENT_NAME',
|
||||
'linkLength': 'LINK_LENGTH',
|
||||
'linkStartTime': 'LINK_START_TIME',
|
||||
'linkStartSlop': 'LINK_START_SLOP',
|
||||
'linkEndSlop': 'LINK_END_SLOP',
|
||||
'linkId': 'LINK_ID',
|
||||
'linkEmbedded': 'LINK_EMBEDDED',
|
||||
'extStartTime': 'EXT_START_TIME',
|
||||
'extLength': 'EXT_LENGTH',
|
||||
'extCartName': 'EXT_CART_NAME',
|
||||
'extData': 'EXT_DATA',
|
||||
'extEventId': 'EXT_EVENT_ID',
|
||||
'extAnncType': 'EXT_ANNC_TYPE'
|
||||
}
|
||||
line=0
|
||||
for ll in line_values:
|
||||
for key in ll.values():
|
||||
if(key in line_postnames.keys()):
|
||||
if(ll.values()[key]==None):
|
||||
postdata['LINE'+str(line)+'_'+line_postnames[key]]=''
|
||||
else:
|
||||
postdata['LINE'+str(line)+'_'+line_postnames[key]]=ll.values()[key]
|
||||
line=line+1
|
||||
|
||||
#
|
||||
# Execute
|
||||
#
|
||||
r=requests.post(self.__connection_url,data=postdata)
|
||||
if(r.status_code!=requests.codes.ok):
|
||||
self.__throwError(response=r)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def SavePodcast(self,cast_id,filename):
|
||||
"""
|
||||
Save posted podcast audio to the Rivendell audio store.
|
||||
|
||||
Takes the following arguments:
|
||||
|
||||
filename - Name of the file containing audio to be stored (string).
|
||||
|
||||
cast_id - ID of the owning podcast item (integer).
|
||||
"""
|
||||
|
||||
if(not filename):
|
||||
raise ValueError('missing filename')
|
||||
if(cast_id<0):
|
||||
raise ValueError('invalid podcast id')
|
||||
|
||||
#
|
||||
# Build the WebAPI arguments
|
||||
#
|
||||
postdata={
|
||||
'COMMAND': '38',
|
||||
'LOGIN_NAME': self.__connection_username,
|
||||
'PASSWORD': self.__connection_password,
|
||||
'ID': str(cast_id)
|
||||
}
|
||||
files={'FILENAME': open(filename,'rb')}
|
||||
|
||||
#
|
||||
# Execute
|
||||
#
|
||||
r=requests.post(self.__connection_url,data=postdata,files=files)
|
||||
if(r.status_code!=requests.codes.ok):
|
||||
self.__throwError(response=r)
|
||||
|
||||
def TrimAudio(self,cart_number,cut_number,trim_level):
|
||||
"""
|
||||
Return time pointers to the first and last instance of a
|
||||
@ -2137,40 +2288,6 @@ class rivwebpyapi(object):
|
||||
|
||||
return handler.output()[0]
|
||||
|
||||
def SavePodcast(self,cast_id,filename):
|
||||
"""
|
||||
Save posted podcast audio to the Rivendell audio store.
|
||||
|
||||
Takes the following arguments:
|
||||
|
||||
filename - Name of the file containing audio to be stored (string).
|
||||
|
||||
cast_id - ID of the owning podcast item (integer).
|
||||
"""
|
||||
|
||||
if(not filename):
|
||||
raise ValueError('missing filename')
|
||||
if(cast_id<0):
|
||||
raise ValueError('invalid podcast id')
|
||||
|
||||
#
|
||||
# Build the WebAPI arguments
|
||||
#
|
||||
postdata={
|
||||
'COMMAND': '38',
|
||||
'LOGIN_NAME': self.__connection_username,
|
||||
'PASSWORD': self.__connection_password,
|
||||
'ID': str(cast_id)
|
||||
}
|
||||
files={'FILENAME': open(filename,'rb')}
|
||||
|
||||
#
|
||||
# Execute
|
||||
#
|
||||
r=requests.post(self.__connection_url,data=postdata,files=files)
|
||||
if(r.status_code!=requests.codes.ok):
|
||||
self.__throwError(response=r)
|
||||
|
||||
def UnassignSchedCode(self,cart_number,sched_code):
|
||||
"""
|
||||
Unassign a schedule code from a cart.
|
||||
|
@ -56,6 +56,7 @@ EXTRA_DIST = add_cart.py\
|
||||
remove_image.py\
|
||||
remove_podcast.py\
|
||||
remove_rss.py\
|
||||
save_log.py\
|
||||
save_podcast.py\
|
||||
trim_audio.py\
|
||||
unassign_sched_code.py
|
||||
|
109
apis/rivwebpyapi/tests/save_log.py
Executable file
109
apis/rivwebpyapi/tests/save_log.py
Executable file
@ -0,0 +1,109 @@
|
||||
#!%PYTHON_BANGPATH%
|
||||
|
||||
# save_log.py
|
||||
#
|
||||
# RivWebPyApi test script for Rivendell
|
||||
#
|
||||
# Test the SaveLog Web API call
|
||||
#
|
||||
# (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
|
||||
import getpass
|
||||
import rivwebpyapi
|
||||
import sys
|
||||
def eprint(*args,**kwargs):
|
||||
print(*args,file=sys.stderr,**kwargs)
|
||||
|
||||
url='';
|
||||
username=''
|
||||
password=''
|
||||
from_log_name=''
|
||||
to_log_name=''
|
||||
|
||||
#
|
||||
# Get login parameters
|
||||
#
|
||||
usage='save_log --url=<rd-url> --username=<rd-username> --from-cart-name=<str> --to-log-name=<str> [--password=<passwd>]'
|
||||
for arg in sys.argv:
|
||||
f0=arg.split('=')
|
||||
key=f0[0]
|
||||
del f0[0]
|
||||
value='='.join(f0)
|
||||
if(value):
|
||||
if(key=='--url'):
|
||||
url=value
|
||||
if(key=='--username'):
|
||||
username=value
|
||||
if(key=='--password'):
|
||||
password=value
|
||||
if(key=='--from-log-name'):
|
||||
from_log_name=value
|
||||
if(key=='--to-log-name'):
|
||||
to_log_name=value
|
||||
|
||||
if(not password):
|
||||
password=getpass.getpass()
|
||||
if((not url)or(not username)):
|
||||
print(usage)
|
||||
sys.exit(1)
|
||||
if(not from_log_name):
|
||||
eprint('you must supply "--from-log-name"')
|
||||
sys.exit(1)
|
||||
if(not to_log_name):
|
||||
eprint('you must supply "--to-log-name"')
|
||||
sys.exit(1)
|
||||
if(from_log_name==to_log_name):
|
||||
eprint('"--from-log-name" and "--to-log_name" must be different')
|
||||
sys.exit(1)
|
||||
|
||||
webapi=rivwebpyapi.rivwebpyapi(url=url,username=username,password=password)
|
||||
|
||||
#
|
||||
# Get the "from" log
|
||||
#
|
||||
try:
|
||||
log_header=webapi.ListLogs(log_name=from_log_name)[0]
|
||||
except rivwebpyapi.RivWebPyError as err:
|
||||
eprint('*** ERROR Calling ListLogs() ***')
|
||||
eprint('Response Code: '+str(err.responseCode))
|
||||
eprint('ErrorString: '+str(err.errorString))
|
||||
eprint('*******************************')
|
||||
eprint('')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
log_lines=webapi.ListLog(log_name=from_log_name)
|
||||
except rivwebpyapi.RivWebPyError as err:
|
||||
eprint('*** ERROR Calling ListLog() ***')
|
||||
eprint('Response Code: '+str(err.responseCode))
|
||||
eprint('ErrorString: '+str(err.errorString))
|
||||
eprint('*******************************')
|
||||
eprint('')
|
||||
sys.exit(1)
|
||||
|
||||
#
|
||||
# Save "to" log
|
||||
#
|
||||
try:
|
||||
webapi.SaveLog(log_name=to_log_name,header_values=log_header,line_values=log_lines)
|
||||
except rivwebpyapi.RivWebPyError as err:
|
||||
eprint('*** ERROR Calling SaveLog() ***')
|
||||
eprint('Response Code: '+str(err.responseCode))
|
||||
eprint('ErrorString: '+str(err.errorString))
|
||||
eprint('*******************************')
|
||||
eprint('')
|
||||
sys.exit(1)
|
Loading…
x
Reference in New Issue
Block a user