This commit is contained in:
Joerg T. (Mic92) 2010-10-02 11:55:43 +02:00
commit 8fa3dd64ac
18 changed files with 842 additions and 13 deletions

17
CHANGES
View File

@ -2,6 +2,23 @@
Full changelog is available online: Full changelog is available online:
http://git.sysphere.org/vicious/log/?showmsg=1 http://git.sysphere.org/vicious/log/?showmsg=1
--------------------------------------------------- ---------------------------------------------------
1534951 mpd: added some optional stats, commented
4113d37 pkg: include FreeBSD support
fc46e7a TODO: solid multigraph support needed
d912663 net: add operational state support
8674c91 dio: add partition support
d6faae1 TODO: remove org-mode extension
6171734 TODO: added the carrier detection todo
6d6e98a TODO: included the todo file to encourage contribution
ca1d8d7 README: cut on the security crap
fdae848 raid: removed permanent stats storage
3e12875 pkg: include Mandriva support
64e5426 uptime: simplified system load regexp
448275a widgets: reuse existing datasets where appropriate
a9347ec raid: import raid state widget type by Hagen
9af29ce pkg: aptitude alternative to apt-show-versions
94a60fb bat: fixed module description
338a2ee Next release, tag 2.0.0
0299c15 widgets: minor cleanup before a tag in cpuinf, fs, mbox... 0299c15 widgets: minor cleanup before a tag in cpuinf, fs, mbox...
4fc6dff wifi: return 0 not N/A when channel is unavailable 4fc6dff wifi: return 0 not N/A when channel is unavailable
f50ad21 thermal: function argument is already local f50ad21 thermal: function argument is already local

14
README
View File

@ -238,7 +238,7 @@ vicious.widgets.org
4th as count of tasks to do in the week 4th as count of tasks to do in the week
vicious.widgets.pkg vicious.widgets.pkg
- provides number of pending updates on GNU/Linux - provides number of pending updates on UNIX systems
- takes the distribution name as an argument, i.e. "Arch" - takes the distribution name as an argument, i.e. "Arch"
- returns 1st value as the count of available updates - returns 1st value as the count of available updates
@ -249,7 +249,7 @@ vicious.widgets.mpd
argument is provided connection attempt will be made to localhost argument is provided connection attempt will be made to localhost
port 6600 with no password port 6600 with no password
- returns a table with string keys: {volume}, {state}, {Artist}, - returns a table with string keys: {volume}, {state}, {Artist},
{Title}, {Album}, {Genre} {Title}, {Album}, {Genre} and optionally {Name} and {file}
vicious.widgets.volume vicious.widgets.volume
- provides volume levels and state of requested ALSA mixers - provides volume levels and state of requested ALSA mixers
@ -278,13 +278,11 @@ in. How data will be formatted, will it be red or blue, should be
defined in rc.lua (or somewhere else, outside the actual module). defined in rc.lua (or somewhere else, outside the actual module).
Before writing a widget type you should check if there is already one Before writing a widget type you should check if there is already one
in the [contrib] branch of Vicious. The [contrib] branch contains in the contrib directory of Vicious. The contrib directory contains
extra widgets you can use. Some are for less common hardware, and extra widgets you can use. Some are for less common hardware, and
other were contributed by Vicious users. The [contrib] branch also other were contributed by Vicious users. The contrib directory also
holds widget types that were deprecated, rewritten or removed from the holds widget types that were obsoleted or rewritten. Contrib widgets
[master] branch. will not be imported by init unless you explicitly enable it.
- http://git.sysphere.org/vicious/tree/extra?h=contrib
Richard Kolkovich, a FreeBSD user, published his vicious-fbsd Richard Kolkovich, a FreeBSD user, published his vicious-fbsd
branch. If you are also a BSD user you can find his work here: branch. If you are also a BSD user you can find his work here:

2
TODO
View File

@ -5,11 +5,11 @@
* Vicious * Vicious
** TODO Document contrib widgets in contrib/README
** TODO Consider multigraph, graph stacking, support ** TODO Consider multigraph, graph stacking, support
** TODO Consider including this code in format helper ** TODO Consider including this code in format helper
- return format and format:gsub("${[^}]+}", "") - return format and format:gsub("${[^}]+}", "")
- Note: We should then also replace just $1/$2... - Note: We should then also replace just $1/$2...
** TODO Include Name and file in MPD widget
** TODO Complete the hddtemp fix ** TODO Complete the hddtemp fix
- In certain setups regexp does not match all devices - In certain setups regexp does not match all devices
- The regexp catches the first device name, but last stats - The regexp catches the first device name, but last stats

51
contrib/batacpi.lua Normal file
View File

@ -0,0 +1,51 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local table = { insert = table.insert }
local string = { match = string.match }
-- }}}
-- Batacpi: provides state, charge, and remaining time for all batteries using acpitool
module("vicious.contrib.batacpi")
-- {{{ Battery widget type
local function worker(format)
local battery_info = {}
local battery_state = {
["full"] = "",
["unknown"] = "",
["charged"] = "",
["charging"] = "+",
["discharging"] = "-"
}
-- Get data from acpitool
local f = io.popen("acpitool -b")
for line in f:lines() do
-- Check if the battery is present
if string.match(line, "^[%s]+Battery.*") then
-- Store state and charge information
table.insert(battery_info, (battery_state[string.match(line, "([%a]*),") or "unknown"]))
table.insert(battery_info, (tonumber(string.match(line, "([%d]?[%d]?[%d])%.")) or 0))
-- Store remaining time information
table.insert(battery_info, (string.match(line, "%%,%s(.*)") or "N/A"))
else
return {battery_state["unknown"], 0, "N/A"}
end
end
f:close()
return battery_info
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

78
contrib/batpmu.lua Normal file
View File

@ -0,0 +1,78 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable
local math = {
min = math.min,
floor = math.floor
}
local string = {
find = string.find,
match = string.match,
format = string.format
}
-- }}}
-- Batpmu: provides state, charge and remaining time for a requested battery using PMU
module("vicious.contrib.batpmu")
-- {{{ Battery widget type
local function worker(format, batid)
local battery_state = {
["full"] = "",
["unknown"] = "",
["00000013"] = "+",
["00000011"] = "-"
}
-- Get /proc/pmu/battery* state
local f = io.open("/proc/pmu/" .. batid)
-- Handler for incompetent users
if not f then return {battery_state["unknown"], 0, "N/A"} end
local statefile = f:read("*all")
f:close()
-- Get /proc/pmu/info data
local f = io.open("/proc/pmu/info")
local infofile = f:read("*all")
f:close()
-- Check if the battery is present
if infofile == nil or string.find(infofile, "Battery count[%s]+:[%s]0") then
return {battery_state["unknown"], 0, "N/A"}
end
-- Get capacity and charge information
local capacity = string.match(statefile, "max_charge[%s]+:[%s]([%d]+).*")
local remaining = string.match(statefile, "charge[%s]+:[%s]([%d]+).*")
-- Calculate percentage
local percent = math.min(math.floor(remaining / capacity * 100), 100)
-- Get timer information
local timer = string.match(statefile, "time rem%.[%s]+:[%s]([%d]+).*")
if timer == "0" then return {battery_state["full"], percent, "N/A"} end
-- Get state information
local state = string.match(statefile, "flags[%s]+:[%s]([%d]+).*")
local state = battery_state[state] or battery_state["unknown"]
-- Calculate remaining (charging or discharging) time
local hoursleft = math.floor(tonumber(timer) / 3600)
local minutesleft = math.floor((tonumber(timer) / 60) % 60)
local time = string.format("%02d:%02d", hoursleft, minutesleft)
return {state, percent, time}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

85
contrib/batproc.lua Normal file
View File

@ -0,0 +1,85 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable
local math = {
min = math.min,
floor = math.floor
}
local string = {
find = string.find,
match = string.match,
format = string.format
}
-- }}}
-- Batproc: provides state, charge, and remaining time for a requested battery using procfs
module("vicious.contrib.batproc")
-- {{{ Battery widget type
local function worker(format, batid)
local battery_state = {
["full"] = "",
["unknown"] = "",
["charged"] = "",
["charging"] = "+",
["discharging"] = "-"
}
-- Get /proc/acpi/battery info
local f = io.open("/proc/acpi/battery/"..batid.."/info")
-- Handler for incompetent users
if not f then return {battery_state["unknown"], 0, "N/A"} end
local infofile = f:read("*all")
f:close()
-- Check if the battery is present
if infofile == nil or string.find(infofile, "present:[%s]+no") then
return {battery_state["unknown"], 0, "N/A"}
end
-- Get capacity information
local capacity = string.match(infofile, "last full capacity:[%s]+([%d]+).*")
-- Get /proc/acpi/battery state
local f = io.open("/proc/acpi/battery/"..batid.."/state")
local statefile = f:read("*all")
f:close()
-- Get state information
local state = string.match(statefile, "charging state:[%s]+([%a]+).*")
local state = battery_state[state] or battery_state["unknown"]
-- Get charge information
local rate = string.match(statefile, "present rate:[%s]+([%d]+).*")
local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
-- Calculate percentage (but work around broken BAT/ACPI implementations)
local percent = math.min(math.floor(remaining / capacity * 100), 100)
-- Calculate remaining (charging or discharging) time
if state == "+" then
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
elseif state == "-" then
timeleft = tonumber(remaining) / tonumber(rate)
else
return {state, percent, "N/A"}
end
local hoursleft = math.floor(timeleft)
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
local time = string.format("%02d:%02d", hoursleft, minutesleft)
return {state, percent, time}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

23
contrib/init.lua Normal file
View File

@ -0,0 +1,23 @@
---------------------------------------------------
-- Vicious widgets for the awesome window manager
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Configure widgets
require("vicious.contrib.batacpi")
require("vicious.contrib.batpmu")
require("vicious.contrib.batproc")
require("vicious.contrib.mpc")
require("vicious.contrib.netcfg")
require("vicious.contrib.net")
require("vicious.contrib.ossvol")
require("vicious.contrib.pop")
require("vicious.contrib.pulse")
require("vicious.contrib.rss")
require("vicious.contrib.sensors")
-- }}}
-- Vicious: widgets for the awesome window manager
module("vicious.contrib")

47
contrib/mpc.lua Normal file
View File

@ -0,0 +1,47 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
---------------------------------------------------
-- {{{ Grab environment
local type = type
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { find = string.find }
local helpers = require("vicious.helpers")
-- }}}
-- Mpc: provides the currently playing song in MPD
module("vicious.contrib.mpc")
-- {{{ MPC widget type
local function worker(format, warg)
-- Get data from mpd
local f = io.popen("mpc")
local np = f:read("*line")
f:close()
-- Not installed,
if np == nil or -- off or stoppped.
(string.find(np, "MPD_HOST") or string.find(np, "volume:"))
then
return {"Stopped"}
end
-- Check if we should scroll, or maybe truncate
if warg then
if type(warg) == "table" then
np = helpers.scroll(np, warg[1], warg[2])
else
np = helpers.truncate(np, warg)
end
end
return {helpers.escape(np)}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

138
contrib/net.lua Normal file
View File

@ -0,0 +1,138 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
-- * (c) 2009, Henning Glawe <glaweh@debian.org>
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
---------------------------------------------------
-- {{{ Grab environment
local pairs = pairs
local tonumber = tonumber
local os = { time = os.time }
local io = { lines = io.lines }
local setmetatable = setmetatable
local string = { match = string.match }
local helpers = require("vicious.helpers")
-- }}}
-- Net: provides usage statistics for all network interfaces
module("vicious.contrib.net")
-- Initialise function tables
local nets = {}
-- Variable definitions
local unit = { ["b"] = 1, ["kb"] = 1024,
["mb"] = 1024^2, ["gb"] = 1024^3
}
-- {{{ Net widget type
local function worker(format, tignorelist)
local args = {}
local tignore = {}
local total_rx = 0
local total_tx = 0
local any_up = 0
if not tignorelist then
tignorelist = {"lo", "wmaster0"}
end
for k, i in pairs(tignorelist) do
tignore[i] = true
end
-- Get NET stats
for line in io.lines("/proc/net/dev") do
-- Match wmaster0 as well as rt0 (multiple leading spaces)
local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):")
if name ~= nil then
-- Received bytes, first value after the name
local recv = tonumber(string.match(line, ":[%s]*([%d]+)"))
-- Transmited bytes, 7 fields from end of the line
local send = tonumber(string.match(line,
"([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$"))
if not tignore[name] then
total_rx = total_rx + recv
total_tx = total_tx + send
end
helpers.uformat(args, name .. " rx", recv, unit)
helpers.uformat(args, name .. " tx", send, unit)
if nets[name] == nil then
-- Default values on the first run
nets[name] = {}
helpers.uformat(args, name .. " down", 0, unit)
helpers.uformat(args, name .. " up", 0, unit)
args["{"..name.." carrier}"] = 0
nets[name].time = os.time()
else -- Net stats are absolute, substract our last reading
local interval = os.time() - nets[name].time > 0 and
os.time() - nets[name].time or 1
nets[name].time = os.time()
local down = (recv - nets[name][1]) / interval
local up = (send - nets[name][2]) / interval
helpers.uformat(args, name .. " down", down, unit)
helpers.uformat(args, name .. " up", up, unit)
-- Carrier detection
sysnet = helpers.pathtotable("/sys/class/net/" .. name)
if sysnet.carrier then
ccarrier = tonumber(sysnet.carrier)
args["{"..name.." carrier}"] = ccarrier
if ccarrier ~= 0 and not tignore[name] then
any_up = 1
end
else
args["{"..name.." carrier}"] = 0
end
end
-- Store totals
nets[name][1] = recv
nets[name][2] = send
end
end
helpers.uformat(args, "total rx", total_rx, unit)
helpers.uformat(args, "total tx", total_tx, unit)
if nets["total"] == nil then
-- Default values on the first run
nets["total"] = {}
helpers.uformat(args, "total down", 0, unit)
helpers.uformat(args, "total up", 0, unit)
args["{total carrier}"] = 0
nets["total"].time = os.time()
else -- Net stats are absolute, substract our last reading
local interval = os.time() - nets["total"].time > 0 and
os.time() - nets["total"].time or 1
nets["total"].time = os.time()
local down = (total_rx - nets["total"][1]) / interval
local up = (total_tx - nets["total"][2]) / interval
helpers.uformat(args, "total down", down, unit)
helpers.uformat(args, "total up", up, unit)
args["{total carrier}"] = any_up
end
-- Store totals
nets["total"][1] = total_rx
nets["total"][2] = total_tx
return args
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

34
contrib/netcfg.lua Normal file
View File

@ -0,0 +1,34 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Radu A. <admiral0@tuxfamily.org>
---------------------------------------------------
-- {{{ Grab environment
local io = { popen = io.popen }
local setmetatable = setmetatable
local table = { insert = table.insert }
-- }}}
-- Netcfg: provides active netcfg network profiles
module("vicious.contrib.netcfg")
-- {{{ Netcfg widget type
local function worker(format)
-- Initialize counters
local profiles = {}
local f = io.popen("ls -1 /var/run/network/profiles")
for line in f:lines() do
if line ~= nil then
table.insert(profiles, line)
end
end
f:close()
return profiles
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

53
contrib/ossvol.lua Normal file
View File

@ -0,0 +1,53 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { match = string.match }
-- }}}
-- Ossvol: provides volume levels of requested OSS mixers
module("vicious.contrib.ossvol")
-- {{{ Volume widget type
local function worker(format, warg)
if not warg then return end
local mixer_state = {
["on"] = "", -- "",
["off"] = "" -- "M"
}
-- Get mixer control contents
local f = io.popen("ossmix -c")
local mixer = f:read("*all")
f:close()
-- Capture mixer control state
local volu = tonumber(string.match(mixer, warg .. "[%s]([%d%.]+)"))/0.25
local mute = string.match(mixer, "vol%.mute[%s]([%a]+)")
-- Handle mixers without data
if volu == nil then
return {0, mixer_state["off"]}
end
-- Handle mixers without mute
if mute == "OFF" and volu == "0"
-- Handle mixers that are muted
or mute == "ON" then
mute = mixer_state["off"]
else
mute = mixer_state["on"]
end
return {volu, mute}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

54
contrib/pop.lua Normal file
View File

@ -0,0 +1,54 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Boris Bolgradov <>
--
-- This widget type depends on luasocket.
--
-- Widget arguments are host, port, username and
-- password, i.e.:
-- {"mail.myhost.com", 110, "John", "132435"}
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local sock_avail, socket = pcall(function()
return require("socket")
end)
-- }}}
-- POP: provides the count of new messages in a POP3 mailbox
module("vicious.contrib.pop")
-- {{{ POP3 count widget type
local function worker(format, warg)
if not sock_avail or (not warg or #warg ~= 4) then
return {"N/A"}
end
local host, port = warg[1], tonumber(warg[2])
local user, pass = warg[3], warg[4]
local client = socket.tcp()
client:settimeout(3)
client:connect(host, port)
client:receive("*l")
client:send("USER " .. user .. "\r\n")
client:receive("*l")
client:send("PASS " .. pass .. "\r\n")
client:receive("*l")
client:send("STAT" .. "\r\n")
local response = client:receive("*l")
client:close()
if response:find("%+OK") then
response = response:match("%+OK (%d+)")
end
return {response}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

105
contrib/pulse.lua Normal file
View File

@ -0,0 +1,105 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, MrMagne <MrMagne@cerv.fr>
---------------------------------------------------
-- Usage example
--
-- -- Register widget
-- vicious.register(vol, vicious.contrib.pulse, " $1%", 2, "alsa_output.pci-0000_00_1b.0.analog-stereo")
-- -- Register buttons
-- vol:buttons(awful.util.table.join(
-- awful.button({ }, 1, function () awful.util.spawn("pavucontrol") end),
-- awful.button({ }, 4, function () vicious.contrib.pulse.add(5,"alsa_output.pci-0000_00_1b.0.analog-stereo") end),
-- awful.button({ }, 5, function () vicious.contrib.pulse.add(-5,"alsa_output.pci-0000_00_1b.0.analog-stereo") end)
-- ))
---------------------------------------------------
-- {{{ Grab environment
local type = type
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local os = { execute = os.execute }
local table = { insert = table.insert }
local string = {
find = string.find,
match = string.match,
format = string.format,
gmatch = string.gmatch
}
-- }}}
-- Pulse: provides volume levels of requested pulseaudio sinks
module("vicious.contrib.pulse")
-- {{{ Helper function
local function get_sink_name(sink)
-- If no sink is specified take the first one
if sink == nil then
local f = io.popen("pacmd list-sinks | grep name:")
local line = f:read("*all")
f:close()
sink = string.match(line, "<(.*)>")
-- If sink is an index, retrieve its name
elseif type(sink) == "number" then
local f = io.popen("pacmd list-sinks | grep name:")
local line = f:read("*all")
f:close()
local sinks = {}
for s in string.gmatch(line, "<(.*)>") do
table.insert(sinks, s)
end
sink = sinks[sink]
end
return sink
end
-- }}}
-- {{{ Pulseaudio widget type
local function worker(format, sink)
sink = get_sink_name(sink)
if sink == nil then return {0} end
-- Get sink data
local f = io.popen("pacmd dump | grep '\\(set-sink-volume " .. sink.."\\)\\|\\(set-sink-mute "..sink.."\\)'")
local data = f:read("*all")
f:close()
-- If mute return 0 (not "Mute") so we don't break progressbars
if string.match(data," (yes)\n$") then
return {0}
end
local vol = tonumber(string.match(data, "(0x[%x]+)"))
if vol == nil then vol = 0 end
return { vol/0x10000*100 }
end
-- }}}
-- {{{ Volume control helper
function add(percent, sink)
sink = get_sink_name(sink)
if sink == nil then return end
local f = io.popen("pacmd dump | grep 'set-sink-volume " .. sink.."'")
local data = f:read("*all")
f:close()
local initial_vol = tonumber(string.match(data, "(0x[%x]+)"))
local vol = initial_vol + percent/100*0x10000
if vol > 0x10000 then vol = 0x10000 end
if vol < 0 then vol = 0 end
local cmd = "pacmd set-sink-volume "..sink..string.format(" 0x%x", vol).." >/dev/null"
os.execute(cmd)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

67
contrib/rss.lua Normal file
View File

@ -0,0 +1,67 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2009, olcc
--
-- This is now a standalone RSS reader for awesome:
-- * http://github.com/olcc/aware
---------------------------------------------------
-- {{{ Grab environment
local pairs = pairs
local io = { popen = io.popen }
local setmetatable = setmetatable
-- }}}
-- RSS: provides latest world news
module("vicious.contrib.rss")
-- {{{ RSS widget type
local function worker(format, input)
-- input: * feed - feed url
-- * object - entity to look for (typically: 'item')
-- * fields - fields to read (example: 'link', 'title', 'description')
-- output: * count - number of entities found
-- * one table for each field, containing wanted values
local feed = input.feed
local object = input.object
local fields = input.fields
-- Initialise tables
local out = {}
for _, v in pairs(fields) do
out[v] = {}
end
-- Initialise variables
local ob = nil
local i,j,k = 1, 1, 0
local curl = "curl -A 'Mozilla/4.0' -fsm 5 --connect-timeout 3 "
-- Get the feed
local f = io.popen(curl .. '"' .. feed .. '"')
local feed = f:read("*all")
f:close()
while true do
i, j, ob = feed.find(feed, "<" .. object .. ">(.-)</" .. object .. ">", i)
if not ob then break end
for _, v in pairs(fields) do
out[v][k] = ob:match("<" .. v .. ">(.*)</" .. v .. ">")
end
k = k+1
i = j+1
end
-- Update the entity count
out.count = k
return out
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

68
contrib/sensors.lua Normal file
View File

@ -0,0 +1,68 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Greg D. <jabbas@jabbas.pl>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local table = { insert = table.insert }
local string = {
gsub = string.gsub,
match = string.match
}
-- }}}
-- Sensors: provides access to lm_sensors data
module("vicious.contrib.sensors")
-- {{{ Split helper function
local function datasplit(str)
-- Splitting strings into associative array
-- with some magic to get the values right.
str = string.gsub(str, "\n", ":")
local tbl = {}
string.gsub(str, "([^:]*)", function (v)
if string.match(v, ".") then
table.insert(tbl, v)
end
end)
local assoc = {}
for c = 1, #tbl, 2 do
local k = string.gsub(tbl[c], ".*_", "")
local v = tonumber(string.match(tbl[c+1], "[%d]+"))
assoc[k] = v
end
return assoc
end
-- }}}
-- {{{ Sensors widget type
local function worker(format, warg)
-- Get data from all sensors
local f = io.popen("LANG=C sensors -uA")
local lm_sensors = f:read("*all")
f:close()
local sensor_data = string.gsub(
string.match(lm_sensors, warg..":\n(%s%s.-)\n[^ ]"), " ", "")
-- One of: crit, max
local divisor = "crit"
local s_data = datasplit(sensor_data)
if s_data[divisor] and s_data[divisor] > 0 then
s_data.percent = s_data.input / s_data[divisor] * 100
end
return {s_data.input, tonumber(s_data.percent)}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

View File

@ -19,6 +19,7 @@ local table = {
require("vicious.helpers") require("vicious.helpers")
require("vicious.widgets") require("vicious.widgets")
--require("vicious.contrib")
-- Vicious: widgets for the awesome window manager -- Vicious: widgets for the awesome window manager
module("vicious") module("vicious")
@ -117,8 +118,13 @@ local function regregister(reg)
timers[reg.update] = { timers[reg.update] = {
timer = capi.timer({ timeout = reg.timer }) timer = capi.timer({ timeout = reg.timer })
} }
timers[reg.update].timer:add_signal("timeout", reg.update) local tm = timers[reg.update].timer
timers[reg.update].timer:start() if tm.connect_signal then
tm:connect_signal("timeout", reg.update)
else
tm:add_signal("timeout", reg.update)
end
tm:start()
end end
-- Initial update -- Initial update

View File

@ -24,7 +24,9 @@ local function worker(format, warg)
["{Artist}"] = "N/A", ["{Artist}"] = "N/A",
["{Title}"] = "N/A", ["{Title}"] = "N/A",
["{Album}"] = "N/A", ["{Album}"] = "N/A",
["{Genre}"] = "N/A" ["{Genre}"] = "N/A",
--["{Name}"] = "N/A",
--["{file}"] = "N/A",
} }
-- Fallback to MPD defaults -- Fallback to MPD defaults
@ -47,6 +49,8 @@ local function worker(format, warg)
elseif k == "Title" then mpd_state["{"..k.."}"] = helpers.escape(v) elseif k == "Title" then mpd_state["{"..k.."}"] = helpers.escape(v)
elseif k == "Album" then mpd_state["{"..k.."}"] = helpers.escape(v) elseif k == "Album" then mpd_state["{"..k.."}"] = helpers.escape(v)
elseif k == "Genre" then mpd_state["{"..k.."}"] = helpers.escape(v) elseif k == "Genre" then mpd_state["{"..k.."}"] = helpers.escape(v)
--elseif k == "Name" then mpd_state["{"..k.."}"] = helpers.escape(v)
--elseif k == "file" then mpd_state["{"..k.."}"] = helpers.escape(v)
end end
end end
end end

View File

@ -10,7 +10,7 @@ local setmetatable = setmetatable
-- }}} -- }}}
-- Pkg: provides number of pending updates on GNU/Linux -- Pkg: provides number of pending updates on UNIX systems
module("vicious.widgets.pkg") module("vicious.widgets.pkg")
@ -26,6 +26,7 @@ local function worker(format, warg)
["Debian"] = { cmd = "apt-show-versions -u -b" }, ["Debian"] = { cmd = "apt-show-versions -u -b" },
["Ubuntu"] = { cmd = "aptitude search '~U'" }, ["Ubuntu"] = { cmd = "aptitude search '~U'" },
["Fedora"] = { cmd = "yum list updates", sub = 3 }, ["Fedora"] = { cmd = "yum list updates", sub = 3 },
["FreeBSD"] ={ cmd = "pkg_version -I -l '<'" },
["Mandriva"]={ cmd = "urpmq --auto-select" } ["Mandriva"]={ cmd = "urpmq --auto-select" }
} }