[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:
|
- 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
|
* bat_freebsd, mem_freebsd, net_freebsd, thermal_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
|
||||||
|
|
19
helpers.lua
19
helpers.lua
|
@ -19,10 +19,12 @@ local getmetatable = getmetatable
|
||||||
local string = {
|
local string = {
|
||||||
upper = string.upper,
|
upper = string.upper,
|
||||||
lower = string.lower,
|
lower = string.lower,
|
||||||
format = string.format
|
format = string.format,
|
||||||
|
match = string.match,
|
||||||
}
|
}
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
local assert = assert
|
local assert = assert
|
||||||
|
local spawn = require("vicious.spawn")
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -260,6 +262,21 @@ function helpers.sysctl_table(syspath)
|
||||||
end
|
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
|
return helpers
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local setmetatable = setmetatable
|
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
-- }}}
|
-- }}}
|
||||||
|
@ -9,26 +8,25 @@ local helpers = require("vicious.helpers")
|
||||||
-- vicious.widgets.thermal
|
-- vicious.widgets.thermal
|
||||||
local thermal_freebsd = {}
|
local thermal_freebsd = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Thermal widget type
|
-- {{{ Thermal widget type
|
||||||
local function worker(format, warg)
|
function thermal_freebsd.async(format, warg, callback)
|
||||||
if not warg then return end
|
if not warg then return callback{} end
|
||||||
if type(warg) ~= "table" then warg = { warg } end
|
if type(warg) ~= "table" then warg = { warg } end
|
||||||
|
|
||||||
local thermals = {}
|
local thermals = {}
|
||||||
|
|
||||||
for i=1, #warg do
|
helpers.sysctl_async(warg, function(ret)
|
||||||
local output = helpers.sysctl(warg[i])
|
for i=1, #warg do
|
||||||
|
if ret[warg[i]] ~= nil then
|
||||||
if not output then
|
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
||||||
thermals[i] = -1
|
else
|
||||||
else
|
thermals[i] = "N/A"
|
||||||
thermals[i] = string.match(output, "[%d]+")
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return thermals
|
callback(thermals)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(thermal_freebsd, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(thermal_freebsd)
|
||||||
|
|
Loading…
Reference in New Issue