complete inplace updates, threshold checking
This commit is contained in:
parent
ded5dc3b8d
commit
51594b77cd
|
@ -85,28 +85,24 @@ proc checkopts {argv} {
|
|||
}
|
||||
-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%' "
|
||||
|
|
|
@ -32,6 +32,7 @@ proc checkopts {argv} {
|
|||
|
||||
# List of options with default values
|
||||
set optarray {
|
||||
thresh 0
|
||||
d 0
|
||||
debug 0
|
||||
alert 0
|
||||
|
@ -39,7 +40,7 @@ proc checkopts {argv} {
|
|||
noconflict 0
|
||||
nomissepg 0
|
||||
noepgchg 0
|
||||
inplace 0
|
||||
noinplace 0
|
||||
}
|
||||
|
||||
# Override default from settings DB
|
||||
|
@ -167,12 +168,12 @@ proc conflict-list {} {
|
|||
set conflicts [rsv newconflicts [system tuners] "xlist"]
|
||||
if {[llength $conflicts] > 1} {
|
||||
log "++++ [llength $conflicts] Conflicts exist +++" 1
|
||||
log "$conflicts" 2
|
||||
log "$conflicts" 3
|
||||
}
|
||||
}
|
||||
|
||||
proc rsvscan {} {
|
||||
global svcmap conflicts svcdef
|
||||
global svcmap conflicts svcdef now thresh
|
||||
svcmap
|
||||
conflict-list
|
||||
|
||||
|
@ -180,14 +181,16 @@ proc rsvscan {} {
|
|||
set resvs [rsv list]
|
||||
|
||||
# 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 ds "[clock format $s -format {%d/%m/%y %H:%M}]"
|
||||
set d [$resv get nduration]
|
||||
set e $($s + $d)
|
||||
set now [clock seconds]
|
||||
set slot [$resv get ulslot]
|
||||
|
||||
lassign [$resv padded 1] sp ep
|
||||
|
||||
# Ignore manual recordings & reminders
|
||||
|
@ -200,7 +203,7 @@ proc rsvscan {} {
|
|||
set ended 0
|
||||
}
|
||||
|
||||
set dresv "$ds [clock format $d -format {%H:%M}] === slot [$resv get ulslot] === $name === [$resv channel_name]"
|
||||
set dresv "$ds [clock format $d -format {%H:%M}] === slot $slot === $name === [$resv channel_name]"
|
||||
|
||||
if {!$ended} {
|
||||
log "Reservation - $dresv" 2
|
||||
|
@ -210,7 +213,9 @@ proc rsvscan {} {
|
|||
set ecrid [$resv get szCRID]
|
||||
|
||||
if {[llength $elist] > 0} {
|
||||
#
|
||||
# check each episode scheduled
|
||||
#
|
||||
foreach epsd $elist {
|
||||
lassign $epsd service_id start end event_id
|
||||
incr enum
|
||||
|
@ -218,24 +223,38 @@ proc rsvscan {} {
|
|||
set epgcrid [string range $ecrid [string first "/" $ecrid] end]
|
||||
set ecrid [string range $ecrid 1 end]
|
||||
set dur $($end-$start)
|
||||
set deps "[clock format $start -format {%d/%m/%y %H:%M}] [clock format $dur -format {%H:%M}] === slot $slot === $name === [$resv channel_name]"
|
||||
|
||||
if {$start > $thresh} {
|
||||
log "Start > Threshold - $deps" 2
|
||||
break
|
||||
}
|
||||
|
||||
if {$start < $now} {
|
||||
log "Already started? - $deps" 1
|
||||
# need to check whether it has actually started and schedule alternate if not tracking
|
||||
continue
|
||||
}
|
||||
|
||||
set svc $svcmap($service_id)
|
||||
# Retrieve epg record for the episode
|
||||
set record [lindex [\
|
||||
epg dbfetch dump -service $svc -event $event_id -sort ""] 0]
|
||||
log "$service_id $start $end $svc $event_id $record $ecrid $epgcrid" 3
|
||||
|
||||
if {$record==""} {
|
||||
set deps "[clock format $start -format {%a %d %b %Y %H:%M}] [clock format $dur -format {%H:%M}] === slot [$resv get ulslot] === $name === [$resv channel_name]"
|
||||
#
|
||||
# No epg rcord found for the episode - find alternate showing
|
||||
#
|
||||
log "+++ No matching epg entry ++++ $deps" 0
|
||||
if {$::opts(nomissepg)} {
|
||||
log "-nomissepg - Not checking for alternate" 1
|
||||
continue
|
||||
}
|
||||
# look for an alternate showing
|
||||
|
||||
set others [epg dbfetch dump -crid $epgcrid -nocase 1 -sort "start" ]
|
||||
#param "collate nocase"
|
||||
log "$ecrid $epgcrid $ecrids $others" 3
|
||||
log "$ecrid $epgcrid $ecrids $others" 32
|
||||
set other [findAlternate $resv $others $start $def 1]
|
||||
if {$other != ""} {
|
||||
set ostart [$other get start]
|
||||
|
@ -243,13 +262,14 @@ proc rsvscan {} {
|
|||
set oend $($ostart+$odur)
|
||||
set oname [$other get name]
|
||||
set ocname [$other get channel_name]
|
||||
set dother "[clock format $ostart -format {%a %d %b %Y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
# attempt to schedule the alternate
|
||||
if {$::opts(inplace)} {
|
||||
update_event $resv $other $epsd $dother "Event Changed"
|
||||
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
# attempt to schedule the alternate (inplace)
|
||||
if {!$::opts(noinplace)} {
|
||||
update_event $resv $other $epsd "$deps--->$dother" "Event Changed"
|
||||
conflict-list
|
||||
continue
|
||||
}
|
||||
# attempt to schedule the alternate (new even+skip)
|
||||
if {[schedule $other $dother "Event Changed"]} {
|
||||
if {![$resv isseries]} {
|
||||
# delete single recording
|
||||
|
@ -265,30 +285,46 @@ proc rsvscan {} {
|
|||
}
|
||||
|
||||
} else {
|
||||
#
|
||||
# Epg entry for the episode found
|
||||
#
|
||||
|
||||
# Check that details match
|
||||
|
||||
set epgname [$record get name]
|
||||
set def $svcdef([$record get channel_hsvc])
|
||||
set deps "[clock format $start -format {%a %d %b %Y %H:%M}] [clock format $dur -format {%H:%M}] === slot [$resv get ulslot] === $epgname === [$record get channel_name]"
|
||||
set deps "[clock format $start -format {%d/%m/%y %H:%M}] [clock format $dur -format {%H:%M}] === slot $slot === $epgname === [$record get channel_name]"
|
||||
|
||||
log "Episode $deps" 2
|
||||
set ok 1
|
||||
set reason "no reason"
|
||||
if {$start != [$record get start]} {
|
||||
set ok 0
|
||||
log "+++ Start Mismatch: $start != [$record get start] +++ $deps" 1
|
||||
set reason "Start Mismatch: $start != [$record get start"
|
||||
log "+++ $reason +++ $deps" 1
|
||||
}
|
||||
if {$dur != [$record get duration]} {
|
||||
set ok 0
|
||||
log "+++ Duration Mismatch: $dur != [$record get duration] +++ $deps" 1
|
||||
set reason "Duration Mismatch: $dur != [$record get duration]"
|
||||
log "+++ $reason +++ $deps" 1
|
||||
}
|
||||
if {$dur != [$record get duration]} {
|
||||
set ok 0
|
||||
set reason "Duration Mismatch: $dur != [$record get duration]"
|
||||
log "+++ $reason +++ $deps" 1
|
||||
}
|
||||
# Refresh event since we cant update individual entry
|
||||
if {!$ok && !$::opts(noepgchg)} {
|
||||
refresh $resv $deps "Event Changed"
|
||||
if {!$::opts(noinplace)} {
|
||||
update_event $resv $record $epsd "$deps--->$dother" $reason
|
||||
} else {
|
||||
refresh $resv $deps $reason
|
||||
}
|
||||
conflict-list
|
||||
}
|
||||
|
||||
# Check for conflicts
|
||||
if {"[$resv get ulslot]$end" in $conflicts} {
|
||||
|
||||
if {"$slot$end" in $conflicts} {
|
||||
set ok 0
|
||||
log "+++ Confict exists +++ $deps" 1
|
||||
#set others [$record othertimes]
|
||||
|
@ -300,11 +336,11 @@ proc rsvscan {} {
|
|||
set oend $($ostart+$odur)
|
||||
set oname [$other get name]
|
||||
set ocname [$other get channel_name]
|
||||
set dother "[clock format $ostart -format {%a %d %b %Y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
|
||||
# attempt to schedule the alternate
|
||||
if {$::opts(inplace)} {
|
||||
update_event $resv $other $epsd $dother "Confict resolution"
|
||||
if {!$::opts(noinplace)} {
|
||||
update_event $resv $other $epsd "$deps--->$dother" "Confict resolution"
|
||||
conflict-list
|
||||
continue
|
||||
}
|
||||
|
@ -360,7 +396,7 @@ proc scanAlternates {resv others start definition sametime samedef} {
|
|||
set oname [$other get name]
|
||||
set ocname [$other get channel_name]
|
||||
set odef $svcdef([$other get channel_hsvc])
|
||||
set dother "[clock format $ostart -format {%a %d %b %Y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
|
||||
# same start time not suitable match for confilcts
|
||||
if {$ostart == $start && !$sametime} {continue}
|
||||
if {$ostart <= [clock seconds]} {continue}
|
||||
|
@ -396,10 +432,10 @@ proc schedule {resv desc {reason ""} {type 1} } {
|
|||
set type 1
|
||||
set r [rsv construct $resv $type]
|
||||
if {[catch {$r insert pending} msg]} {
|
||||
log "+++ Error encountered while scheduling: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while scheduling: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully scheduled *** $desc === $reason" 0
|
||||
log "*** scheduled *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -418,10 +454,10 @@ proc refresh {resv desc {reason ""}} {
|
|||
$resv set_refresh
|
||||
$resv insert
|
||||
} msg]} {
|
||||
log "+++ Error encountered while refreshing: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while refreshing: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully refreshed *** $desc === $reason" 0
|
||||
log "*** refreshed *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -440,10 +476,10 @@ proc cancel {resv desc {reason ""}} {
|
|||
$resv set_delete
|
||||
$resv insert pending 0 1
|
||||
} msg]} {
|
||||
log "+++ Error encountered while cancelling: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while cancelling: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully cancelled *** $desc === $reason" 0
|
||||
log "*** cancelled *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -459,10 +495,10 @@ proc skip {resv xservice xevent desc {reason ""}} {
|
|||
if {[catch {
|
||||
$resv apply_skip $xservice $xevent
|
||||
} msg]} {
|
||||
log "+++ Error encountered while skipping: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while skipping: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully skipped *** $desc === $reason" 0
|
||||
log "*** skipped *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -480,10 +516,10 @@ proc replaceskip {resv skipcrid desc {reason ""}} {
|
|||
$resv replace_skip [list $skipcrid]
|
||||
$resv insert
|
||||
} msg]} {
|
||||
log "+++ Error encountered while skipping: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while skipping: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully skipped *** $desc === $reason" 0
|
||||
log "*** skipped *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -494,7 +530,7 @@ proc replaceskip {resv skipcrid desc {reason ""}} {
|
|||
proc update_event {resv other origaul desc {reason ""}} {
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =Updated *** $desc === $reason" 0
|
||||
#return 1
|
||||
return 1
|
||||
}
|
||||
set curauls [$resv aul]
|
||||
set ecrids [split [$resv get szEventToRecord] "|"]
|
||||
|
@ -506,7 +542,7 @@ proc update_event {resv other origaul desc {reason ""}} {
|
|||
set othcrid [string toupper "1[$other get channel_crid][$other get event_crid]"]
|
||||
set newaul {}
|
||||
set newevnts ""
|
||||
puts "$origaul-- $othaul -- $curauls $ecrids "
|
||||
log "$origaul-- $othaul -- $curauls $ecrids " 3
|
||||
set insert 0
|
||||
|
||||
# rebuild aul and events list with new event in correct order
|
||||
|
@ -528,29 +564,37 @@ proc update_event {resv other origaul desc {reason ""}} {
|
|||
lappend newaul $othaul
|
||||
append newevnts "$othcrid|"
|
||||
}
|
||||
puts "$newevnts -- $newaul"
|
||||
log "$newevnts -- $newaul" 3
|
||||
|
||||
# update header with next event
|
||||
lassign [lindex $newaul 0] service_id start end event_id
|
||||
#$resv set hsvc $service_id
|
||||
$resv set nsttime $start
|
||||
$resv set nduration $($end-$start)
|
||||
$resv set usevtid $event_id
|
||||
$resv set ucVolume "$service_id:$event_id:$start"
|
||||
set dur $($end-$start)
|
||||
if {[$resv get hsvc] != $service_id ||
|
||||
[$resv get nsttime] != $start ||
|
||||
[$resv get nduration] != $dur ||
|
||||
[$resv get usevtid] != $event_id} {
|
||||
$resv set nduration $($end-$start)
|
||||
$resv set ucVolume "$service_id:$event_id:$start"
|
||||
log "$desc update next episode [$resv get ucVolume]" 2
|
||||
}
|
||||
|
||||
if {[catch {
|
||||
$resv clear_ulslot
|
||||
$resv set action 5
|
||||
$resv setaul [$resv buildaul $newaul]
|
||||
$resv set szEventToRecord $newevnts
|
||||
$resv insert
|
||||
} msg]} {
|
||||
log "+++ Error encountered while updating: $msg ++++ $desc === $reason" 0
|
||||
log "+++ Error while updating: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully Updated *** $desc === $reason" 0
|
||||
log "*** Updated *** $desc === $reason" 0
|
||||
system restartpending
|
||||
#rsv commit
|
||||
# Ensure our copy matches the updated
|
||||
$resv set hsvc $service_id
|
||||
$resv set nsttime $start
|
||||
$resv set nduration $($end-$start)
|
||||
$resv set usevtid $event_id
|
||||
$resv set ucVolume 0
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
@ -561,24 +605,20 @@ proc update_event {resv other origaul desc {reason ""}} {
|
|||
set ::optlist ""
|
||||
set ::opt "-h"
|
||||
set ::debug 0
|
||||
|
||||
set logfd stdout
|
||||
if {[info exists ::auto::logfd]} {
|
||||
set logfd $::auto::logfd
|
||||
}
|
||||
|
||||
# validate parameters
|
||||
checkopts $argv
|
||||
|
||||
# Open log file / use auto logfile
|
||||
if {[info exists ::auto::logfile]} {
|
||||
set logfile $::auto::logfile
|
||||
set now [clock seconds]
|
||||
if {$::opts(thresh)} {
|
||||
set thresh $($now + ($::opts(thresh)*60*60))
|
||||
} else {
|
||||
set logfile "/mod/tmp/schedchk.log"
|
||||
}
|
||||
if {![info exists ::auto::logfd]} {
|
||||
if {$debug} {
|
||||
set logfd stdout
|
||||
puts "DEBUG ON level $::loglevel"
|
||||
} else {
|
||||
set logfd [open $logfile "a+"]
|
||||
}
|
||||
set thresh $($now + (9*24*60*60))
|
||||
}
|
||||
|
||||
# process command
|
||||
|
@ -596,12 +636,13 @@ switch -- $opt {
|
|||
|
||||
puts ""
|
||||
puts "Option Default (unless changed in Settings) "
|
||||
puts "-d 0 = produce detailed debug on Stdout (0, 1, 2) "
|
||||
puts "-thresh 0 = don't check problems more than x hrs away start (0 no thresh) "
|
||||
puts "-d 0 = produce detailed debug (0, 1, 2) "
|
||||
puts "-test n = don't make updates "
|
||||
puts "-noconflict n = don't check for confilcts"
|
||||
puts "-nomissepg n = don't resolve missing epg entries"
|
||||
puts "-noepgchg n = don't resolve epg time changes"
|
||||
puts "-inplace n = upate confilcts inplace rather than by skipping"
|
||||
puts "-noinplace n = upate problems inplace rather than by skipping"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue