diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-15 15:37:46 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-15 15:37:46 +0100 |
commit | b7f80a98d8b78e259648d820912b7c2338529e0a (patch) | |
tree | c399b203a293f5351d0135f96259a54f6314adb3 | |
parent | 9780ee382e72f8a5fb69e337a3fcc51fc0914883 (diff) |
luci-mod-admin-full: switch to nixio.fs
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
6 files changed, 61 insertions, 66 deletions
diff --git a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua index 5fa4c3a38..9b09e2766 100644 --- a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua +++ b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua @@ -16,13 +16,15 @@ $Id$ module("luci.controller.admin.system", package.seeall) function index() + local fs = require "nixio.fs" + entry({"admin", "system"}, alias("admin", "system", "system"), _("System"), 30).index = true entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1) entry({"admin", "system", "clock_status"}, call("action_clock_status")) entry({"admin", "system", "admin"}, cbi("admin_system/admin"), _("Administration"), 2) - if nixio.fs.access("/bin/opkg") then + if fs.access("/bin/opkg") then entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10) entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg")) end @@ -30,13 +32,13 @@ function index() entry({"admin", "system", "startup"}, form("admin_system/startup"), _("Startup"), 45) entry({"admin", "system", "crontab"}, form("admin_system/crontab"), _("Scheduled Tasks"), 46) - if nixio.fs.access("/etc/config/fstab") then + if fs.access("/etc/config/fstab") then entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), _("Mount Points"), 50) entry({"admin", "system", "fstab", "mount"}, cbi("admin_system/fstab/mount"), nil).leaf = true entry({"admin", "system", "fstab", "swap"}, cbi("admin_system/fstab/swap"), nil).leaf = true end - if nixio.fs.access("/sys/class/leds") then + if fs.access("/sys/class/leds") then entry({"admin", "system", "leds"}, cbi("admin_system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60) end @@ -142,12 +144,11 @@ function action_packages() -- List state local no_lists = true local old_lists = false - local tmp = nixio.fs.dir("/var/opkg-lists/") - if tmp then - for tmp in tmp do + if fs.access("/var/opkg-lists/") then + local list + for list in fs.dir("/var/opkg-lists/") do no_lists = false - tmp = nixio.fs.stat("/var/opkg-lists/"..tmp) - if tmp and tmp.mtime < (os.time() - (24 * 60 * 60)) then + if (fs.stat("/var/opkg-lists/"..list, "mtime") or 0) < (os.time() - (24 * 60 * 60)) then old_lists = true break end @@ -171,15 +172,15 @@ function action_packages() -- Remove index cache if changes then - nixio.fs.unlink("/tmp/luci-indexcache") + fs.unlink("/tmp/luci-indexcache") end end function action_flashops() local sys = require "luci.sys" - local fs = require "luci.fs" + local fs = require "nixio.fs" - local upgrade_avail = nixio.fs.access("/lib/upgrade/platform.sh") + local upgrade_avail = fs.access("/lib/upgrade/platform.sh") local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0 local restore_cmd = "tar -xzC/ >/dev/null 2>&1" @@ -202,7 +203,7 @@ function action_flashops() local function storage_size() local size = 0 - if nixio.fs.access("/proc/mtd") then + if 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" or n == "firmware" then @@ -210,7 +211,7 @@ function action_flashops() break end end - elseif nixio.fs.access("/proc/partitions") then + elseif 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 @@ -270,11 +271,11 @@ function action_flashops() luci.template.render("admin_system/upgrade", { checksum = image_checksum(), storage = storage_size(), - size = nixio.fs.stat(image_tmp).size, + size = (fs.stat(image_tmp, "size") or 0), keep = (not not luci.http.formvalue("keep")) }) else - nixio.fs.unlink(image_tmp) + fs.unlink(image_tmp) luci.template.render("admin_system/flashops", { reset_avail = reset_avail, upgrade_avail = upgrade_avail, diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/startup.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/startup.lua index fc35f774a..e5dcbbf23 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/startup.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/startup.lua @@ -14,15 +14,14 @@ You may obtain a copy of the License at $Id$ ]]-- -require "luci.fs" -require "luci.sys" -require "luci.util" +local fs = require "nixio.fs" +local sys = require "luci.sys" local inits = { } -for _, name in ipairs(luci.sys.init.names()) do - local index = luci.sys.init.index(name) - local enabled = luci.sys.init.enabled(name) +for _, name in ipairs(sys.init.names()) do + local index = sys.init.index(name) + local enabled = sys.init.enabled(name) if index < 255 then inits["%02i.%s" % { index, name }] = { @@ -62,10 +61,10 @@ end e.write = function(self, section) if inits[section].enabled then inits[section].enabled = false - return luci.sys.init.disable(inits[section].name) + return sys.init.disable(inits[section].name) else inits[section].enabled = true - return luci.sys.init.enable(inits[section].name) + return sys.init.enable(inits[section].name) end end @@ -73,7 +72,7 @@ end start = s:option(Button, "start", translate("Start")) start.inputstyle = "apply" start.write = function(self, section) - luci.sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option }) + sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option }) end restart = s:option(Button, "restart", translate("Restart")) @@ -94,13 +93,13 @@ t.rmempty = true t.rows = 20 function t.cfgvalue() - return luci.fs.readfile("/etc/rc.local") or "" + return fs.readfile("/etc/rc.local") or "" end function f.handle(self, state, data) if state == FORM_VALID then if data.rcs then - luci.fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n")) + fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n")) end end return true diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua index 5e82289bd..21bdea343 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua @@ -13,14 +13,13 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.sys") -require("luci.sys.zoneinfo") -require("luci.tools.webadmin") -require("luci.fs") -require("luci.config") +local sys = require "luci.sys" +local zones = require "luci.sys.zoneinfo" +local fs = require "nixio.fs" +local conf = require "luci.config" local m, s, o -local has_ntpd = luci.fs.access("/usr/sbin/ntpd") +local has_ntpd = fs.access("/usr/sbin/ntpd") m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone.")) m:chain("luci") @@ -48,20 +47,20 @@ o.datatype = "hostname" function o.write(self, section, value) Value.write(self, section, value) - luci.sys.hostname(value) + sys.hostname(value) end o = s:taboption("general", ListValue, "zonename", translate("Timezone")) o:value("UTC") -for i, zone in ipairs(luci.sys.zoneinfo.TZ) do +for i, zone in ipairs(zones.TZ) do o:value(zone[1]) end function o.write(self, section, value) local function lookup_zone(title) - for _, zone in ipairs(luci.sys.zoneinfo.TZ) do + for _, zone in ipairs(zones.TZ) do if zone[1] == title then return zone[2] end end end @@ -69,7 +68,7 @@ function o.write(self, section, value) AbstractValue.write(self, section, value) local timezone = lookup_zone(value) or "GMT0" self.map.uci:set("system", section, "timezone", timezone) - luci.fs.writefile("/etc/TZ", timezone .. "\n") + fs.writefile("/etc/TZ", timezone .. "\n") end @@ -117,9 +116,9 @@ o = s:taboption("language", ListValue, "_lang", translate("Language")) o:value("auto") local i18ndir = luci.i18n.i18ndir .. "base." -for k, v in luci.util.kspairs(luci.config.languages) do +for k, v in luci.util.kspairs(conf.languages) do local file = i18ndir .. k:gsub("_", "-") - if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then + if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then o:value(k, v) end end @@ -134,7 +133,7 @@ end o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design")) -for k, v in pairs(luci.config.themes) do +for k, v in pairs(conf.themes) do if k:sub(1, 1) ~= "." then o:value(v, k) end @@ -196,17 +195,17 @@ if has_ntpd then o.rmempty = false function o.cfgvalue(self) - return luci.sys.init.enabled("sysntpd") + return sys.init.enabled("sysntpd") and self.enabled or self.disabled end function o.write(self, section, value) if value == self.enabled then - luci.sys.init.enable("sysntpd") - luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") + sys.init.enable("sysntpd") + sys.call("env -i /etc/init.d/sysntpd start >/dev/null") else - luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") - luci.sys.init.disable("sysntpd") + sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") + sys.init.disable("sysntpd") end end diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm index 312fd0865..63bb6dc9c 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm @@ -14,7 +14,7 @@ You may obtain a copy of the License at <%- local sys = require "luci.sys" - local fs = require "luci.fs" + local fs = require "nixio.fs" local utl = require "luci.util" local uci = require "luci.model.uci".cursor() local ntm = require "luci.model.network" @@ -86,7 +86,7 @@ You may obtain a copy of the License at return translate("Hermes 802.11b Wireless Controller") -- hostap - elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then + elseif name == "wlan" and fs.stat("/proc/net/hostap/" .. ifname, "type") == "dir" then return translate("Prism2/2.5/3 802.11b Wireless Controller") -- dunno yet diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm index cb6371bfa..17dfd1466 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm @@ -12,13 +12,13 @@ You may obtain a copy of the License at -%> <% - require "luci.fs" - require "luci.tools.status" + local fs = require "nixio.fs" + local util = require "luci.util" + local stat = require "luci.tools.status" - local has_ipv6 = luci.fs.access("/proc/net/ipv6_route") - local has_dhcp = luci.fs.access("/etc/config/dhcp") - local has_wifi = luci.fs.stat("/etc/config/wireless") - has_wifi = has_wifi and has_wifi.size > 0 + local has_ipv6 = fs.access("/proc/net/ipv6_route") + local has_dhcp = fs.access("/etc/config/dhcp") + local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0) local sysinfo = luci.util.ubus("system", "info") or { } local boardinfo = luci.util.ubus("system", "board") or { } @@ -35,7 +35,7 @@ You may obtain a copy of the License at free = 0 } - local has_dsl = luci.fs.stat("/etc/init.d/dsl_control") + local has_dsl = fs.access("/etc/init.d/dsl_control") if luci.http.formvalue("status") == "1" then local ntm = require "luci.model.network".init() @@ -60,9 +60,9 @@ You may obtain a copy of the License at swap = swapinfo, connmax = conn_max, conncount = conn_count, - leases = luci.tools.status.dhcp_leases(), - leases6 = luci.tools.status.dhcp6_leases(), - wifinets = luci.tools.status.wifi_networks() + leases = stat.dhcp_leases(), + leases6 = stat.dhcp6_leases(), + wifinets = stat.wifi_networks() } if wan then @@ -695,13 +695,10 @@ You may obtain a copy of the License at <% end %> <%- - require "luci.util" - require "nixio.fs" - - local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index") - if plugins then + local incdir = util.libpath() .. "/view/admin_status/index/" + if fs.access(incdir) then local inc - for inc in plugins do + for inc in fs.dir(incdir) do if inc:match("%.htm$") then include("admin_status/index/" .. inc:gsub("%.htm$", "")) end diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm index 957604e8a..d6997f837 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm @@ -16,10 +16,10 @@ $Id$ <%- require "luci.sys.iptparser" - require "luci.tools.webadmin" - require "luci.fs" + local wba = require "luci.tools.webadmin" + local fs = require "nixio.fs" - local has_ip6tables = luci.fs.access("/usr/sbin/ip6tables") + local has_ip6tables = fs.access("/usr/sbin/ip6tables") local mode = 4 if has_ip6tables then @@ -28,7 +28,6 @@ $Id$ end local ipt = luci.sys.iptparser.IptParser(mode) - local wba = luci.tools.webadmin local rowcnt = 1 function rowstyle() |