aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-15 03:02:50 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-15 03:02:50 +0100
commit49b1b0972f7db6ef77b459e3010c3b569fa69534 (patch)
tree14205aa46f1ae3c889b9665a9333721576b92bbc
parent7cbf987a2a22d69de6a5194bb7d8c685f8d6b62e (diff)
downloadvicious-legacy-49b1b0972f7db6ef77b459e3010c3b569fa69534.tar.xz
helpers: index subdirectories in pathtotable()
-rw-r--r--helpers.lua18
-rw-r--r--widgets/dio.lua5
2 files changed, 15 insertions, 8 deletions
diff --git a/helpers.lua b/helpers.lua
index 8b6541d..c61468e 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -11,6 +11,7 @@
local pairs = pairs
local io = { open = io.open }
local setmetatable = setmetatable
+local getmetatable = getmetatable
local string = {
upper = string.upper,
format = string.format
@@ -28,14 +29,21 @@ local scroller = {}
-- {{{ Helper functions
-- {{{ Expose path as a Lua table
-function pathtotable(path)
- return setmetatable({},
- { __index = function(_, name)
- local f = io.open(path .. '/' .. name)
+function pathtotable(dir)
+ return setmetatable({ _path = dir },
+ { __index = function(table, index)
+ local path = table._path .. '/' .. index
+ local f = io.open(path)
if f then
local s = f:read("*all")
f:close()
- return s
+ if s then
+ return s
+ else
+ local o = { _path = path }
+ setmetatable(o, getmetatable(table))
+ return o
+ end
end
end
})
diff --git a/widgets/dio.lua b/widgets/dio.lua
index 64a56e1..e886dac 100644
--- a/widgets/dio.lua
+++ b/widgets/dio.lua
@@ -28,7 +28,6 @@ local function worker(format, disk)
local disk_lines = { [disk] = {} }
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
- local disk_queue = helpers.pathtotable("/sys/block/" .. disk .. "/queue")
if disk_stats.stat then
local match = string.gmatch(disk_stats.stat, "[%s]+([%d]+)")
@@ -62,8 +61,8 @@ local function worker(format, disk)
helpers.uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3], unit)
-- Store I/O scheduler
- if disk_queue.scheduler then
- disk_usage[disk]["{sched}"] = string.gmatch(disk_queue.scheduler, "%[([%a]+)%]")
+ if disk_stats.queue.scheduler then
+ disk_usage[disk]["{sched}"] = string.gmatch(disk_stats.queue.scheduler, "%[([%a]+)%]")
end
return disk_usage[disk]