diff --git a/README b/README index 743f83f..5fc65f4 100644 --- a/README +++ b/README @@ -172,6 +172,12 @@ vicious.widgets.dio {read_s}, {read_kb}, {read_mb}, {write_s}, {write_kb}, {write_mb} and {sched} +vicious.widgets.raid + - provides state information for a requested RAID array + - takes the RAID array ID as an argument + - returns 1st value as the number of assigned, and 2nd as active, + devices in the array + vicious.widgets.hddtemp - provides hard drive temperatures using the hddtemp daemon - takes the hddtemp listening port as an argument, or defaults to @@ -501,3 +507,4 @@ Vicious contributors: - Henning Glawe - Rémy C. - Hiltjo Posthuma + - Hagen Schink diff --git a/widgets/bat.lua b/widgets/bat.lua index 958c613..0048981 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -15,7 +15,7 @@ local math = { -- }}} --- Batsys: provides state, charge, and remaining time for a requested battery +-- Bat: provides state, charge, and remaining time for a requested battery module("vicious.widgets.bat") diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 3dfc22f..2673021 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -21,7 +21,7 @@ local string = { module("vicious.widgets.cpu") --- Initialise function tables +-- Initialize function tables local cpu_usage = {} local cpu_total = {} local cpu_active = {} diff --git a/widgets/dio.lua b/widgets/dio.lua index e886dac..4aa7002 100644 --- a/widgets/dio.lua +++ b/widgets/dio.lua @@ -16,7 +16,7 @@ local helpers = require("vicious.helpers") module("vicious.widgets.dio") --- Initialise function tables +-- Initialize function tables local disk_usage = {} local disk_total = {} -- Variable definitions diff --git a/widgets/gmail.lua b/widgets/gmail.lua index b2f0d8c..c772be8 100644 --- a/widgets/gmail.lua +++ b/widgets/gmail.lua @@ -38,16 +38,15 @@ local rss = { -- Default is all unread local feed = rss.unread +local mail = { + ["{count}"] = 0, + ["{subject}"] = "N/A" +} -- }}} -- {{{ Gmail widget type local function worker(format, warg) - local mail = { - ["{count}"] = 0, - ["{subject}"] = "N/A" - } - -- Get info from the Gmail atom feed local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. feed[1]) diff --git a/widgets/init.lua b/widgets/init.lua index 940565c..e2846b8 100644 --- a/widgets/init.lua +++ b/widgets/init.lua @@ -16,6 +16,7 @@ require("vicious.widgets.mem") require("vicious.widgets.os") require("vicious.widgets.fs") require("vicious.widgets.dio") +require("vicious.widgets.raid") require("vicious.widgets.hddtemp") require("vicious.widgets.net") require("vicious.widgets.wifi") diff --git a/widgets/mbox.lua b/widgets/mbox.lua index 475d018..be64e03 100644 --- a/widgets/mbox.lua +++ b/widgets/mbox.lua @@ -16,13 +16,13 @@ local helpers = require("vicious.helpers") module("vicious.widgets.mbox") +-- Initialize variables +local subject = "N/A" + -- {{{ Mailbox widget type local function worker(format, warg) if not warg then return end - -- Default value - local subject = "N/A" - -- mbox could be huge, get a 30kb chunk from EOF if type(warg) ~= "table" then mbox = warg end -- * attachment could be much bigger than 30kb diff --git a/widgets/mboxc.lua b/widgets/mboxc.lua index 6de1066..c928cd3 100644 --- a/widgets/mboxc.lua +++ b/widgets/mboxc.lua @@ -18,7 +18,7 @@ module("vicious.widgets.mboxc") local function worker(format, warg) if not warg then return end - -- Initialise counters + -- Initialize counters local count = { old = 0, total = 0, new = 0 } -- Get data from mbox files diff --git a/widgets/mdir.lua b/widgets/mdir.lua index 94522e7..464d9a1 100644 --- a/widgets/mdir.lua +++ b/widgets/mdir.lua @@ -18,7 +18,7 @@ module("vicious.widgets.mdir") local function worker(format, warg) if not warg then return end - -- Initialise counters + -- Initialize counters local count = { new = 0, cur = 0 } for i=1, #warg do diff --git a/widgets/net.lua b/widgets/net.lua index 9fd221f..9eda942 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -18,7 +18,7 @@ local helpers = require("vicious.helpers") module("vicious.widgets.net") --- Initialise function tables +-- Initialize function tables local nets = {} -- Variable definitions local unit = { ["b"] = 1, ["kb"] = 1024, diff --git a/widgets/org.lua b/widgets/org.lua index e6c622e..2d563b2 100644 --- a/widgets/org.lua +++ b/widgets/org.lua @@ -28,7 +28,7 @@ local function worker(format, warg) local soon = today + 24 * 3600 * 3 -- 3 days ahead is close local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum - -- Initialise counters + -- Initialize counters local count = { past = 0, today = 0, soon = 0, future = 0 } -- Get data from agenda files diff --git a/widgets/pkg.lua b/widgets/pkg.lua index d514e33..3bc6807 100644 --- a/widgets/pkg.lua +++ b/widgets/pkg.lua @@ -18,13 +18,15 @@ module("vicious.widgets.pkg") local function worker(format, warg) if not warg then return end - -- Initialise counters + -- Initialize counters local updates = 0 local manager = { ["Arch"] = { cmd = "pacman -Qu" }, ["Arch S"] = { cmd = "yes | pacman -Sup", sub = 2 }, ["Debian"] = { cmd = "apt-show-versions -u -b" }, - ["Fedora"] = { cmd = "yum list updates", sub = 3 } + ["Ubuntu"] = { cmd = "aptitude search '~U'" }, + ["Fedora"] = { cmd = "yum list updates", sub = 3 }, + ["Mandriva"]={ cmd = "urpmq --auto-select" } } -- Check if updates are available diff --git a/widgets/raid.lua b/widgets/raid.lua new file mode 100644 index 0000000..a714fb0 --- /dev/null +++ b/widgets/raid.lua @@ -0,0 +1,57 @@ +----------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2010, Hagen Schink +----------------------------------------------------- + +-- {{{ Grab environment +local io = { lines = io.lines } +local setmetatable = setmetatable +local string = { + len = string.len, + sub = string.sub, + match = string.match, + gmatch = string.gmatch +} +-- }}} + + +-- Raid: provides state information for a requested RAID array +module("vicious.widgets.raid") + + +-- Initialize function tables +local mddev = {} + +-- {{{ RAID widget type +local function worker(format, warg) + if not warg then return end + mddev[warg] = { + ["found"] = false, + ["active"] = 0, + ["assigned"] = 0 + } + + -- Linux manual page: md(4) + for line in io.lines("/proc/mdstat") do + if mddev[warg]["found"] then + local updev = string.match(line, "%[[_U]+%]") + + for i in string.gmatch(updev, "U") do + mddev[warg]["active"] = mddev[warg]["active"] + 1 + end + + break + elseif string.sub(line, 1, string.len(warg)) == warg then + mddev[warg]["found"] = true + + for i in string.gmatch(line, "%[%d%]") do + mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1 + end + end + end + + return {mddev[warg]["assigned"], mddev[warg]["active"]} +end +-- }}} + +setmetatable(_M, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/uptime.lua b/widgets/uptime.lua index e0bdc3b..ece3739 100644 --- a/widgets/uptime.lua +++ b/widgets/uptime.lua @@ -27,8 +27,7 @@ local function worker(format) local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60) local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes - string.match(proc.loadavg, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)") - + string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)") return {up_d, up_h, up_m, l1, l5, l15} end -- }}} diff --git a/widgets/weather.lua b/widgets/weather.lua index 7a114c0..f54fbc3 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -17,24 +17,24 @@ local helpers = require("vicious.helpers") module("vicious.widgets.weather") +-- Initialize function tables +local weather = { + ["{city}"] = "N/A", + ["{wind}"] = "N/A", + ["{windmph}"] = "N/A", + ["{windkmh}"] = "N/A", + ["{sky}"] = "N/A", + ["{weather}"] = "N/A", + ["{tempf}"] = "N/A", + ["{tempc}"] = "N/A", + ["{humid}"] = "N/A", + ["{press}"] = "N/A" +} + -- {{{ Weather widget type local function worker(format, warg) if not warg then return end - -- Default values - local weather = { - ["{city}"] = "N/A", - ["{wind}"] = "N/A", - ["{windmph}"] = "N/A", - ["{windkmh}"] = "N/A", - ["{sky}"] = "N/A", - ["{weather}"] = "N/A", - ["{tempf}"] = "N/A", - ["{tempc}"] = "N/A", - ["{humid}"] = "N/A", - ["{press}"] = "N/A" - } - -- Get weather forceast by the station ICAO code, from: -- * US National Oceanic and Atmospheric Administration local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/" diff --git a/widgets/wifi.lua b/widgets/wifi.lua index 61dee12..2e400bc 100644 --- a/widgets/wifi.lua +++ b/widgets/wifi.lua @@ -21,20 +21,20 @@ local string = { module("vicious.widgets.wifi") +-- Initialize function tables +local winfo = { + ["{ssid}"] = "N/A", + ["{mode}"] = "N/A", + ["{chan}"] = 0, + ["{rate}"] = 0, + ["{link}"] = 0, + ["{sign}"] = 0 +} + -- {{{ Wireless widget type local function worker(format, warg) if not warg then return end - -- Default values - local winfo = { - ["{ssid}"] = "N/A", - ["{mode}"] = "N/A", - ["{chan}"] = 0, - ["{rate}"] = 0, - ["{link}"] = 0, - ["{sign}"] = 0 - } - -- Get data from iwconfig where available local iwconfig = "/sbin/iwconfig" local f = io.open(iwconfig, "rb")