From 2a5126f4f0c0a3e073becb98f49499363072643d Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 14 Sep 2009 17:25:23 +0200 Subject: General cleanup --- bat.lua | 1 - batat.lua | 2 -- cpu.lua | 2 -- cpufreq.lua | 1 - cpuinf.lua | 4 ---- date.lua | 1 - dio.lua | 2 -- fs.lua | 3 +-- gmail.lua | 1 - hddtemp.lua | 1 - init.lua | 39 ++++++++++++++++----------------------- load.lua | 1 - mbox.lua | 3 --- mboxc.lua | 8 +------- mdir.lua | 6 ------ mem.lua | 1 - mpd.lua | 4 ---- net.lua | 3 +-- org.lua | 4 +--- pacman.lua | 21 ++++++++------------- thermal.lua | 1 - uptime.lua | 2 -- volume.lua | 5 +---- weather.lua | 7 ++----- wifi.lua | 5 ++--- 25 files changed, 33 insertions(+), 95 deletions(-) diff --git a/bat.lua b/bat.lua index 26b251c..ba29894 100644 --- a/bat.lua +++ b/bat.lua @@ -22,7 +22,6 @@ module("vicious.bat") -- {{{ Battery widget type local function worker(format, batid) - -- Initialise tables local battery_state = { ["full"] = "↯", ["unknown"] = "⌁", diff --git a/batat.lua b/batat.lua index 37224af..dce5820 100644 --- a/batat.lua +++ b/batat.lua @@ -16,7 +16,6 @@ module("vicious.batat") -- {{{ Battery widget type local function worker(format) - -- Initialise tables local battery_info = {} local battery_state = { ["full"] = "↯", @@ -29,7 +28,6 @@ local function worker(format) -- Get data from acpitool local f = io.popen("acpitool -b") - -- Format data for line in f:lines() do -- Check if the battery is present if line:match("^[%s]+Battery.*") then diff --git a/cpu.lua b/cpu.lua index 5251670..648f8fb 100644 --- a/cpu.lua +++ b/cpu.lua @@ -27,7 +27,6 @@ local function worker(format) local f = io.open("/proc/stat") local cpu_lines = {} - -- Format data for line in f:lines() do if line:find("^cpu") then if #cpu_lines < 1 then cpuid = 1 @@ -52,7 +51,6 @@ local function worker(format) table.insert(cpu_usage, 0) end - -- Setup tables local total_new = {} local active_new = {} local diff_total = {} diff --git a/cpufreq.lua b/cpufreq.lua index ef0fbc0..b94676c 100644 --- a/cpufreq.lua +++ b/cpufreq.lua @@ -19,7 +19,6 @@ module("vicious.cpufreq") -- {{{ CPU frequency widget type local function worker(format, cpuid) - -- Initialise tables --local governor_state = { -- ["ondemand"] = "↯", -- ["powersave"] = "⌁", diff --git a/cpuinf.lua b/cpuinf.lua index bb34880..50cfc0f 100644 --- a/cpuinf.lua +++ b/cpuinf.lua @@ -16,25 +16,21 @@ module("vicious.cpuinf") -- {{{ CPU Information widget type local function worker(format) - -- Initialise variables cpu_id = nil -- Get cpuinfo local f = io.open("/proc/cpuinfo") local cpu_info = {} - -- Get data for line in f:lines() do if line:match("^processor.*") then cpu_id = line:match("([%d]+)") elseif line:match("^cpu MHz.*") then local cpu_speed = line:match("([%d]+)%.") - -- Store values cpu_info["{"..cpu_id.." mhz}"] = cpu_speed cpu_info["{"..cpu_id.." ghz}"] = tonumber(cpu_speed) / 1000 elseif line:match("^cache size.*") then local cpu_cache = line:match("([%d]+)[%s]KB") - -- Store values cpu_info["{"..cpu_id.." kb}"] = cpu_cache cpu_info["{"..cpu_id.." mb}"] = tonumber(cpu_cache) / 1024 end diff --git a/date.lua b/date.lua index aa7ac2f..1530702 100644 --- a/date.lua +++ b/date.lua @@ -15,7 +15,6 @@ module("vicious.date") -- {{{ Date widget type local function worker(format) - -- Get format if format == nil then return os.date() else diff --git a/dio.lua b/dio.lua index e77407c..f570816 100644 --- a/dio.lua +++ b/dio.lua @@ -27,7 +27,6 @@ local function worker(format, disk) local f = io.open("/proc/diskstats") local disk_lines = {} - -- Format data for line in f:lines() do if line:match("("..disk..")%s") then -- Todo: find a way to do this @@ -52,7 +51,6 @@ local function worker(format, disk) table.insert(disk_total, 0) end - -- Setup tables local diff_total = {} for i, v in ipairs(disk_lines) do diff --git a/fs.lua b/fs.lua index d5b0031..01b74e5 100644 --- a/fs.lua +++ b/fs.lua @@ -20,11 +20,10 @@ local function worker(format) local f = io.popen("LANG=C df -hP") local fs_info = {} - -- Format data for line in f:lines() do if not line:match("^Filesystem.*") then -- Format helper can't deal with matrices, so don't setup a - -- table for each mount point with gmatch + -- table for each mount point, with gmatch local size, used, avail, usep, mount = -- Instead match all at once, including network file systems line:match("^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$") diff --git a/gmail.lua b/gmail.lua index c893c2d..bcb815f 100644 --- a/gmail.lua +++ b/gmail.lua @@ -16,7 +16,6 @@ module("vicious.gmail") -- {{{ Gmail widget type local function worker(format, login) - -- Initialise tables local mail = { ["{count}"] = "0", ["{subject}"] = "N/A" diff --git a/hddtemp.lua b/hddtemp.lua index 38bbe13..f748a80 100644 --- a/hddtemp.lua +++ b/hddtemp.lua @@ -22,7 +22,6 @@ local function worker(format, port) local f = io.popen("curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:" .. port) local hdd_temp = {} - -- Get temperature data for line in f:lines() do local disk, temp = line:match("|([%/%a]+)|.*|([%d]+)|[CF]+|") diff --git a/init.lua b/init.lua index bf22918..78f49a5 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,13 @@ ----------------------------------------------------------------- +-------------------------------------------------------------- -- Vicious widgets for the awesome window manager --- +-------------------------------------------------------------- -- Licensed under the GNU General Public License version 2 -- * Copyright (C) 2009 Adrian C. --- --- To view a human-readable summary of the license, visit: --- * http://creativecommons.org/licenses/GPL/2.0/ ----------------------------------------------------------------- +-------------------------------------------------------------- -- Derived from Wicked, by Lucas de Vries -- * http://git.glacicle.com/cgit.cgi/wicked -- * Wicked is licensed under the WTFPL v2 ----------------------------------------------------------------- +-------------------------------------------------------------- -- {{{ Grab environment require("awful") @@ -63,7 +60,7 @@ require("vicious.date") module("vicious") --- {{{ Initialise variables +-- {{{ Initialise tables local timers = {} local registered = {} local widget_cache = {} @@ -88,7 +85,7 @@ end -- }}} -- {{{ Main functions --- {{{ Register widget +-- {{{ Register a widget function register(widget, wtype, format, timer, warg) local reg = {} local widget = widget @@ -110,10 +107,10 @@ function register(widget, wtype, format, timer, warg) reg.timer = 1 end - -- Register reg object + -- Register a reg object regregister(reg) - -- Return reg object for reuse + -- Return a reg object for reuse return reg end -- }}} @@ -121,12 +118,11 @@ end -- {{{ Register from reg object function regregister(reg) if not reg.running then - -- Put widget in table if registered[reg.widget] == nil then registered[reg.widget] = {} table.insert(registered[reg.widget], reg) else - already = false + local already = false for w, i in pairs(registered) do if w == reg.widget then @@ -148,7 +144,7 @@ function regregister(reg) end end - -- Start timer + -- Start the timer if reg.timer > 0 then timers[reg.update] = { timer = capi.timer({ timeout = reg.timer }) @@ -159,14 +155,12 @@ function regregister(reg) -- Initial update reg.update() - - -- Set running reg.running = true end end -- }}} --- {{{ Unregister widget +-- {{{ Unregister a widget function unregister(widget, keep, reg) if reg == nil then for w, i in pairs(registered) do @@ -192,7 +186,7 @@ function unregister(widget, keep, reg) end end - -- Stop timer + -- Stop the timer if timers[reg.update].timer.started then timers[reg.update].timer:stop() end @@ -202,7 +196,7 @@ function unregister(widget, keep, reg) end -- }}} --- {{{ Suspend vicious, halt all widget updates +-- {{{ Suspend vicious function suspend() for w, i in pairs(registered) do for _, v in pairs(i) do @@ -212,7 +206,7 @@ function suspend() end -- }}} --- {{{ Activate vicious, restart all widget updates +-- {{{ Activate vicious function activate(widget) for w, i in pairs(registered) do if widget == nil or w == widget then @@ -224,7 +218,7 @@ function activate(widget) end -- }}} --- {{{ Update widget +-- {{{ Update a widget function update(widget, reg, disablecache) -- Check if there are any equal widgets if reg == nil then @@ -242,8 +236,7 @@ function update(widget, reg, disablecache) local t = os.time() local data = {} - -- Check if we have output chached for this widget newer than last - -- widget update + -- Do we have output chached for a widget newer than last update if widget_cache[reg.type] ~= nil then local c = widget_cache[reg.type] diff --git a/load.lua b/load.lua index 8f4c3e0..3fdaee0 100644 --- a/load.lua +++ b/load.lua @@ -20,7 +20,6 @@ local function worker(format) local line = f:read("*line") f:close() - -- Get load data local avg1, avg5, avg15 = line:match("([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)") diff --git a/mbox.lua b/mbox.lua index c73236c..51c2e6b 100644 --- a/mbox.lua +++ b/mbox.lua @@ -21,12 +21,9 @@ local function worker(format, mbox) -- mbox could be huge, get a 15kb chunk from EOF -- * attachments could be much bigger than this f:seek("end", -15360) - - -- Get data local text = f:read("*all") f:close() - -- Find subject lines for match in string.gfind(text, "Subject: ([^\n]*)") do subject = match end diff --git a/mboxc.lua b/mboxc.lua index bc67896..67078e3 100644 --- a/mboxc.lua +++ b/mboxc.lua @@ -21,17 +21,11 @@ local function worker(format, mbox) local total = 0 -- Open the mbox - -- - -- If we had LuaFileSystem we could check the mtime and size of - -- the file and if they didn't change since the last read we could - -- return the old, cached, count. However, we didn't rely on extra - -- libraries to this point so we won't start now. local f = io.open(mbox) while true do -- Read the mbox line by line, if we are going to read some - -- *HUGE* folders then switch to reading chunks. It's why we are - -- not reading the whole file at once in the first place. + -- *HUGE* folders then switch to reading chunks local lines = f:read("*line") if not lines then break end diff --git a/mdir.lua b/mdir.lua index 520592a..39683c0 100644 --- a/mdir.lua +++ b/mdir.lua @@ -16,12 +16,6 @@ module("vicious.mdir") -- {{{ Maildir widget type local function worker(format, mdir) - -- Like with the mbox count widget, we would benefit from the - -- LuaFileSystem library. However, we didn't rely on extra - -- libraries to this point so we won't start now. Widgets like - -- this one are not agressive like CPU or NET, so we can keep it - -- simple, find is OK with me if we execute every >60s - -- -- Initialise counters local newcount = 0 local curcount = 0 diff --git a/mem.lua b/mem.lua index 9a38305..e501229 100644 --- a/mem.lua +++ b/mem.lua @@ -20,7 +20,6 @@ local function worker(format) -- Get meminfo local f = io.open("/proc/meminfo") - -- Get data for line in f:lines() do if line:match("^MemTotal.*") then mem_total = math.floor(tonumber(line:match("([%d]+)")) / 1024) diff --git a/mpd.lua b/mpd.lua index 5a563fd..3cebe61 100644 --- a/mpd.lua +++ b/mpd.lua @@ -16,10 +16,6 @@ module("vicious.mpd") -- {{{ MPD widget type local function worker(format) - -- This one is as simple as they come. Using sockets or expanding - -- it is a lost cause since there are already a few MPD Lua libs - -- written for awesome. Use them. - -- -- Get data from mpc local f = io.popen("mpc") local np = f:read("*line") diff --git a/net.lua b/net.lua index 6ddd25d..068459e 100644 --- a/net.lua +++ b/net.lua @@ -25,7 +25,6 @@ local function worker(format) local f = io.open("/proc/net/dev") local args = {} - -- Format data for line in f:lines() do -- Match wmaster0 as well as rt0 (multiple leading spaces) if line:match("^[%s]?[%s]?[%s]?[%s]?[%w]+:") then @@ -48,7 +47,7 @@ local function worker(format) args["{"..name.." tx_gb}"] = math.floor(send/1024/1024/1024*10)/10 if nets[name] == nil then - -- Default values on our first run + -- Default values on the first run nets[name] = {} args["{"..name.." down}"] = "n/a" args["{"..name.." up}"] = "n/a" diff --git a/org.lua b/org.lua index d0a2315..f8f96bc 100644 --- a/org.lua +++ b/org.lua @@ -26,7 +26,7 @@ local function worker(format, files) local soon = today + 24 * 3600 * 3 -- 3 days ahead is close local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum - -- Initialise count table + -- Initialise counters local count = { past = 0, today = 0, @@ -38,7 +38,6 @@ local function worker(format, files) for i=1, #files do local f = io.open(files[i]) - -- Parse the agenda for line in f:lines() do local scheduled = string.find(line, "SCHEDULED:") local closed = string.find(line, "CLOSED:") @@ -47,7 +46,6 @@ local function worker(format, files) if (scheduled and not closed) or (deadline and not closed) then local b, e, y, m, d = string.find(line, "(%d%d%d%d)-(%d%d)-(%d%d)") - -- Enumerate agenda items if b then local t = os.time{ year = y, month = m, day = d } diff --git a/pacman.lua b/pacman.lua index 0bcb2c8..abe0a73 100644 --- a/pacman.lua +++ b/pacman.lua @@ -16,27 +16,22 @@ module("vicious.pacman") -- {{{ Pacman widget type local function worker(format) + -- Initialise counters + local updates = 0 + -- Check if updates are available local f = io.popen("pacman -Qu") - -- Initialise updates - local updates = 0 - - -- Get data for line in f:lines() do - -- Pacman 3.3 returns one package on a line, without any extra - -- information - updates = updates + 1 - - -- Pacman 3.2 returns 'Targets:' followed by a number of - -- available updates and a list of packages all on one - -- line. Since the number is provided we don't have to count - -- them + -- Pacman 3.2 provides the number of available updates --updates = line:match("^Targets[%s]%(([%d]+)%)") or 0 - -- If the count changed then break out of the loop + ---- If the count changed then break out of the loop --if tonumber(updates) > 0 then -- break --end + + -- Pacman 3.3 returns one line per package + updates = updates + 1 end f:close() diff --git a/thermal.lua b/thermal.lua index 6c792e7..54a6c40 100644 --- a/thermal.lua +++ b/thermal.lua @@ -20,7 +20,6 @@ local function worker(format, thermal_zone) local line = f:read("*line") f:close() - -- Get temperature data local temperature = line:match("[%d]?[%d]?[%d]") return {temperature} diff --git a/uptime.lua b/uptime.lua index 83485e4..7261b16 100644 --- a/uptime.lua +++ b/uptime.lua @@ -22,9 +22,7 @@ local function worker(format) local line = f:read("*line") f:close() - -- Format data local total_uptime = math.floor(tonumber(line:match("[%d%.]+"))) - local uptime_days = math.floor(total_uptime / (3600 * 24)) local uptime_hours = math.floor((total_uptime % (3600 * 24)) / 3600) local uptime_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60) diff --git a/volume.lua b/volume.lua index 603b9d3..e36b610 100644 --- a/volume.lua +++ b/volume.lua @@ -21,13 +21,10 @@ local function worker(format, channel) local mixer = f:read("*all") f:close() - -- Get volume level local volume_level = string.match(mixer, "([%d]?[%d]?[%d])%%") -- Don't break progressbars - if volume_level == nil then - return {0} - end + if volume_level == nil then return {0} end return {volume_level} end diff --git a/weather.lua b/weather.lua index 476c969..cf43aa1 100644 --- a/weather.lua +++ b/weather.lua @@ -18,7 +18,7 @@ module("vicious.weather") -- {{{ Weather widget type local function worker(format, station) -- US National Oceanic and Atmospheric Administration - -- * Station (ICAO) codes: http://www.rap.ucar.edu/weather/surface/stations.txt + -- * ICAO codes: http://www.rap.ucar.edu/weather/surface/stations.txt local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/" -- Get info from a weather station @@ -26,11 +26,8 @@ local function worker(format, station) local ws = f:read("*all") f:close() - -- Setup tables + -- Default values local weather = { - -- Some of the weather symbols would look nice if prepended to - -- the final output, but it is up to the user to do that - -- * http://www.alanwood.net/unicode/miscellaneous_symbols.html ["{city}"] = "N/A", ["{wind}"] = "N/A", ["{windmph}"] = "N/A", diff --git a/wifi.lua b/wifi.lua index 966435f..063ce06 100644 --- a/wifi.lua +++ b/wifi.lua @@ -19,13 +19,12 @@ module("vicious.wifi") -- {{{ Wireless widget type local function worker(format, iface) - -- Get data from iwconfig, on distributions where it is executable - -- by users, and /sbin or /usr/sbin is in their path + -- Get data from iwconfig (where available) local f = io.popen("iwconfig " .. iface) local iw = f:read("*all") f:close() - -- Setup tables + -- Default values local winfo = { ["{ssid}"] = "N/A", ["{mode}"] = "N/A", -- cgit v1.2.3