os: merge with entropy widget type

Operating System widget type now returns two additional values, 5th as
available system entropy and 6th as available entropy in percent.
This commit is contained in:
Adrian C. (anrxc) 2010-03-15 17:52:02 +01:00
parent 49b1b0972f
commit 4f86e28ec3
4 changed files with 20 additions and 43 deletions

9
README
View File

@ -153,7 +153,9 @@ vicious.widgets.mem
vicious.widgets.os vicious.widgets.os
- provides operating system information - provides operating system information
- returns 1st value as the operating system in use, 2nd as the - returns 1st value as the operating system in use, 2nd as the
release version, 3rd as your username and 4th the hostname release version, 3rd as your username, 4th the hostname, 5th as
available system entropy and 6th value as available entropy in
percent
vicious.widgets.fs vicious.widgets.fs
- provides file system disk space usage - provides file system disk space usage
@ -220,11 +222,6 @@ vicious.widgets.gmail
machine mail.google.com login user password pass machine mail.google.com login user password pass
- returns a table with string keys: {count} and {subject} - returns a table with string keys: {count} and {subject}
vicious.widgets.entropy
- provides available system entropy
- returns 1st value as available system entropy and 2nd value as
available entropy in percent
vicious.widgets.org vicious.widgets.org
- provides agenda statistics for Emacs org-mode - provides agenda statistics for Emacs org-mode
- takes a table with full paths to agenda files, that will be - takes a table with full paths to agenda files, that will be

View File

@ -1,33 +0,0 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local math = { ceil = math.ceil }
local helpers = require("vicious.helpers")
-- }}}
-- Entropy: provides available system entropy
module("vicious.widgets.entropy")
-- {{{ Entropy widget type
local function worker(format)
local random = helpers.pathtotable("/proc/sys/kernel/random")
-- Linux 2.6 has a default entropy pool of 4096-bits
local poolsize = tonumber(random.poolsize)
-- Get available entropy
local ent = tonumber(random.entropy_avail)
-- Calculate percentage
local ent_percent = math.ceil(ent * 100 / poolsize)
return {ent, ent_percent}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

View File

@ -23,7 +23,6 @@ require("vicious.widgets.mbox")
require("vicious.widgets.mboxc") require("vicious.widgets.mboxc")
require("vicious.widgets.mdir") require("vicious.widgets.mdir")
require("vicious.widgets.gmail") require("vicious.widgets.gmail")
require("vicious.widgets.entropy")
require("vicious.widgets.org") require("vicious.widgets.org")
require("vicious.widgets.pkg") require("vicious.widgets.pkg")
require("vicious.widgets.mpd") require("vicious.widgets.mpd")

View File

@ -5,8 +5,10 @@
-- {{{ Grab environment -- {{{ Grab environment
local pairs = pairs local pairs = pairs
local tonumber = tonumber
local io = { popen = io.popen } local io = { popen = io.popen }
local os = { getenv = os.getenv } local os = { getenv = os.getenv }
local math = { ceil = math.ceil }
local setmetatable = setmetatable local setmetatable = setmetatable
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
local string = { local string = {
@ -26,7 +28,9 @@ local function worker(format)
["ostype"] = "N/A", ["ostype"] = "N/A",
["hostname"] = "N/A", ["hostname"] = "N/A",
["osrelease"] = "N/A", ["osrelease"] = "N/A",
["username"] = "N/A" ["username"] = "N/A",
["entropy"] = "N/A",
["entropy_p"] = "N/A"
} }
-- Linux manual page: uname(2) -- Linux manual page: uname(2)
@ -47,11 +51,21 @@ local function worker(format)
string.match(uname, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)") string.match(uname, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
end end
-- Linux manual page: random(4)
if kernel.random then
-- Linux 2.6 default entropy pool is 4096-bits
local poolsize = tonumber(kernel.random.poolsize)
-- Get available entropy and calculate percentage
system["entropy"] = tonumber(kernel.random.entropy_avail)
system["entropy_p"] = math.ceil(system["entropy"] * 100 / poolsize)
end
-- Get user from the environment -- Get user from the environment
system["username"] = os.getenv("USER") system["username"] = os.getenv("USER")
return {system["ostype"], system["osrelease"], return {system["ostype"], system["osrelease"], system["username"],
system["username"], system["hostname"]} system["hostname"], system["entropy"], system["entropy_p"]}
end end
-- }}} -- }}}