pkg improvements

git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2615 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2016-02-10 23:41:02 +00:00
parent f4afecf77c
commit e1a5bb3998
5 changed files with 154 additions and 25 deletions

View File

@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
Version: 1.2.8
Version: 1.2.8-1
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.1.18),lighttpd(>=1.4.39-1),jim(>=0.76),jim-oo,jim-sqlite3(>=0.76),jim-cgi(>=0.7),jim-binary(>=0.76),service-control(>=2.1),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.1),hmt(>=2.0.9),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7)

View File

@ -8,8 +8,9 @@ if {[[settings] pkgdev]} { set filter 0 } else { set filter 1 }
httpheader
proc pkgrow {pkg} {
set name [$pkg get name]
set pkgdata [pkg getall]
proc pkgrow {name pkg} {
altrow "pkg=\"$name\""
puts "<td nowrap>$name"
if {$::type eq "inst"} {
@ -21,29 +22,30 @@ proc pkgrow {pkg} {
puts "</td>"
if {$::type eq "avail"} {
puts "<td nowrap>[$pkg get latest]</td>"
puts "<td nowrap>$pkg(version)</td>"
} else {
puts "<td nowrap>[$pkg get installed]</td>"
puts "<td nowrap>$pkg(installed)</td>"
}
if {$::type eq "upgr"} {
puts "<td nowrap>[$pkg get latest]</td>"
puts "<td nowrap>$pkg(version)</td>"
}
puts "<td>"
set descr $pkg(description)
set changes ""
regexp {(.*) \[(.*)\]} $descr x descr changes
if {[dict exists $::pkgmeta $name]} {
puts "$::pkgmeta($name)"
puts $::pkgmeta($name)
} else {
puts "[$pkg get descr]"
puts $descr
}
if {$::type eq "upgr"} {
$pkg loadraw
set url [$pkg get url]
set changes [$pkg get changes]
if {$changes ne ""} {
puts "<br>&nbsp;&nbsp;-&nbsp;<i>$changes</i>"
}
if {$url ne ""} {
if {[dict exists $pkg tags]} {
set url $pkg(tags)
puts "
<br>
<a class=va href=\"$url\" target=_blank style=\"color: darkblue\">
@ -53,17 +55,27 @@ proc pkgrow {pkg} {
}
puts "</td>"
if {![$pkg is installed]} {
if {$pkg(installed) eq "0"} {
set type Install
} elseif {$::type eq "upgr" && [$pkg is upgradable]} {
set type Upgrade
} elseif {$::type eq "upgr" && $pkg(installed) ne $pkg(version)} {
if {[pkg vercompare $pkg(version) $pkg(installed)] == 1} {
set type Upgrade
} else {
set type ""
}
} else {
set type Remove
}
puts "<td align=center><small><button id=\"$name\"
action=[string tolower $type]
class=\"va [string tolower $type]\">$type</button></small></td>"
puts "<td align=center>"
if {$type ne ""} {
puts "<small><button id=\"$name\"
action=[string tolower $type]
class=\"va [string tolower $type]\">$type</button></small>"
} else {
puts "<i>Newer</i>"
}
puts "</td>"
puts "</tr>"
}
@ -72,7 +84,29 @@ pkg loadmeta
set type [cgi_get type "avail"]
set pkgs [pkg $type]
set pkgs {}
foreach {pkg data} $pkgdata {
switch $type {
avail {
if {$data(installed) eq "0"} {
lappend pkgs $pkg
}
}
inst {
if {$data(installed) ne "0"} {
lappend pkgs $pkg
}
}
upgr {
if {$data(installed) ne "0" && \
$data(installed) ne $data(version)} {
lappend pkgs $pkg
}
}
}
}
#set pkgs [pkg $type]
if {[llength $pkgs] > 0} {
puts "<table><tr><th>Package</th>"
@ -95,8 +129,9 @@ if {[llength $pkgs] > 0} {
foreach pkg $pkgs {
if {$type ne "upgr" && $filter && \
![dict exists $::pkgmeta $pkg]} { continue }
pkgrow [pkg load $pkg]
![dict exists $::pkgmeta $pkg]} continue
if {![dict exists $pkgdata $pkg]} continue
pkgrow $pkg $pkgdata($pkg)
}
puts "</table>"
if {$type ne "upgr" && $filter} {

View File

@ -31,6 +31,59 @@ pkg method _load {nm} {
return $self
}
proc {pkg getall} {{repo base}} {
set pkglist {}
# Fetch details of installed packages
foreach line [split [exec /bin/opkg list-installed] "\n"] {
lassign $line pkg x ver
#regexp {^([^ ]+) - ([^ ]+)$} $line pkg x ver
set installed($pkg) $ver
}
# Now build list of all packages
if {[catch { set fp [open "/mod/var/opkg/$repo" r] } msg]} {
error "Error opening repository, $msg"
}
set cur ""
set pkg {}
foreach line [split [$fp read] "\n"] {
if {![regexp {^([^:]+): (.*)$} $line x tag val]} {
if {[string equal -length 1 $line " "]} {
# Continuation
if {$lasttag ne ""} {
append pkg($lasttag) " \
[string trim $line]"
}
}
continue
}
set tag [string tolower $tag]
if {$tag eq "package"} {
if {$pkg ne ""} {
set pkglist($name) $pkg
}
set name $val
if {[dict exists $installed $val]} {
set pkg "installed $installed($val)"
} else {
set pkg {installed 0}
}
set lasttag ""
continue
}
set lasttag $tag
set pkg($tag) $val
}
$fp close
if {$pkg ne ""} {
set pkglist($name) $pkg
}
return $pkglist
}
pkg method loadraw {} {
set tag ""
set txt ""
@ -175,3 +228,18 @@ proc {pkg upgrade} {nm} {
exec /bin/opkg upgrade $nm
}
proc {pkg vercompare} {v1 v2} {
if {$v1 eq $v2} { return 0 }
lassign [split $v1 -] v1 r1
lassign [split $v2 -] v2 r2
foreach a [split $v1 .] b [split $v2 .] {
if {$b eq "" || $a > $b} { return 1 }
if {$a eq "" || $a < $b} { return -1 }
}
if {$r2 eq "" || $r1 > $r2} { return 1 }
if {$r1 eq "" || $r2 > $r1} { return -1 }
return 0
}

View File

@ -3,17 +3,17 @@ if {![exists -proc class]} { package require oo }
if {![exists -proc sqlite3.open]} { package require sqlite3 }
if {![file exists /mod/etc/webif.db]} {
set settingsdb [sqlite3.open /mod/etc/webif.db]
set ::settingsdb [sqlite3.open /mod/etc/webif.db]
catch {
$settingsdb query {
$::settingsdb query {
CREATE TABLE settings(name text, nval int, tval text);
}
$settingsdb query {
$::settingsdb query {
CREATE UNIQUE INDEX key on settings(name);
}
}
} else {
set settingsdb [sqlite3.open /mod/etc/webif.db]
set ::settingsdb [sqlite3.open /mod/etc/webif.db]
}
class settings {

26
webif/lib/test/pkgver Executable file
View File

@ -0,0 +1,26 @@
#!/mod/bin/jimsh
source /mod/webif/lib/setup
require pkg.class
set verlist {
1.0.0 1.0.1 -1
1.0.1 1.0.0 1
1.0.2 1.0.2 0
1.0 1.0.1 -1
1.0.1 1.0 1
1.0-1 1.0 1
1.0 1.0-1 -1
2 1.0.1 1
}
foreach {a b e} $verlist {
set ret [pkg vercompare $a $b]
if {$ret eq $e} {
puts " OK $a $b ($e)"
} else {
puts "BAD $a $b ($e)"
}
}