[uptime_freebsd] Deprecate synchronous sysctl
This commit is contained in:
parent
df4048da37
commit
2b60a72d06
|
@ -19,7 +19,7 @@ Fixed:
|
||||||
|
|
||||||
- Deprecate the use of `io.popen` in following widgets:
|
- Deprecate the use of `io.popen` in following widgets:
|
||||||
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
||||||
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd
|
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd
|
||||||
* volume, gmail, mdir, mpd, fs
|
* volume, gmail, mdir, mpd, fs
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
|
|
16
helpers.lua
16
helpers.lua
|
@ -21,7 +21,9 @@ local string = {
|
||||||
lower = string.lower,
|
lower = string.lower,
|
||||||
format = string.format,
|
format = string.format,
|
||||||
match = string.match,
|
match = string.match,
|
||||||
|
find = string.find,
|
||||||
}
|
}
|
||||||
|
local table = { concat = table.concat }
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
local assert = assert
|
local assert = assert
|
||||||
local spawn = require("vicious.spawn")
|
local spawn = require("vicious.spawn")
|
||||||
|
@ -263,14 +265,22 @@ end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- {{{ Return result from sysctl variable as table (async)
|
-- {{{ Return result from sysctl variable as table (async)
|
||||||
function helpers.sysctl_async(path, parse)
|
function helpers.sysctl_async(path_table, parse)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
local path = table.concat(path, " ")
|
local path = {}
|
||||||
|
|
||||||
spawn.with_line_callback("sysctl " .. helpers.shellquote(path), {
|
for i=1,#path_table do
|
||||||
|
path[i] = helpers.shellquote(path_table[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
path = table.concat(path, " ")
|
||||||
|
|
||||||
|
spawn.with_line_callback("sysctl " .. path, {
|
||||||
stdout = function(line)
|
stdout = function(line)
|
||||||
|
if not string.find(line, "sysctl: unknown oid") then
|
||||||
local key, value = string.match(line, "(.+): (.+)")
|
local key, value = string.match(line, "(.+): (.+)")
|
||||||
ret[key] = value
|
ret[key] = value
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
output_done = function() parse(ret) end
|
output_done = function() parse(ret) end
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,10 +13,18 @@ function thermal_freebsd.async(format, warg, callback)
|
||||||
if not warg then return callback{} end
|
if not warg then return callback{} end
|
||||||
if type(warg) ~= "table" then warg = { warg } end
|
if type(warg) ~= "table" then warg = { warg } end
|
||||||
|
|
||||||
|
helpers.sysctl_async(warg, function(ret)
|
||||||
local thermals = {}
|
local thermals = {}
|
||||||
|
|
||||||
helpers.sysctl_async(warg, function(ret)
|
for k, v in pairs(ret) do
|
||||||
for i=1, #warg do
|
print(k, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1,#warg do
|
||||||
|
print(warg[i])
|
||||||
|
print(ret[warg[i]])
|
||||||
|
print(ret["hw.acpi.thermal.tz0.temperature"])
|
||||||
|
print(ret['hw.acpi.thermal.tz0.temperature'])
|
||||||
if ret[warg[i]] ~= nil then
|
if ret[warg[i]] ~= nil then
|
||||||
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,17 +14,21 @@ local uptime_freebsd = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Uptime widget type
|
-- {{{ Uptime widget type
|
||||||
local function worker(format)
|
function uptime_freebsd.async(format, warg, callback)
|
||||||
local l1, l5, l15 = string.match(helpers.sysctl("vm.loadavg"), "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
|
helpers.sysctl_async({ "vm.loadavg",
|
||||||
local up_t = os.time() - tonumber(string.match(helpers.sysctl("kern.boottime"), "sec = ([%d]+)"))
|
"kern.boottime" },
|
||||||
|
function(ret)
|
||||||
|
local l1, l5, l15 = string.match(ret["vm.loadavg"], "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
|
||||||
|
local up_t = os.time() - tonumber(string.match(ret["kern.boottime"], "sec = ([%d]+)"))
|
||||||
|
|
||||||
-- Get system uptime
|
-- Get system uptime
|
||||||
local up_d = math.floor(up_t / (3600 * 24))
|
local up_d = math.floor(up_t / (3600 * 24))
|
||||||
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
|
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
|
||||||
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
|
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
|
||||||
|
|
||||||
return {up_d, up_h, up_m, l1, l5, l15}
|
return callback({ up_d, up_h, up_m, l1, l5, l15 })
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(uptime_freebsd, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(uptime_freebsd)
|
||||||
|
|
Loading…
Reference in New Issue