[os_all] Splitted into os_linux and os_bsd

This commit is contained in:
mutlusun 2019-07-31 18:46:01 +02:00
parent 875e98e24e
commit f5060093c6
No known key found for this signature in database
GPG Key ID: C0AF8F434E1AB79B
2 changed files with 50 additions and 17 deletions

47
widgets/os_bsd.lua Normal file
View File

@ -0,0 +1,47 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local los = { getenv = os.getenv }
local string = { match = string.match }
local helpers = require("vicious.helpers")
local spawn = require("vicious.spawn")
-- }}}
-- OS: provides operating system information
-- vicious.widgets.os
local os_bsd = {}
-- {{{ Operating system widget type
local function parse(stdout, stderr, exitreason, exitcode)
local system = {
["ostype"] = "N/A",
["hostname"] = "N/A",
["osrelease"] = "N/A",
["username"] = "N/A",
["entropy"] = "N/A",
["entropy_p"] = "N/A"
}
-- BSD manual page: uname(1)
system["ostype"], system["hostname"], system["osrelease"] =
string.match(stdout, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
-- Get user from the environment
system["username"] = los.getenv("USER")
return {system["ostype"], system["osrelease"], system["username"],
system["hostname"], system["entropy"], system["entropy_p"]}
end
function os_bsd.async(format, warg, callback)
spawn.easy_async("uname -snr",
function (...) callback(parse(...)) end)
end
-- }}}
return helpers.setasyncall(os_bsd)

View File

@ -6,21 +6,17 @@
-- {{{ Grab environment
local pairs = pairs
local tonumber = tonumber
local io = { popen = io.popen }
local math = { ceil = math.ceil }
local los = { getenv = os.getenv }
local setmetatable = setmetatable
local helpers = require("vicious.helpers")
local string = {
gsub = string.gsub,
match = string.match
}
local string = { gsub = string.gsub }
-- }}}
-- OS: provides operating system information
-- vicious.widgets.os
local os_all = {}
local os_linux = {}
-- {{{ Operating system widget type
@ -42,16 +38,6 @@ local function worker(format)
end
end
-- BSD manual page: uname(1)
if system["ostype"] == "N/A" then
local f = io.popen("uname -snr")
local uname = f:read("*line")
f:close()
system["ostype"], system["hostname"], system["osrelease"] =
string.match(uname, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
end
-- Linux manual page: random(4)
if kernel.random then
-- Linux 2.6 default entropy pool is 4096-bits
@ -70,4 +56,4 @@ local function worker(format)
end
-- }}}
return setmetatable(os_all, { __call = function(_, ...) return worker(...) end })
return setmetatable(os_linux, { __call = function(_, ...) return worker(...) end })