modularise schedule/backup restore. Fix bug in reset new

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1709 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2013-10-26 11:05:47 +00:00
parent a505022d39
commit 8dc232646b
7 changed files with 191 additions and 169 deletions

View File

@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
Version: 1.0.7-2
Version: 1.0.7-3
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.1.4),mongoose(>=3.0-9),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73-1),jim-cgi(>=0.7),jim-binary,service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.13),hmt(>=1.1.14),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.2.3),smartmontools,tmenu(>=1.05),ffmpeg,id3v2,multienv(>=1.6)

View File

@ -5,7 +5,7 @@ source /mod/webif/lib/setup
require rsv.class
set dir /mod/var/backup
set dir "/mod/var/backup"
httpheader
@ -26,58 +26,12 @@ if {[string match {auto-*} $file]} {
}
}
set ffile "/$dir/$file.rbk"
set ffile "$dir/$file.rbk"
if {[file exists $ffile]} {
puts "Backup file <i>$file</i> already exists."
exit
}
if {[catch { set fd [open $ffile w] } msg]} {
puts "Error creating backup file. - $msg"
exit
}
puts "Backing up scheduled recordings and events..."
set events [rsv list]
set fields [lsort [[rsv] vars]]
#puts $fd "# [join $fields "\t"]"
foreach event $events {
puts " Backing up scheduled event '[$event name]'"
puts -nonewline $fd "event\t"
foreach f $fields {
if {$f eq "aulEventToRecordInfo"} { continue }
puts -nonewline $fd "[$event get $f]\t"
}
puts $fd ""
}
puts "Done."
puts "Backing up channel favourites..."
set grp 0
foreach res [$rsvdb query {
select eFavGroup,
TBL_FAV.eSvcType,
substr(szSvcName, 2) as szSvcName,
favIdx
from TBL_FAV join TBL_SVC using (hSvc)
order by eFavGroup, favIdx
}] {
if {$res(eFavGroup) != $grp} {
set grp $res(eFavGroup)
puts " Group $grp"
}
puts " $res(szSvcName)"
puts $fd "fav\t$res(eFavGroup)\t$res(eSvcType)\t$res(szSvcName)\t$res(favIdx)"
}
puts "Done."
close $fd
rsv cleanup
rsv backup $ffile

View File

@ -3,9 +3,9 @@
package require cgi
source /mod/webif/lib/setup
require rsv.class findhsvc system.class
require rsv.class
set dir /mod/var/backup
set dir "/mod/var/backup"
httpheader
@ -15,121 +15,7 @@ if {$file == 0} {
exit
}
set ffile "/$dir/$file.rbk"
set ffile "$dir/$file.rbk"
if {![file exists $ffile]} {
puts "Backup file <i>$file</i> does not exist."
exit
}
if {[catch { set fd [open $ffile r] } msg]} {
puts "Error opening <i>$file</i> - $msg"
exit
}
puts "Restoring scheduled events from <i>$file</i>..."
$rsvdb query {begin transaction;}
$rsvdb query {delete from TBL_RESERVATION;}
set fields [lsort [[rsv] vars]]
set data [split [read $fd] "\n"]
foreach line $data {
set vals [split $line "\t"]
if {[lindex $vals 0] ne "event"} { continue }
set vars {}
set i 0
foreach f $fields {
if {$f eq "aulEventToRecordInfo"} { continue }
incr i
lappend vars $f [lindex $vals $i]
}
# Don't restore DSO events.
if {$vars(ersvtype) == 11} { continue }
set rsv [rsv new $vars]
# Need to fix up channel and CRID mappings in case something has
# changed during a channel scan.
puts " Restoring [$rsv name]"
set bad 0
# First, the service number
set ohsvc [$rsv get hsvc]
if {$ohsvc > 0} {
set hsvc [$rsv fix_hsvc]
if {$hsvc == 0} {
puts " Cannot find channel, restore failed."
set bad 1
} elseif {$hsvc != $ohsvc} {
puts -nonewline " Service number has "
puts "changed $ohsvc -> $hsvc, fixing."
} else {
puts " No change in channel service."
}
}
if {!$bad} {
if {[catch {$rsv insert pending 1} msg]} {
puts " Error inserting event, $msg"
}
}
}
$rsvdb query {commit transaction;}
puts "Restoring favourite channels..."
$rsvdb query {begin transaction;}
$rsvdb query {delete from channel.TBL_FAV}
$rsvdb query {drop table if exists pending.fav}
$rsvdb query {create table pending.fav (
favIdx integer primary key autoincrement unique,
hSvc integer(4),
eFavGroup integer(4),
[eSvcType] integer(4)
)}
set grp 0
foreach line $data {
set vals [split $line "\t"]
if {[lindex $vals 0] ne "fav"} { continue }
set group [lindex $vals 1]
set type [lindex $vals 2]
set chan [lindex $vals 3]
set idx [lindex $vals 4]
if {$idx eq ""} { set idx 0 }
set hsvc [get_channel_attr $chan]
if {$grp != $group} {
set grp $group
puts " Group $grp"
}
puts " $chan"
if {$hsvc eq ""} {
puts " Cannot map channel name to service."
continue
}
set query "
insert into pending.fav(favIdx, hSvc, eFavGroup, eSvcType)
values($idx, $hsvc, $group, $type);
"
$rsvdb query $query
}
$rsvdb query {commit transaction;}
system restartpending
close $fd
rsv cleanup
rsv restore $ffile

View File

@ -1,6 +1,6 @@
if {![exists -proc get_channel_attr]} {
require rsv.class
if {![exists -proc rsv]} { require rsv.class }
proc get_channel_attr {channel {field hSvc}} {
global rsvdb

View File

@ -499,3 +499,172 @@ proc {rsv construct} {event type} {
return [rsv new $args]
}
proc {rsv backup} {file} {
global rsvdb
if {[catch { set fd [open $file w] } msg]} {
error "Error creating backup file. - $msg"
}
puts "Backing up scheduled recordings and events..."
set events [rsv list]
set fields [lsort [[rsv] vars]]
#puts $fd "# [join $fields "\t"]"
foreach event $events {
puts " Backing up scheduled event '[$event name]'"
puts -nonewline $fd "event\t"
foreach f $fields {
if {$f eq "aulEventToRecordInfo"} { continue }
puts -nonewline $fd "[$event get $f]\t"
}
puts $fd ""
}
puts "Done."
puts "Backing up channel favourites..."
set grp 0
foreach res [$rsvdb query {
select eFavGroup,
TBL_FAV.eSvcType,
substr(szSvcName, 2) as szSvcName,
favIdx
from TBL_FAV join TBL_SVC using (hSvc)
order by eFavGroup, favIdx
}] {
if {$res(eFavGroup) != $grp} {
set grp $res(eFavGroup)
puts " Group $grp"
}
puts " $res(szSvcName)"
puts $fd "fav\t$res(eFavGroup)\t$res(eSvcType)\t$res(szSvcName)\t$res(favIdx)"
}
puts "Done."
close $fd
}
proc {rsv restore} {file} {
global rsvdb
require findhsvc
if {![file exists $file]} {
error "Backup file <i>$file</i> does not exist."
}
if {[catch { set fd [open $file r] } msg]} {
error "Error opening <i>$file</i> - $msg"
}
puts "Restoring scheduled events from <i>$file</i>..."
$rsvdb query {begin transaction;}
$rsvdb query {delete from TBL_RESERVATION;}
set fields [lsort [[rsv] vars]]
set data [split [read $fd] "\n"]
foreach line $data {
set vals [split $line "\t"]
if {[lindex $vals 0] ne "event"} { continue }
set vars {}
set i 0
foreach f $fields {
if {$f eq "aulEventToRecordInfo"} { continue }
incr i
lappend vars $f [lindex $vals $i]
}
# Don't restore DSO events.
if {$vars(ersvtype) == 11} { continue }
set rsv [rsv new $vars]
# Need to fix up channel and CRID mappings in case something
# has changed during a channel scan.
puts " Restoring [$rsv name]"
set bad 0
# First, the service number
set ohsvc [$rsv get hsvc]
if {$ohsvc > 0} {
set hsvc [$rsv fix_hsvc]
if {$hsvc == 0} {
puts " Cannot find channel, restore failed."
set bad 1
} elseif {$hsvc != $ohsvc} {
puts -nonewline " Service number has "
puts "changed $ohsvc -> $hsvc, fixing."
} else {
puts " No change in channel service."
}
}
if {!$bad} {
if {[catch {$rsv insert pending 1} msg]} {
puts " Error inserting event, $msg"
}
}
}
$rsvdb query {commit transaction;}
puts "Restoring favourite channels..."
$rsvdb query {begin transaction;}
$rsvdb query {delete from channel.TBL_FAV}
$rsvdb query {drop table if exists pending.fav}
$rsvdb query {create table pending.fav (
favIdx integer primary key autoincrement unique,
hSvc integer(4),
eFavGroup integer(4),
[eSvcType] integer(4)
)}
set grp 0
foreach line $data {
set vals [split $line "\t"]
if {[lindex $vals 0] ne "fav"} { continue }
set group [lindex $vals 1]
set type [lindex $vals 2]
set chan [lindex $vals 3]
set idx [lindex $vals 4]
if {$idx eq ""} { set idx 0 }
set hsvc [get_channel_attr $chan]
if {$grp != $group} {
set grp $group
puts " Group $grp"
}
puts " $chan"
if {$hsvc eq ""} {
puts " Cannot map channel name to service."
continue
}
set query "
insert into
pending.fav(favIdx, hSvc, eFavGroup, eSvcType)
values($idx, $hsvc, $group, $type);
"
$rsvdb query $query
}
$rsvdb query {commit transaction;}
system restartpending
close $fd
}

View File

@ -275,3 +275,11 @@ proc {system notify} {msg} {
$logfd close
}
proc {system display} {hdr hd} {
if {[system model] eq "HDR"} {
exec /sbin/display $hdr
} else {
exec /sbin/display "\$$hd"
}
}

View File

@ -352,6 +352,11 @@ proc {ts resetnew} {dir} {
}
}
if {!$tot} {
file delete "$dir/.series"
return
}
set fd [open "$dir/.series"]
set bytes [read $fd]
close $fd