webif/var/mongoose/lib/system.class
hummypkg 9a72e40c03 improve system busy detection
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@424 2a923420-c742-0410-a762-8d5b09965624
2011-09-26 20:31:17 +00:00

103 lines
2.1 KiB
Plaintext

if {![exists -proc class ]} { package require oo }
if {![exists -proc sqlite3.open ]} { package require sqlite3 }
class system {}
proc {system model} {} {
if {[catch {set fp [open /etc/model r]}]} {
set model {HD[R]}
} else {
set model [string trim [read $fp]]
close $fp
}
return $model
}
proc {system hostname} {} {
if {[catch {set hostname [string trim [exec hostname]]}]} {
set hostname "humax"
}
return $hostname
}
proc {system modversion} {} {
if {[catch {set fp [open /etc/modversion r]}]} {
set modver "1.02"
} else {
set modver [string trim [read $fp]]
close $fp
}
lassign [split $modver ""] a b c
return [format "%d.%d%d" $a $b $c]
}
proc {system pkgver} {{pkg webif}} {
return [lrange [split [exec opkg list-installed $pkg] " "] 2 end]
}
proc {system diskspace} {} {
switch [system model] {
HDR { set part /mnt/hd2 }
HD { set part /media/drive1 }
}
set size 0
set used 0
set perc 0
foreach line [split [exec /mod/bin/busybox/df -h $part 2>>/dev/null] "\n\r"] {
if {[string match "/*" $line]} {
regsub -all -- {[[:space:]]+} $line " " line
set fields [split $line]
set size [lindex $fields 1]
set used [lindex $fields 2]
set perc [string trimright [lindex $fields 4] "%"]
break
}
}
return [list $size $used $perc]
}
proc {system busy} {} {
# Is humaxtv doing anything important?
set pid [exec /mod/bin/busybox/pgrep humaxtv]
set c 0
foreach line [split [exec /mod/bin/lsof -p $pid] "\n"] {
if {[string match {*Video*.ts} $line]} { incr c }
}
if {$c > 0} { return 1 }
return 0
}
proc {system reboot} {} {
exec /etc/init.d/S90settop shut
exec /sbin/reboot
}
proc {system restartpending} {} {
close [open /tmp/.restartpending w]
}
proc {system padding} {} {
set start 0
set stop 0
if {[catch {set db [sqlite3.open /var/lib/humaxtv/setup.db]} msg]} {
return {0 0}
}
foreach l [$db query "
select itemName, itemValue
from TBL_MENUCONFIG
where itemName in ('START_PADDING_TIME', 'STOP_PADDING_TIME')
"] {
lassign $l x name x val
switch $name {
"START_PADDING_TIME" { set start $val }
"STOP_PADDING_TIME" { set stop $val }
}
}
$db close
return [list $start $stop]
}