[hddtemp_linux] Deprecate io.popen

This commit is contained in:
Nguyễn Gia Phong 2019-06-22 18:12:37 +07:00
parent 565d74cc8b
commit 0e7f5e5bcb
2 changed files with 17 additions and 29 deletions

View File

@ -18,7 +18,7 @@ Added:
Fixed:
- Deprecate the use of `io.popen` in following widgets:
* wifi_linux, wifiiw_linux, hwmontemp_linux
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
* bat_freebsd, mem_freebsd, net_freebsd
* volume, gmail, mdir, mpd, fs
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo

View File

@ -5,36 +5,24 @@
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
local helpers = require("vicious.helpers")
local helpers = require"vicious.helpers"
local spawn = require"vicious.spawn"
-- }}}
-- Hddtemp: provides hard drive temperatures using the hddtemp daemon
-- vicious.widgets.hddtemp
local hddtemp_linux = {}
-- {{{ HDD Temperature widget type
local function worker(format, warg)
-- Fallback to default hddtemp port
if warg == nil then warg = 7634 end
local hdd_temp = {} -- Get info from the hddtemp daemon
local quoted = helpers.shellquote(warg)
local f = io.popen("echo | curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:"..quoted)
for line in f:lines() do
for d, t in string.gmatch(line, "|([%/%a%d]+)|.-|([%d]+)|[CF]+|") do
hdd_temp["{"..d.."}"] = tonumber(t)
end
end
f:close()
return hdd_temp
end
-- }}}
return setmetatable(hddtemp_linux, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall{
async = function(format, warg, callback)
if warg == nil then warg = 7634 end -- fallback to default hddtemp port
local hdd_temp = {} -- get info from the hddtemp daemon
spawn.with_line_callback_with_shell(
"echo | curl -fs telnet://127.0.0.1:" .. warg,
{ stdout = function (line)
for d, t in line:gmatch"|([%/%w]+)|.-|(%d+)|[CF]|" do
hdd_temp["{"..d.."}"] = tonumber(t)
end
end,
output_done = function () callback(hdd_temp) end })
end }