fmtrsv - format rsv entries
This commit is contained in:
parent
ffd5670962
commit
cefbb62994
|
@ -0,0 +1,320 @@
|
|||
#!/mod/bin/jimsh
|
||||
# "fmtrsv = Format content of rsv.db schedule entries"
|
||||
# author MymsMan based on webif functions by af123
|
||||
|
||||
source /mod/webif/lib/setup
|
||||
require rsv.class epg.class system.class
|
||||
set ::loglevel 0
|
||||
|
||||
proc log {msg {level 1}} {
|
||||
if {$level > $::loglevel} return
|
||||
puts $::logfd "[\
|
||||
clock format [clock seconds] -format "%d/%m/%Y %H:%M:%S"\
|
||||
] SC([pid])- $msg"
|
||||
flush $::logfd
|
||||
}
|
||||
|
||||
|
||||
# Parse command options and apply defaults
|
||||
proc checkopts {argv} {
|
||||
set settings [settings]
|
||||
set parmerror 0
|
||||
|
||||
# List of options with default values
|
||||
set optarray {
|
||||
d 0
|
||||
debug 0
|
||||
|
||||
}
|
||||
|
||||
# Override default from settings DB
|
||||
foreach {key defvalue} [array get optarray] {
|
||||
set ::opts($key) [$settings _nval_setting "fmtrsv_$key"]
|
||||
if {$::opts($key)==0} {set ::opts($key) $defvalue}
|
||||
}
|
||||
|
||||
# Handle text setting for oher options
|
||||
set otheropts [$settings _tval_setting "fmtrsv_otheropts"]
|
||||
if {$otheropts == 0} {set otheropts ""}
|
||||
|
||||
set otheropts ""
|
||||
|
||||
# Parse argument lists
|
||||
foreach argl [list $otheropts $argv] {
|
||||
set ::optlist ""
|
||||
log "arg list $argl" 2
|
||||
for {set ix 0} {$ix < [llength $argl]} {incr ix} {
|
||||
set arg [lindex $argl $ix]
|
||||
|
||||
#check if option in optarray list
|
||||
if {[string range $arg 0 0] == "-"} {
|
||||
set argx [string tolower [string range $arg 1 end]]
|
||||
if {[dict exists $optarray $argx]} {
|
||||
incr ix
|
||||
set val [lindex $argl $ix]
|
||||
set nval $val
|
||||
if {$val eq "y"} {set nval 1}
|
||||
if {$val eq "n"} {set nval 0}
|
||||
if {![string is double -strict $nval]} {
|
||||
if {[string length $nval] == 0 ||
|
||||
[string range $nval 0 0] == "-"} {
|
||||
# Value omitted assume true
|
||||
set nval 1
|
||||
set val "y"
|
||||
incr ix -1
|
||||
} else {
|
||||
log "Option $arg value ($val) is not y, n or numeric" 0
|
||||
incr ix -1
|
||||
set parmerror 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
lappend ::optlist $arg
|
||||
lappend ::optlist $val
|
||||
set ::opts($argx) $nval
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
# check other options
|
||||
switch -- $arg {
|
||||
-fmt -
|
||||
--help -
|
||||
-h {
|
||||
set ::opt $arg
|
||||
}
|
||||
-s -
|
||||
-slot {
|
||||
set ::opt $arg
|
||||
incr ix
|
||||
set find [lindex $argl $ix]
|
||||
append ::select "ulslot = $find "
|
||||
}
|
||||
-l -
|
||||
-lcn {
|
||||
set ::opt $arg
|
||||
incr ix
|
||||
set find [lindex $argl $ix]
|
||||
append ::select "usLcn = $find "
|
||||
}
|
||||
-n -
|
||||
-name {
|
||||
set ::opt $arg
|
||||
incr ix
|
||||
set find [lindex $argl $ix]
|
||||
append ::select "szevtname like '%$find%' "
|
||||
}
|
||||
-c -
|
||||
-cname {
|
||||
set ::opt $arg
|
||||
incr ix
|
||||
set find [lindex $argl $ix]
|
||||
append ::select "szSvcName like '%$find%' "
|
||||
}
|
||||
default {
|
||||
log "Unrecognized option: $arg" 0
|
||||
set parmerror 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if {$::opts(debug) || $::opts(d)} {
|
||||
set ll $::loglevel
|
||||
if {$::opts(debug) > $ll} {set ll $::opts(debug)}
|
||||
if {$::opts(d) > $ll} {set ll $::opts(d)}
|
||||
set ::debug 1
|
||||
set ::loglevel $ll
|
||||
set ::auto::loglevel $ll
|
||||
}
|
||||
|
||||
if {$parmerror} {
|
||||
log "Parameter errors found"
|
||||
exit
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
proc svcmap {} {
|
||||
# establish rsv <-> epg service_id mapping
|
||||
global svcmap svcdef
|
||||
set svcmap {}
|
||||
set svcdef {}
|
||||
set svcdef(0) 0
|
||||
lmap i \
|
||||
[$::channeldb query {select hSvc, usSvcid, eVideoType from TBL_SVC}] \
|
||||
{
|
||||
set svcmap([lindex $i 1]) [lindex $i 3]
|
||||
set svcdef([lindex $i 1]) [lindex $i 5]
|
||||
}
|
||||
set svckeys [array names svcmap]
|
||||
}
|
||||
|
||||
proc conflict-list {} {
|
||||
global conflicts
|
||||
if {$::opts(noconflict)} {
|
||||
log "-noconflict Bypassing automatic conflict resolution"
|
||||
set conflicts {}
|
||||
return
|
||||
}
|
||||
|
||||
set conflicts [rsv newconflicts [system tuners] "xlist"]
|
||||
if {[llength $conflicts] > 1} {
|
||||
log "++++ [llength $conflicts] Conflicts exist +++" 1
|
||||
log "$conflicts" 2
|
||||
}
|
||||
}
|
||||
|
||||
proc rsvscan {} {
|
||||
global svcmap conflicts svcdef
|
||||
#svcmap
|
||||
#conflict-list
|
||||
|
||||
if {$::select != ""} {set ::select "where $::select"}
|
||||
set resvs [rsv list TBL_RESERVATION $::select]
|
||||
|
||||
# for each reservation
|
||||
foreach resv $resvs {
|
||||
set name [$resv name]
|
||||
#set def $svcdef([$resv get hsvc])
|
||||
set s [$resv start]
|
||||
set ds "[clock format $s -format {%a %d %b %Y %H:%M}]"
|
||||
set d [$resv get nduration]
|
||||
set e $($s + $d)
|
||||
set now [clock seconds]
|
||||
lassign [$resv padded 1] sp ep
|
||||
|
||||
# Ignore manual recordings & reminders
|
||||
#if {[$resv get ersvtype] != 3} { continue}
|
||||
# Has event passed
|
||||
if {$now > $e + $ep} {
|
||||
set ended 1
|
||||
incr num_ended
|
||||
} else {
|
||||
set ended 0
|
||||
}
|
||||
|
||||
set ulslot [$resv get ulslot ]
|
||||
set ersvtype [$resv get ersvtype ]
|
||||
set hsvc [$resv get hsvc ]
|
||||
set nsttime [$resv get nsttime ]
|
||||
set szsttime [$resv get szsttime ]
|
||||
set nduration [$resv get nduration ]
|
||||
set erepeat [$resv get erepeat ]
|
||||
set usevtid [$resv get usevtid ]
|
||||
set szevtname [$resv get szevtname ]
|
||||
set ulPreOffset [$resv get ulPreOffset ]
|
||||
set ulPostOffset [$resv get ulPostOffset ]
|
||||
set ulProgramId [$resv get ulProgramId ]
|
||||
set ulSeriesId [$resv get ulSeriesId ]
|
||||
set ucVolume [$resv get ucVolume ]
|
||||
set ucInputMode [$resv get ucInputMode ]
|
||||
set usChNum [$resv get usChNum ]
|
||||
set ucRecKind [$resv get ucRecKind ]
|
||||
set ucCRIDType [$resv get ucCRIDType ]
|
||||
set szCRID [$resv get szCRID ]
|
||||
set szFPBRecPath [$resv get szFPBRecPath ]
|
||||
set szRecordedProgCrid [$resv get szRecordedProgCrid ]
|
||||
set szEventToRecord [$resv get szEventToRecord ]
|
||||
set aulEventToRecordInfo [$resv get aulEventToRecordInfo]
|
||||
set bRecomRsv [$resv get bRecomRsv ]
|
||||
set usLastRecordedEvtId [$resv get usLastRecordedEvtId ]
|
||||
set eReady [$resv get eReady ]
|
||||
set szSvcName [$resv get szSvcName ]
|
||||
set usLcn [$resv get usLcn ]
|
||||
set auls [$resv aul]
|
||||
|
||||
puts "ulslot = $ulslot "
|
||||
puts "ersvtype = $ersvtype "
|
||||
puts "hsvc = $hsvc "
|
||||
puts "nsttime = $nsttime [clock format $nsttime -format "%d/%m/%Y %H:%M"]"
|
||||
puts "szsttime = $szsttime "
|
||||
puts "nduration = $nduration [clock format $nduration -format "%H:%M"]"
|
||||
puts "erepeat = $erepeat "
|
||||
puts "usevtid = $usevtid "
|
||||
puts "szevtname = $szevtname ($name) "
|
||||
puts "ulPreOffset = $ulPreOffset "
|
||||
puts "ulPostOffset = $ulPostOffset "
|
||||
puts "ulProgramId = $ulProgramId "
|
||||
puts "ulSeriesId = $ulSeriesId "
|
||||
puts "ucVolume = $ucVolume "
|
||||
puts "ucInputMode = $ucInputMode "
|
||||
puts "usChNum = $usChNum "
|
||||
puts "ucRecKind = $ucRecKind "
|
||||
puts "ucCRIDType = $ucCRIDType "
|
||||
puts "szCRID = $szCRID "
|
||||
puts "szFPBRecPath = $szFPBRecPath "
|
||||
puts "szRecordedProgCrid = $szRecordedProgCrid "
|
||||
puts "szEventToRecord = $szEventToRecord "
|
||||
puts "aulEventToRecordInfo = $auls"
|
||||
puts "bRecomRsv = $bRecomRsv "
|
||||
puts "usLastRecordedEvtId = $usLastRecordedEvtId "
|
||||
puts "eReady = $eReady "
|
||||
puts "szSvcName = $szSvcName "
|
||||
puts "usLcn = $usLcn "
|
||||
|
||||
set ecrids [split $szEventToRecord "|"]
|
||||
set enum -1
|
||||
puts "Svcid Start End Evtid CRID"
|
||||
foreach aul $auls {
|
||||
lassign $aul service_id start end event_id
|
||||
incr enum
|
||||
set ecrid [lindex $ecrids $enum]
|
||||
puts "$service_id \
|
||||
$start [clock format $start -format "%d/%m/%Y %H:%M"] \
|
||||
$end [clock format $end -format "%d/%m/%Y %H:%M"] \
|
||||
$event_id \
|
||||
$ecrid"
|
||||
}
|
||||
puts "========================================================"
|
||||
|
||||
|
||||
}
|
||||
|
||||
epg cleanup
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------------------------------------
|
||||
# Start of mainline
|
||||
|
||||
set ::optlist ""
|
||||
set ::opt "-fmt"
|
||||
set ::debug 0
|
||||
set logfd stdout
|
||||
set ::loglevel 0
|
||||
set ::opts {}
|
||||
set ::select ""
|
||||
|
||||
# validate parameters
|
||||
checkopts $argv
|
||||
|
||||
|
||||
|
||||
# process command
|
||||
switch -- $::opt {
|
||||
-fmt { # "Format the recording schedule"
|
||||
rsvscan
|
||||
}
|
||||
-h -
|
||||
--help -
|
||||
default { # Help
|
||||
puts "fmtrsv = Check for recording schedule issues and attempt to fix them"
|
||||
puts " "
|
||||
puts "fmtrsv -h = produce this help"
|
||||
puts "fmtrsv -fmt = format the recording schedule"
|
||||
|
||||
puts ""
|
||||
puts "Options "
|
||||
#puts "-d 0 = produce detailed debug on Stdout (0, 1, 2) "
|
||||
puts "-n,-name xxx = select recording name contains"
|
||||
puts "-s,-slot n = select slot"
|
||||
puts "-l,-lcn n = select channel number"
|
||||
puts "-c,-cname xxx = select channel name contains"
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue