diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
commit | 8fcd841aa9af96c8a4a4d3c1a555d2d1ed42332c (patch) | |
tree | cf6466b373236442e63742cb4f73b22579940784 /modules/admin-mini | |
parent | 6abba6163290b58cd9ebae98d8459ac38ef52a4b (diff) |
convert luci.fs users to nixio.fs api
Diffstat (limited to 'modules/admin-mini')
-rw-r--r-- | modules/admin-mini/luasrc/controller/mini/system.lua | 16 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua | 32 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/luci.lua | 11 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/network.lua | 20 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/wifi.lua | 13 |
5 files changed, 50 insertions, 42 deletions
diff --git a/modules/admin-mini/luasrc/controller/mini/system.lua b/modules/admin-mini/luasrc/controller/mini/system.lua index 589e83a84..075f51e91 100644 --- a/modules/admin-mini/luasrc/controller/mini/system.lua +++ b/modules/admin-mini/luasrc/controller/mini/system.lua @@ -98,7 +98,7 @@ function action_upgrade() local function storage_size() local size = 0 - if luci.fs.access("/proc/mtd") then + if nixio.fs.access("/proc/mtd") then for l in io.lines("/proc/mtd") do local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') if n == "linux" then @@ -106,7 +106,7 @@ function action_upgrade() break end end - elseif luci.fs.access("/proc/partitions") then + elseif nixio.fs.access("/proc/partitions") then for l in io.lines("/proc/partitions") do local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)') if b and n and not n:match('[0-9]') then @@ -123,7 +123,7 @@ function action_upgrade() local file luci.http.setfilehandler( function(meta, chunk, eof) - if not luci.fs.access(tmpfile) and not file and chunk and #chunk > 0 then + if not nixio.fs.access(tmpfile) and not file and chunk and #chunk > 0 then file = io.open(tmpfile, "w") end if file and chunk then @@ -139,9 +139,9 @@ function action_upgrade() -- Determine state local keep_avail = true local step = tonumber(luci.http.formvalue("step") or 1) - local has_image = luci.fs.access(tmpfile) + local has_image = nixio.fs.access(tmpfile) local has_support = image_supported() - local has_platform = luci.fs.access("/lib/upgrade/platform.sh") + local has_platform = nixio.fs.access("/lib/upgrade/platform.sh") local has_upload = luci.http.formvalue("image") -- This does the actual flashing which is invoked inside an iframe @@ -182,7 +182,7 @@ function action_upgrade() -- If there is an image but user has requested step 1 -- or type is not supported, then remove it. if has_image then - luci.fs.unlink(tmpfile) + nixio.fs.unlink(tmpfile) end luci.template.render("admin_system/upgrade", { @@ -197,7 +197,7 @@ function action_upgrade() luci.template.render("admin_system/upgrade", { step=2, checksum=image_checksum(), - filesize=luci.fs.stat(tmpfile).size, + filesize=nixio.fs.stat(tmpfile).size, flashsize=storage_size(), keepconfig=(keep_avail and luci.http.formvalue("keepcfg") == "1") } ) @@ -217,7 +217,7 @@ function _keep_pattern() if files then kpattern = "" for k, v in pairs(files) do - if k:sub(1,1) ~= "." and luci.fs.glob(v) then + if k:sub(1,1) ~= "." and nixio.fs.glob(v)() then kpattern = kpattern .. " " .. v end end diff --git a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua index 2aadded3e..5817a93d7 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua @@ -12,9 +12,11 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.model.uci") -require("luci.sys") -require("luci.tools.webadmin") + +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local wa = require "luci.tools.webadmin" +local fs = require "nixio.fs" m = Map("dhcp", "DHCP") @@ -61,12 +63,12 @@ time.rmempty = true m2 = Map("luci_ethers", translate("dhcp_leases")) local leasefn, leasefp, leases -luci.model.uci.cursor():foreach("dhcp", "dnsmasq", +uci:foreach("dhcp", "dnsmasq", function(section) leasefn = section.leasefile end ) -local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn) +local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn) if leasefp then leases = {} for lease in leasefp do @@ -83,9 +85,7 @@ if leases then ltime = v:option(DummyValue, 1, translate("dhcp_timeremain")) function ltime.cfgvalue(self, ...) local value = DummyValue.cfgvalue(self, ...) - return luci.tools.webadmin.date_format( - os.difftime(tonumber(value), os.time()) - ) + return wa.date_format(os.difftime(tonumber(value), os.time())) end end @@ -96,10 +96,12 @@ s.template = "cbi/tblsection" mac = s:option(Value, "macaddr", translate("macaddress")) ip = s:option(Value, "ipaddr", translate("ipaddress")) -for i, dataset in ipairs(luci.sys.net.arptable()) do - ip:value(dataset["IP address"]) - mac:value(dataset["HW address"], - dataset["HW address"] .. " (" .. dataset["IP address"] .. ")") -end - -return m, m2
\ No newline at end of file +sys.net.arptable(function(entry) + ip:value(entry["IP address"]) + mac:value( + entry["HW address"], + entry["HW address"] .. " (" .. entry["IP address"] .. ")" + ) +end) + +return m, m2 diff --git a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua index 0a57b3056..d358c8a0b 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua @@ -12,13 +12,16 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.config") + +require "luci.config" +local fs = require "nixio.fs" + m = Map("luci", translate("webui"), translate("a_i_luci1")) -- force reload of global luci config namespace to reflect the changes function m.commit_handler(self) package.loaded["luci.config"] = nil - require("luci.config") + require "luci.config" end @@ -31,8 +34,8 @@ local i18ndir = luci.i18n.i18ndir .. "default." for k, v in luci.util.kspairs(luci.config.languages) do local file = i18ndir .. k:gsub("_", "-") if k:sub(1, 1) ~= "." and ( - luci.fs.access(file .. ".lua") or - luci.fs.access(file .. ".lua.gz") + fs.access(file .. ".lua") or + fs.access(file .. ".lua.gz") ) then l:value(k, v) end diff --git a/modules/admin-mini/luasrc/model/cbi/mini/network.lua b/modules/admin-mini/luasrc/model/cbi/mini/network.lua index 508bac155..14414e999 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/network.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/network.lua @@ -13,16 +13,16 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.tools.webadmin") -require("luci.sys") -require("luci.fs") +local wa = require "luci.tools.webadmin" +local sys = require "luci.sys" +local fs = require "nixio.fs" -local has_pptp = luci.fs.mtime("/usr/sbin/pptp") -local has_pppoe = luci.fs.glob("/usr/lib/pppd/*/rp-pppoe.so") +local has_pptp = fs.access("/usr/sbin/pptp") +local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() local network = luci.model.uci.cursor_state():get_all("network") -local netstat = luci.sys.net.deviceinfo() +local netstat = sys.net.deviceinfo() local ifaces = {} for k, v in pairs(network) do @@ -41,7 +41,7 @@ hwaddr = s:option(DummyValue, "_hwaddr", translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc")) function hwaddr.cfgvalue(self, section) local ix = self.map:get(section, "ifname") or "" - return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") + return fs.readfile("/sys/class/net/" .. ix .. "/address") or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n") or "n/a" end @@ -59,10 +59,10 @@ function txrx.cfgvalue(self, section) local ix = self.map:get(section, "ifname") local rx = netstat and netstat[ix] and netstat[ix][1] - rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-" + rx = rx and wa.byte_format(tonumber(rx)) or "-" local tx = netstat and netstat[ix] and netstat[ix][9] - tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-" + tx = tx and wa.byte_format(tonumber(tx)) or "-" return string.format("%s / %s", tx, rx) end @@ -150,7 +150,7 @@ pwd:depends("proto", "pptp") -- Allow user to set MSS correction here if the UCI firewall is installed -- This cures some cancer for providers with pre-war routers -if luci.fs.access("/etc/config/firewall") then +if fs.access("/etc/config/firewall") then mssfix = s:option(Flag, "_mssfix", translate("m_n_mssfix"), translate("m_n_mssfix_desc")) mssfix.rmempty = false diff --git a/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua b/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua index ee423f3b4..98f66972a 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua @@ -15,7 +15,10 @@ $Id$ -- Data init -- -local uci = luci.model.uci.cursor() +local fs = require "nixio.fs" +local sys = require "luci.sys" +local uci = require "luci.model.uci".cursor() + if not uci:get("network", "wan") then uci:section("network", "interface", "wan", {proto="none", ifname=" "}) uci:save("network") @@ -24,7 +27,7 @@ end local wlcursor = luci.model.uci.cursor_state() local wireless = wlcursor:get_all("wireless") -local wifidata = luci.sys.wifi.getiwconfig() +local wifidata = sys.wifi.getiwconfig() local wifidevs = {} local ifaces = {} @@ -99,7 +102,7 @@ function scan.write(self, section) m.autoapply = false t2.render = t2._render local ifname = self.map:get(section, "ifname") - luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname)) + luci.util.update(t2.data, sys.wifi.iwscan(ifname)) end t2._render = t2.render @@ -218,8 +221,8 @@ encr:value("none", "No Encryption") encr:value("wep", "WEP") if hwtype == "atheros" or hwtype == "mac80211" then - local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant") - local hostapd = luci.fs.mtime("/usr/sbin/hostapd") + local supplicant = fs.access("/usr/sbin/wpa_supplicant") + local hostapd = fs.access("/usr/sbin/hostapd") if hostapd and supplicant then encr:value("psk", "WPA-PSK") |