From: Jo-Philipp Wich Date: Sun, 18 Apr 2010 22:55:59 +0000 (+0000) Subject: modules/admin-full: merge rewritten package management from luci-0.9 X-Git-Tag: 0.10.0~709 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cde6e129d4759e7a5089b8779c416b1a85206217;p=oweals%2Fluci.git modules/admin-full: merge rewritten package management from luci-0.9 --- diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua index d420b2427..d3afead40 100644 --- a/modules/admin-full/luasrc/controller/admin/system.lua +++ b/modules/admin-full/luasrc/controller/admin/system.lua @@ -41,90 +41,63 @@ end function action_packages() local ipkg = require("luci.model.ipkg") - local void = nil local submit = luci.http.formvalue("submit") local changes = false - - + local install = { } + local remove = { } + -- Search query local query = luci.http.formvalue("query") query = (query ~= '') and query or nil -- Packets to be installed - local install = submit and luci.http.formvaluetable("install") - + local ninst = submit and luci.http.formvalue("install") + local uinst = nil + -- Install from URL local url = luci.http.formvalue("url") if url and url ~= '' and submit then - if not install then - install = {} - end - install[url] = 1 - changes = true + uinst = url end - + -- Do install - if install then - for k, v in pairs(install) do - void, install[k] = ipkg.install(k) - end + if ninst then + _, install[ninst] = ipkg.install(ninst) changes = true end - - + + if uinst then + _, install[uinst] = ipkg.install(uinst) + changes = true + end + -- Remove packets - local remove = submit and luci.http.formvaluetable("remove") - if remove then - for k, v in pairs(remove) do - void, remove[k] = ipkg.remove(k) - end + local rem = submit and luci.http.formvalue("remove") + if rem then + _, remove[rem] = ipkg.remove(rem) changes = true end - + -- Update all packets local update = luci.http.formvalue("update") if update then - void, update = ipkg.update() + _, update = ipkg.update() end -- Upgrade all packets local upgrade = luci.http.formvalue("upgrade") if upgrade then - void, upgrade = ipkg.upgrade() + _, upgrade = ipkg.upgrade() end + - - -- Package info - local info = luci.model.ipkg.info(query and "*"..query.."*") - info = info or {} - local pkgs = {} - - -- Sort after status and name - for k, v in pairs(info) do - local x = 0 - for i, j in pairs(pkgs) do - local vins = (v.Status and v.Status.installed) - local jins = (j.Status and j.Status.installed) - if vins ~= jins then - if vins then - break - end - else - if j.Package > v.Package then - break - end - end - x = i - end - table.insert(pkgs, x+1, v) - end - - luci.template.render("admin_system/packages", {pkgs=pkgs, query=query, - install=install, remove=remove, update=update, upgrade=upgrade}) - + luci.template.render("admin_system/packages", { + query=query, install=install, remove=remove, update=update, upgrade=upgrade + }) + -- Remove index cache if changes then nixio.fs.unlink("/tmp/luci-indexcache") diff --git a/modules/admin-full/luasrc/view/admin_system/packages.htm b/modules/admin-full/luasrc/view/admin_system/packages.htm index 0f2f2e2ab..a1a8d698f 100644 --- a/modules/admin-full/luasrc/view/admin_system/packages.htm +++ b/modules/admin-full/luasrc/view/admin_system/packages.htm @@ -1,7 +1,7 @@ <%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich +Copyright 2008-2010 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,6 +14,9 @@ $Id$ -%> <%- local bit = require "bit" +local opkg = require "luci.model.ipkg" +local fs = require "nixio.fs" +local wa = require "luci.tools.webadmin" local rowcnt = 1 function rowstyle() @@ -25,30 +28,18 @@ function opkg_error(code) code = bit.rshift(tonumber(code), 8) return translate("OPKG error code %i" % code) end + +local fstat = fs.statvfs(opkg.overlay_root()) +local space_total = fstat and fstat.blocks or 0 +local space_free = fstat and fstat.bfree or 0 +local space_used = space_total - space_free + +local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100)) +local free_byte = space_free * fstat.frsize + -%> <%+header%> -

<%:System%>

-

<%:Software%>

- -
- -<% if install or remove or update or upgrade then %> -
<%:Status%>:
-<% if update then %> - <%:Package lists updated%>: <% if update == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(update)%>)<% end %>
-<% end %> -<% if upgrade then%> - <%:Upgrade installed packages%>: <% if upgrade == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(upgrade)%>)<% end %>
-<% end %> -<% if install then for k,v in pairs(install) do %> - <%:Install%> '<%=k%>': <% if v == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(v)%>)<% end %>
-<% end end %> -<% if remove then for k,v in pairs(remove) do %> - <%:Remove%> '<%=k%>': <% if v == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(v)%>)<% end %>
-<% end end %> -
-
-<% end %> +

<%:System%> - <%:Software%>

@@ -59,47 +50,106 @@ end
-
- -
- - +
+ +
+ + +
-
-
- -
- - +
+ +
+ + +
+
+ +
+ +

<%:Status%>

+
+ <%:Free space%>: <%=(100-used_perc)%>% (<%=wa.byte_format(free_byte)%>) +
+
 
- + <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %> +


+ <% if update then %> + <%:Package lists updated%>: <% if update == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(update)%>)<% end %>
+ <% end %> + <% if upgrade then%> + <%:Upgrade installed packages%>: <% if upgrade == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(upgrade)%>)<% end %>
+ <% end %> + <% if install then for k,v in pairs(install) do %> + <%:Install%> '<%=k%>': <% if v == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(v)%>)<% end %>
+ <% end end %> + <% if remove then for k,v in pairs(remove) do %> + <%:Remove%> '<%=k%>': <% if v == 0 then %><%:OK%><% else %><%:Error%> (<%=opkg_error(v)%>)<% end %>
+ <% end end %> + <% end %> + +
+ +

<%:Installed packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %>

+ +
+
- - - - - + + + - <% for k, pkg in pairs(pkgs) do %> + <% local empty = true; luci.model.ipkg.list_installed(query, function(n, v, d) empty = false %> - - - - - + + + + + <% end) %> + <% if empty then %> + + + + <% end %>
<%:Package name%><%:Version%><%:Install%><%:Delete%><%:Description%> <%:Package name%><%:Version%>
<%=luci.util.pcdata(pkg.Package)%><%=luci.util.pcdata(pkg.Version)%><% if not pkg.Status or not pkg.Status.installed then %><% else %><%:installed%><% end %><% if pkg.Status and pkg.Status.installed then %><% else %><%:not installed%><% end %><%=luci.util.pcdata(pkg.Description)%><%:Remove%><%=luci.util.pcdata(n)%><%=luci.util.pcdata(v)%>
 <%:none%><%:none%>
+
+
-
-
- -
- +

<%:Available packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %>

+ +
+ + + + + + + + <% local empty = true; luci.model.ipkg.list_all(query, function(n, v, d) empty = false %> + + + + + + + <% end) %> + <% if empty then %> + + + + + + + <% end %> +
 <%:Package name%><%:Version%><%:Description%>
<%:Install%><%=luci.util.pcdata(n)%><%=luci.util.pcdata(v)%><%=luci.util.pcdata(d)%>
 <%:none%><%:none%><%:none%>
+
<%+footer%>