os: import operating system information widget

This widget type returns 1st value as the operating system in use, 2nd
as the release version, 3rd as your username and 4th the hostname.
This commit is contained in:
Adrian C. (anrxc) 2010-03-12 03:37:39 +01:00
parent de15934120
commit edb4619a55
3 changed files with 64 additions and 0 deletions

5
README
View File

@ -210,6 +210,11 @@ vicious.widgets.mem
in percent, 6th as swap usage, 7th as total system swap and 8th as in percent, 6th as swap usage, 7th as total system swap and 8th as
free swap free swap
vicious.widgets.os
- provides operating system information
- returns 1st value as the operating system in use, 2nd as the
release version, 3rd as your username and 4th the hostname
vicious.widgets.fs vicious.widgets.fs
- provides file system disk space usage - provides file system disk space usage
- takes an (optional) argument which, if true, includes remote file - takes an (optional) argument which, if true, includes remote file

View File

@ -28,6 +28,7 @@ require("vicious.thermal")
require("vicious.uptime") require("vicious.uptime")
require("vicious.bat") require("vicious.bat")
require("vicious.mem") require("vicious.mem")
require("vicious.os")
require("vicious.fs") require("vicious.fs")
require("vicious.dio") require("vicious.dio")
require("vicious.hddtemp") require("vicious.hddtemp")

58
os.lua Normal file
View File

@ -0,0 +1,58 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local pairs = pairs
local io = { popen = io.popen }
local os = { getenv = os.getenv }
local setmetatable = setmetatable
local helpers = require("vicious.helpers")
local string = {
gsub = string.gsub,
match = string.match
}
-- }}}
-- OS: provides operating system information
module("vicious.os")
-- {{{ Operating system widget type
local function worker(format)
local system = {
["ostype"] = "N/A",
["hostname"] = "N/A",
["osrelease"] = "N/A",
["username"] = "N/A"
}
-- Linux manual page: uname(2)
local kernel = helpers.pathtotable("/proc/sys/kernel")
for k, v in pairs(system) do
if kernel[k] then
system[k] = string.gsub(kernel[k], "[%s]*$", "")
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
-- Get user from the environment
system["username"] = os.getenv("USER")
return {system["ostype"], system["osrelease"],
system["username"], system["hostname"]}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })