From 4f86e28ec38cd9f53718e0b34c6d9f15de99fb23 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 15 Mar 2010 17:52:02 +0100 Subject: 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. --- README | 9 +++------ widgets/entropy.lua | 33 --------------------------------- widgets/init.lua | 1 - widgets/os.lua | 20 +++++++++++++++++--- 4 files changed, 20 insertions(+), 43 deletions(-) delete mode 100644 widgets/entropy.lua diff --git a/README b/README index b41faf5..743f83f 100644 --- a/README +++ b/README @@ -153,7 +153,9 @@ vicious.widgets.mem 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 + 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 - provides file system disk space usage @@ -220,11 +222,6 @@ vicious.widgets.gmail machine mail.google.com login user password pass - 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 - provides agenda statistics for Emacs org-mode - takes a table with full paths to agenda files, that will be diff --git a/widgets/entropy.lua b/widgets/entropy.lua deleted file mode 100644 index 395d5d9..0000000 --- a/widgets/entropy.lua +++ /dev/null @@ -1,33 +0,0 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- - --- {{{ 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 }) diff --git a/widgets/init.lua b/widgets/init.lua index 5b8ae04..8420880 100644 --- a/widgets/init.lua +++ b/widgets/init.lua @@ -23,7 +23,6 @@ require("vicious.widgets.mbox") require("vicious.widgets.mboxc") require("vicious.widgets.mdir") require("vicious.widgets.gmail") -require("vicious.widgets.entropy") require("vicious.widgets.org") require("vicious.widgets.pkg") require("vicious.widgets.mpd") diff --git a/widgets/os.lua b/widgets/os.lua index 8b1d11e..57b807a 100644 --- a/widgets/os.lua +++ b/widgets/os.lua @@ -5,8 +5,10 @@ -- {{{ Grab environment local pairs = pairs +local tonumber = tonumber local io = { popen = io.popen } local os = { getenv = os.getenv } +local math = { ceil = math.ceil } local setmetatable = setmetatable local helpers = require("vicious.helpers") local string = { @@ -26,7 +28,9 @@ local function worker(format) ["ostype"] = "N/A", ["hostname"] = "N/A", ["osrelease"] = "N/A", - ["username"] = "N/A" + ["username"] = "N/A", + ["entropy"] = "N/A", + ["entropy_p"] = "N/A" } -- Linux manual page: uname(2) @@ -47,11 +51,21 @@ local function worker(format) 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 + 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 system["username"] = os.getenv("USER") - return {system["ostype"], system["osrelease"], - system["username"], system["hostname"]} + return {system["ostype"], system["osrelease"], system["username"], + system["hostname"], system["entropy"], system["entropy_p"]} end -- }}} -- cgit v1.2.3