[thermal_freebsd] Deprecate synchronous sysctl
This commit is contained in:
parent
ca075d0c8e
commit
df4048da37
|
@ -19,7 +19,7 @@ Fixed:
|
|||
|
||||
- Deprecate the use of `io.popen` in following widgets:
|
||||
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
||||
* bat_freebsd, mem_freebsd, net_freebsd
|
||||
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd
|
||||
* volume, gmail, mdir, mpd, fs
|
||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||
|
|
19
helpers.lua
19
helpers.lua
|
@ -19,10 +19,12 @@ local getmetatable = getmetatable
|
|||
local string = {
|
||||
upper = string.upper,
|
||||
lower = string.lower,
|
||||
format = string.format
|
||||
format = string.format,
|
||||
match = string.match,
|
||||
}
|
||||
local pcall = pcall
|
||||
local assert = assert
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -260,6 +262,21 @@ function helpers.sysctl_table(syspath)
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Return result from sysctl variable as table (async)
|
||||
function helpers.sysctl_async(path, parse)
|
||||
local ret = {}
|
||||
local path = table.concat(path, " ")
|
||||
|
||||
spawn.with_line_callback("sysctl " .. helpers.shellquote(path), {
|
||||
stdout = function(line)
|
||||
local key, value = string.match(line, "(.+): (.+)")
|
||||
ret[key] = value
|
||||
end,
|
||||
output_done = function() parse(ret) end
|
||||
})
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers
|
||||
|
||||
-- }}}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
-- {{{ Grab environment
|
||||
local setmetatable = setmetatable
|
||||
local string = { match = string.match }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
@ -9,26 +8,25 @@ local helpers = require("vicious.helpers")
|
|||
-- vicious.widgets.thermal
|
||||
local thermal_freebsd = {}
|
||||
|
||||
|
||||
-- {{{ Thermal widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
function thermal_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
if type(warg) ~= "table" then warg = { warg } end
|
||||
|
||||
local thermals = {}
|
||||
|
||||
for i=1, #warg do
|
||||
local output = helpers.sysctl(warg[i])
|
||||
|
||||
if not output then
|
||||
thermals[i] = -1
|
||||
else
|
||||
thermals[i] = string.match(output, "[%d]+")
|
||||
helpers.sysctl_async(warg, function(ret)
|
||||
for i=1, #warg do
|
||||
if ret[warg[i]] ~= nil then
|
||||
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
||||
else
|
||||
thermals[i] = "N/A"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return thermals
|
||||
callback(thermals)
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return setmetatable(thermal_freebsd, { __call = function(_, ...) return worker(...) end })
|
||||
return helpers.setasyncall(thermal_freebsd)
|
||||
|
|
Loading…
Reference in New Issue