cleaned up with
This commit is contained in:
parent
d7b6477d68
commit
bcd386e538
|
@ -15,7 +15,7 @@ proc log {msg {level 1}} {
|
|||
|
||||
|
||||
# Parse command options and apply defaults
|
||||
proc ::schedchk::checkopts {argv} {
|
||||
proc checkopts {argv} {
|
||||
set settings [settings]
|
||||
set parmerror 0
|
||||
|
||||
|
@ -32,6 +32,9 @@ proc ::schedchk::checkopts {argv} {
|
|||
alert 0
|
||||
test 0
|
||||
noconflict 0
|
||||
nomissepg 0
|
||||
noepgchg 0
|
||||
inplace 0
|
||||
}
|
||||
|
||||
# Override default from settings DB
|
||||
|
@ -96,8 +99,7 @@ proc ::schedchk::checkopts {argv} {
|
|||
|
||||
if {[file isfile $file]} {
|
||||
set ::ts [ts fetch $file]
|
||||
if {$::ts == 0} {
|
||||
log "Cannot process ($file) file is not valid recording" 0
|
||||
if {$::ts == 0} { "Cannot process ($file) file is not valid recording" 0
|
||||
set parmerror 1
|
||||
continue
|
||||
}
|
||||
|
@ -134,18 +136,22 @@ proc ::schedchk::checkopts {argv} {
|
|||
}
|
||||
|
||||
|
||||
proc ::schedchk::svcmap {} {
|
||||
proc svcmap {} {
|
||||
# establish rsv <-> epg service_id mapping
|
||||
global svcmap
|
||||
global svcmap svcdef
|
||||
set svcmap {}
|
||||
set svcdef {}
|
||||
set svcdef(0) 0
|
||||
lmap i \
|
||||
[$::channeldb query {select hSvc, usSvcid from TBL_SVC}] \
|
||||
[$::channeldb query {select hSvc, usSvcid, eVideoType from TBL_SVC}] \
|
||||
{
|
||||
set svcmap([lindex $i 1]) [lindex $i 3]
|
||||
set svcmap([lindex $i 1]) [lindex $i 3]
|
||||
set svcdef([lindex $i 1]) [lindex $i 5]
|
||||
}
|
||||
set svckeys [array names svcmap]
|
||||
}
|
||||
proc ::schedchk::conflicts {} {
|
||||
|
||||
proc conflict-list {} {
|
||||
global conflicts
|
||||
if {$::opts(noconflict)} {
|
||||
log "-noconflict Bypassing automatic conflict resolution"
|
||||
|
@ -160,10 +166,10 @@ proc ::schedchk::conflicts {} {
|
|||
}
|
||||
}
|
||||
|
||||
proc ::schedchk::rsvscan {} {
|
||||
global svcmap conflicts
|
||||
::schedchk::svcmap
|
||||
::schedchk::conflicts
|
||||
proc rsvscan {} {
|
||||
global svcmap conflicts svcdef
|
||||
svcmap
|
||||
conflict-list
|
||||
|
||||
|
||||
set events [rsv list]
|
||||
|
@ -171,6 +177,7 @@ proc ::schedchk::rsvscan {} {
|
|||
# for each reservation
|
||||
foreach event $events {
|
||||
set name [$event name]
|
||||
set def $svcdef([$event get hsvc])
|
||||
set s [$event start]
|
||||
set ds "[clock format $s -format {%a %d %b %Y %H:%M}]"
|
||||
set d [$event get nduration]
|
||||
|
@ -202,57 +209,56 @@ proc ::schedchk::rsvscan {} {
|
|||
foreach epsd $elist {
|
||||
lassign $epsd service_id start end event_id
|
||||
incr enum
|
||||
set ecrid [lindex $ecrids $enum]
|
||||
set epgcrid [string range $ecrid [string first "/" $ecrid] end]
|
||||
set ecrid [string range $ecrid 1 end]
|
||||
set dur $($end-$start)
|
||||
|
||||
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" 3
|
||||
log "$service_id $start $end $svc $event_id $record $ecrid $epgcrid" 3
|
||||
if {$record==""} {
|
||||
log "+++ No matching epg entry ++++ $devent" 0
|
||||
set deps "[clock format $start -format {%a %d %b %Y %H:%M}] [clock format $dur -format {%H:%M}] === $name === [$event channel_name]"
|
||||
log "+++ No matching epg entry ++++ $deps" 0
|
||||
if {$::opts(nomissepg)} {
|
||||
log "-nomissepg - Not checking for alternate" 1
|
||||
continue
|
||||
}
|
||||
# look for an alternate showing
|
||||
set ecrid [lindex $ecrids $enum]
|
||||
set ecrid [string range $ecrid [string first "/" $ecrid] end]
|
||||
set others [epg dbfetch dump -crid $ecrid -nocase 1 -debug 1]
|
||||
|
||||
set others [epg dbfetch dump -crid $epgcrid -nocase 1 -sort "start" debug 1]
|
||||
#param "collate nocase"
|
||||
log "$ecrid $ecrids $others" 0
|
||||
foreach other $others {
|
||||
log "$ecrid $epgcrid $ecrids $others" 3
|
||||
set other [findAlternate $event $others $start $def 1]
|
||||
if {$other != ""} {
|
||||
set ostart [$other get start]
|
||||
set odur [$other get duration]
|
||||
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}] === $name === $ocname"
|
||||
if {$ostart <= $now} {continue}
|
||||
## should favour same definition
|
||||
log "Alternate Episode $dother" 2
|
||||
set oconflicts [rsv checkconflict \
|
||||
$ostart $odur \
|
||||
[system tuners]]
|
||||
# Should ignore conflicts with self
|
||||
if {[llength $oconflicts]} {
|
||||
# Alternate has Conflicts
|
||||
log "Alternate conflicts $oconflicts" 2
|
||||
continue
|
||||
}
|
||||
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 {[::schedchk::schedule $other $dother]} {
|
||||
if {[schedule $other $dother "Event Changed"]} {
|
||||
if {![$event isseries]} {
|
||||
# delete single recording
|
||||
::schedchk::cancel $event $deps
|
||||
cancel $event $deps "Event Changed"
|
||||
} else {
|
||||
# refresh since can't skip without epg entry
|
||||
::schedchk::refresh $event $deps
|
||||
# move crid from scheduled to recorded
|
||||
replaceskip $event $ecrid $deps "Event Changed"
|
||||
#refresh $event $deps
|
||||
}
|
||||
::schedchk::conflicts
|
||||
conflict-list
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
# Check that details match
|
||||
set dur $($end-$start)
|
||||
|
||||
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}] === $epgname === [$record get channel_name]"
|
||||
|
||||
log "Episode $deps" 2
|
||||
|
@ -266,9 +272,9 @@ proc ::schedchk::rsvscan {} {
|
|||
log "+++ Duration Mismatch: $dur != [$record get duration] +++ $deps" 1
|
||||
}
|
||||
# Refresh event since we cant update individual entry
|
||||
if {!$ok} {
|
||||
::schedchk::refresh $event $deps
|
||||
::schedchk::conflicts
|
||||
if {!$ok && !$::opts(noepgchg)} {
|
||||
refresh $event $deps "Event Changed"
|
||||
conflict-list
|
||||
}
|
||||
|
||||
# Check for conflicts
|
||||
|
@ -276,36 +282,25 @@ proc ::schedchk::rsvscan {} {
|
|||
set ok 0
|
||||
log "+++ Confict exists +++ $deps" 1
|
||||
set others [$record othertimes]
|
||||
foreach other $others {
|
||||
set other [findAlternate $event $others $start $def 0]
|
||||
if {$other != ""} {
|
||||
set ostart [$other get start]
|
||||
set odur [$other get duration]
|
||||
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}] === $name === $ocname"
|
||||
if {$ostart == $start} {continue}
|
||||
if {$ostart <= $now} {continue}
|
||||
## should favour same definition
|
||||
log "Alternate Episode $dother" 2
|
||||
set oconflicts [rsv checkconflict \
|
||||
$ostart $odur \
|
||||
[system tuners]]
|
||||
# Should ignore conflicts with self
|
||||
if {[llength $oconflicts]} {
|
||||
# Alternate has Conflicts
|
||||
log "Alternate conflicts $oconflicts" 2
|
||||
continue
|
||||
}
|
||||
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 {[::schedchk::schedule $other $dother]} {
|
||||
if {[schedule $other $dother "Confict resolution"]} {
|
||||
if {![$event isseries]} {
|
||||
# delete single recording
|
||||
::schedchk::cancel $event $deps
|
||||
cancel $event $deps "Conflict resolution"
|
||||
} else {
|
||||
# skip conflicted epidode
|
||||
::schedchk::skip $event $svc $event_id $deps
|
||||
skip $event $svc $event_id $deps "Conflict resolution"
|
||||
}
|
||||
::schedchk::conflicts
|
||||
conflict-list
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +309,7 @@ proc ::schedchk::rsvscan {} {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
log "+++ No episodes scheduled +++ $devent" 0
|
||||
log "+++ No episodes scheduled +++ $devent" 1
|
||||
}
|
||||
} else {
|
||||
log "Completed - $devent" 2
|
||||
|
@ -327,24 +322,68 @@ proc ::schedchk::rsvscan {} {
|
|||
log "===============================================" 1
|
||||
epg cleanup
|
||||
}
|
||||
# Scan others for a suitable alternate episode
|
||||
proc findAlternate {event others start definition sametime} {
|
||||
# look for alternate with same definition HD/SD/radio
|
||||
set other [scanAlternates $event $others $start $definition $sametime 1]
|
||||
if {$other == ""} {
|
||||
# scan again wihout requiring matching definition
|
||||
set other [scanAlternates $event $others $start $definition $sametime 0]
|
||||
}
|
||||
return $other
|
||||
}
|
||||
|
||||
# Scan others for a suitable alternate episode
|
||||
proc scanAlternates {event others start definition sametime samedef} {
|
||||
global svcdef
|
||||
|
||||
foreach other $others {
|
||||
set ostart [$other get start]
|
||||
set odur [$other get duration]
|
||||
set oend $($ostart+$odur)
|
||||
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"
|
||||
# same start time not suitable match for confilcts
|
||||
if {$ostart == $start && !$sametime} {continue}
|
||||
if {$ostart <= [clock seconds]} {continue}
|
||||
# should favour same definition
|
||||
if {$odef != $definition && $samedef} {continue}
|
||||
log "Alternate Episode $dother" 2
|
||||
set oconflicts [rsv checkconflict \
|
||||
$ostart $odur \
|
||||
[system tuners]]
|
||||
# Should ignore conflicts with self
|
||||
set cl [llength $oconflicts]
|
||||
if {"$oname" in $oconflicts} {incr cl -1}
|
||||
if {$cl >= [system tuners]} {
|
||||
# Alternate has Conflicts
|
||||
log "Alternate conflicts $oconflicts" 2
|
||||
continue
|
||||
}
|
||||
return $other
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
# Create a new reservation
|
||||
proc ::schedchk::schedule {event desc} {
|
||||
proc schedule {event desc {reason ""} {type 1} } {
|
||||
if {[$event scheduled]} {
|
||||
log "*** Already scheduled *** $desc" 0
|
||||
log "*** Already scheduled *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =scheduled *** $desc" 0
|
||||
log "*** Test mode =scheduled *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
set type 1
|
||||
set r [rsv construct $event $type]
|
||||
if {[catch {$r insert pending} msg]} {
|
||||
log "+++ Error encountered while scheduling: $msg ++++ $desc" 0
|
||||
log "+++ Error encountered while scheduling: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully scheduled *** $desc" 0
|
||||
log "*** Successfully scheduled *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -352,9 +391,9 @@ proc ::schedchk::schedule {event desc} {
|
|||
}
|
||||
|
||||
# Refresh a reservation
|
||||
proc ::schedchk::refresh {event desc} {
|
||||
proc refresh {event desc {reason ""}} {
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =refreshed *** $desc" 0
|
||||
log "*** Test mode =refreshed *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
set type 1
|
||||
|
@ -363,10 +402,10 @@ proc ::schedchk::refresh {event desc} {
|
|||
$event set_refresh
|
||||
$event insert
|
||||
} msg]} {
|
||||
log "+++ Error encountered while refreshing: $msg ++++ $desc" 0
|
||||
log "+++ Error encountered while refreshing: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully refreshed *** $desc" 0
|
||||
log "*** Successfully refreshed *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
|
@ -374,9 +413,9 @@ proc ::schedchk::refresh {event desc} {
|
|||
}
|
||||
|
||||
# Cancel reservation
|
||||
proc ::schedchk::cancel {event desc} {
|
||||
proc cancel {event desc {reason ""}} {
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =cancelled *** $desc" 0
|
||||
log "*** Test mode =cancelled *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
set type 1
|
||||
|
@ -385,34 +424,54 @@ proc ::schedchk::cancel {event desc} {
|
|||
$event set_delete
|
||||
$event insert pending 0 1
|
||||
} msg]} {
|
||||
log "+++ Error encountered while cancelling: $msg ++++ $desc" 0
|
||||
log "+++ Error encountered while cancelling: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully cancelled *** $desc" 0
|
||||
log "*** Successfully cancelled *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
# Skip an episode
|
||||
proc ::schedchk::skip {event xservice xevent desc} {
|
||||
# Skip an episode - with apply_skip
|
||||
proc skip {event xservice xevent desc {reason ""}} {
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =skipped *** $desc" 0
|
||||
log "*** Test mode =skipped *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
if {[catch {
|
||||
$event apply_skip $xservice $xevent
|
||||
} msg]} {
|
||||
log "+++ Error encountered while skipping: $msg ++++ $desc" 0
|
||||
log "+++ Error encountered while skipping: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully skipped *** $desc" 0
|
||||
log "*** Successfully skipped *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
# Skip an episode - with replace_skip
|
||||
proc replaceskip {event skipcrid desc {reason ""}} {
|
||||
if {$::opts(test)} {
|
||||
log "*** Test mode =skipped *** $desc === $reason" 0
|
||||
return 1
|
||||
}
|
||||
if {[catch {
|
||||
$event clear_ulslot
|
||||
$event replace_skip [list $skipcrid]
|
||||
$event insert
|
||||
} msg]} {
|
||||
log "+++ Error encountered while skipping: $msg ++++ $desc === $reason" 0
|
||||
return 0
|
||||
} else {
|
||||
log "*** Successfully skipped *** $desc === $reason" 0
|
||||
system restartpending
|
||||
rsv commit
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------------------------------------
|
||||
|
@ -424,7 +483,7 @@ set ::debug 0
|
|||
set logfd stdout
|
||||
|
||||
# validate parameters
|
||||
::schedchk::checkopts $argv
|
||||
checkopts $argv
|
||||
|
||||
# Open log file / use auto logfile
|
||||
if {[info exists ::auto::logfile]} {
|
||||
|
@ -444,7 +503,7 @@ if {![info exists ::auto::logfd]} {
|
|||
# process command
|
||||
switch -- $opt {
|
||||
-rsv { # "scan the recording schedule"
|
||||
::schedchk::rsvscan
|
||||
rsvscan
|
||||
}
|
||||
-h -
|
||||
--help -
|
||||
|
@ -457,8 +516,11 @@ switch -- $opt {
|
|||
puts ""
|
||||
puts "Option Default (unless changed in Settings) "
|
||||
puts "-d 0 = produce detailed debug on Stdout (0, 1, 2) "
|
||||
puts "-test n = produce detailed debug on Stdout (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"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue