modules/admin-full: merge rewritten package management from luci-0.9

This commit is contained in:
Jo-Philipp Wich 2010-04-18 22:55:59 +00:00
parent dc9394f94d
commit cde6e129d4
2 changed files with 129 additions and 106 deletions

View file

@ -41,10 +41,10 @@ end
function action_packages() function action_packages()
local ipkg = require("luci.model.ipkg") local ipkg = require("luci.model.ipkg")
local void = nil
local submit = luci.http.formvalue("submit") local submit = luci.http.formvalue("submit")
local changes = false local changes = false
local install = { }
local remove = { }
-- Search query -- Search query
local query = luci.http.formvalue("query") local query = luci.http.formvalue("query")
@ -52,33 +52,30 @@ function action_packages()
-- Packets to be installed -- 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 -- Install from URL
local url = luci.http.formvalue("url") local url = luci.http.formvalue("url")
if url and url ~= '' and submit then if url and url ~= '' and submit then
if not install then uinst = url
install = {}
end
install[url] = 1
changes = true
end end
-- Do install -- Do install
if install then if ninst then
for k, v in pairs(install) do _, install[ninst] = ipkg.install(ninst)
void, install[k] = ipkg.install(k)
end
changes = true changes = true
end end
if uinst then
_, install[uinst] = ipkg.install(uinst)
changes = true
end
-- Remove packets -- Remove packets
local remove = submit and luci.http.formvaluetable("remove") local rem = submit and luci.http.formvalue("remove")
if remove then if rem then
for k, v in pairs(remove) do _, remove[rem] = ipkg.remove(rem)
void, remove[k] = ipkg.remove(k)
end
changes = true changes = true
end end
@ -86,44 +83,20 @@ function action_packages()
-- Update all packets -- Update all packets
local update = luci.http.formvalue("update") local update = luci.http.formvalue("update")
if update then if update then
void, update = ipkg.update() _, update = ipkg.update()
end end
-- Upgrade all packets -- Upgrade all packets
local upgrade = luci.http.formvalue("upgrade") local upgrade = luci.http.formvalue("upgrade")
if upgrade then if upgrade then
void, upgrade = ipkg.upgrade() _, upgrade = ipkg.upgrade()
end end
-- Package info luci.template.render("admin_system/packages", {
local info = luci.model.ipkg.info(query and "*"..query.."*") query=query, install=install, remove=remove, update=update, upgrade=upgrade
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})
-- Remove index cache -- Remove index cache
if changes then if changes then

View file

@ -1,7 +1,7 @@
<%# <%#
LuCI - Lua Configuration Interface LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org> Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,6 +14,9 @@ $Id$
-%> -%>
<%- <%-
local bit = require "bit" local bit = require "bit"
local opkg = require "luci.model.ipkg"
local fs = require "nixio.fs"
local wa = require "luci.tools.webadmin"
local rowcnt = 1 local rowcnt = 1
function rowstyle() function rowstyle()
@ -25,30 +28,18 @@ function opkg_error(code)
code = bit.rshift(tonumber(code), 8) code = bit.rshift(tonumber(code), 8)
return translate("OPKG error code %i" % code) return translate("OPKG error code %i" % code)
end 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%> <%+header%>
<h2><a id="content" name="content"><%:System%></a></h2> <h2><a id="content" name="content"><%:System%> - <%:Software%></a></h2>
<h3><%:Software%></h3>
<br />
<% if install or remove or update or upgrade then %>
<div class="code"><strong><%:Status%>:</strong><br />
<% if update then %>
<%:Package lists updated%>: <% if update == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(update)%>)</span><% end %><br />
<% end %>
<% if upgrade then%>
<%:Upgrade installed packages%>: <% if upgrade == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(upgrade)%>)</span><% end %><br />
<% end %>
<% if install then for k,v in pairs(install) do %>
<%:Install%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
<% end end %>
<% if remove then for k,v in pairs(remove) do %>
<%:Remove%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
<% end end %>
</div>
<br />
<% end %>
<form method="post" action="<%=REQUEST_URI%>"> <form method="post" action="<%=REQUEST_URI%>">
<div class="cbi-map"> <div class="cbi-map">
@ -59,47 +50,106 @@ end
</ul> </ul>
<br /> <br />
<fieldset class="cbi-section-node"> <fieldset class="cbi-section-node">
<div class="cbi-value"> <div class="cbi-value">
<label class="cbi-value-title"><%:Download and install package%>:</label> <label class="cbi-value-title"><%:Download and install package%>:</label>
<div class="cbi-value-field"> <div class="cbi-value-field">
<input type="text" name="url" size="30" value="" /> <input type="text" name="url" size="30" value="" />
<input class="cbi-input-save" type="submit" name="submit" value="<%:OK%>" /> <input class="cbi-input-save" type="submit" name="submit" value="<%:OK%>" />
</div>
</div> </div>
<div class="cbi-value">
<label class="cbi-value-title"><%:Filter%>:</label>
<div class="cbi-value-field">
<input type="text" name="query" size="20" value="<%=query%>" />
<input type="submit" class="cbi-input-find" name="search" value="<%:Find package%>" />
</div>
</div>
</fieldset>
</fieldset>
<br />
<h3><%:Status%></h3>
<fieldset class="cbi-section">
<%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
<div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
<div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&nbsp;</div>
</div> </div>
<div class="cbi-value"> <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
<label class="cbi-value-title"><%:Filter%>:</label> <br /><hr /><br />
<div class="cbi-value-field"> <% if update then %>
<input type="text" name="query" size="20" value="<%=query%>" /> <%:Package lists updated%>: <% if update == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(update)%>)</span><% end %><br />
<input type="submit" class="cbi-input-find" name="search" value="<%:Find package%>" /> <% end %>
</div> <% if upgrade then%>
</div> <%:Upgrade installed packages%>: <% if upgrade == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(upgrade)%>)</span><% end %><br />
<% end %>
<% if install then for k,v in pairs(install) do %>
<%:Install%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
<% end end %>
<% if remove then for k,v in pairs(remove) do %>
<%:Remove%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
<% end end %>
<% end %>
</fieldset>
<br />
<table class="cbi-section-table"> <h3><%:Installed packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %></h3>
<fieldset class="cbi-section">
<table class="cbi-section-table" style="width:100%">
<tr class="cbi-section-table-titles"> <tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"><%:Package name%></th> <th class="cbi-section-table-cell" style="text-align:left">&nbsp;</th>
<th class="cbi-section-table-cell"><%:Version%></th> <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
<th class="cbi-section-table-cell"><%:Install%></th> <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
<th class="cbi-section-table-cell"><%:Delete%></th>
<th class="cbi-section-table-cell"><%:Description%></th>
</tr> </tr>
<% for k, pkg in pairs(pkgs) do %> <% local empty = true; luci.model.ipkg.list_installed(query, function(n, v, d) empty = false %>
<tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>"> <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
<td><%=luci.util.pcdata(pkg.Package)%></td> <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Remove%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;remove=<%=luci.util.pcdata(n)%>"><%:Remove%></a></td>
<td><%=luci.util.pcdata(pkg.Version)%></td> <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
<td><% if not pkg.Status or not pkg.Status.installed then %><input type="checkbox" name="install.<%=pkg.Package%>" value="1" /><% else %><%:installed%><% end %></td> <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
<td><% if pkg.Status and pkg.Status.installed then %><input type="checkbox" name="remove.<%=pkg.Package%>" value="1" /><% else %><%:not installed%><% end %></td> </tr>
<td><%=luci.util.pcdata(pkg.Description)%></td> <% end) %>
<% if empty then %>
<tr class="cbi-section-table-row">
<td style="text-align:left">&nbsp;</td>
<td style="text-align:left"><em><%:none%></em></td>
<td style="text-align:left"><em><%:none%></em></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
</fieldset>
<br />
<br />
<div style="text-align: right"> <h3><%:Available packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %></h3>
<input type="submit" class="cbi-input-apply" name="submit" value="<%:Perform Actions%>" />
</div> <fieldset class="cbi-section">
</fieldset></fieldset> <table class="cbi-section-table" style="width:100%">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell" style="text-align:left">&nbsp;</th>
<th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
<th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
<th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
</tr>
<% local empty = true; luci.model.ipkg.list_all(query, function(n, v, d) empty = false %>
<tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
<td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Install%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;install=<%=luci.util.pcdata(n)%>"><%:Install%></a></td>
<td style="text-align:left"><%=luci.util.pcdata(n)%></td>
<td style="text-align:left"><%=luci.util.pcdata(v)%></td>
<td style="text-align:left"><%=luci.util.pcdata(d)%></td>
</tr>
<% end) %>
<% if empty then %>
<tr class="cbi-section-table-row">
<td style="text-align:left">&nbsp;</td>
<td style="text-align:left"><em><%:none%></em></td>
<td style="text-align:left"><em><%:none%></em></td>
<td style="text-align:left"><em><%:none%></em></td>
</tr>
<% end %>
</table>
</fieldset>
</div> </div>
</form> </form>
<%+footer%> <%+footer%>