From c28bac5d71a2f315e309f41822abb33c3f38db17 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 25 Jun 2012 22:35:10 +0200 Subject: [PATCH 1/5] uptime: metatable bugfix after lua52 port fixed by Jorg Thalheim --- widgets/uptime.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/uptime.lua b/widgets/uptime.lua index 14de99a..0e996ac 100644 --- a/widgets/uptime.lua +++ b/widgets/uptime.lua @@ -33,4 +33,4 @@ local function worker(format) end -- }}} -local setmetatable(uptime, { __call = function(_, ...) return worker(...) end }) +return setmetatable(uptime, { __call = function(_, ...) return worker(...) end }) From eba6eb05737aefd75f45444b85809ff7a26db2ab Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Thu, 2 Aug 2012 02:15:53 +0200 Subject: [PATCH 2/5] README: prefer vicious in global space We want to expose suspend, activate and force functions to external shell scripts not just the Lua prompt. --- README | 2 +- contrib/README | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 6cae001..3a92628 100644 --- a/README +++ b/README @@ -35,7 +35,7 @@ your memory. Then add the following to the top of your rc.lua: - local vicious = require("vicious") + vicious = require("vicious") Once you create a widget (a textbox, graph or a progressbar) call vicious.register() to register it with Vicious: diff --git a/contrib/README b/contrib/README index 0c1e55b..4be896b 100644 --- a/contrib/README +++ b/contrib/README @@ -13,7 +13,7 @@ To use contrib widgets uncomment the line that loads them in init.lua. Or you can load them in your rc.lua after you require Vicious: - local vicious = require("vicious") + vicious = require("vicious") vicious.contrib = require("vicious.contrib") From da37c0917a6fd14ea177b363f7a000b6fc3e879f Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 19 Aug 2012 00:48:24 +0200 Subject: [PATCH 3/5] mdir: add support for maildir whitespaces This feature was sent by pofman@free.fr. --- widgets/mdir.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/mdir.lua b/widgets/mdir.lua index 32dd3b3..d7c6f3d 100644 --- a/widgets/mdir.lua +++ b/widgets/mdir.lua @@ -24,12 +24,12 @@ local function worker(format, warg) for i=1, #warg do -- Recursively find new messages - local f = io.popen("find "..warg[i].." -type f -wholename '*/new/*'") + local f = io.popen("find '"..warg[i].."' -type f -wholename '*/new/*'") for line in f:lines() do count.new = count.new + 1 end f:close() -- Recursively find "old" messages lacking the Seen flag - local f = io.popen("find "..warg[i].." -type f -regex '.*/cur/.*2,[^S]*$'") + local f = io.popen("find '"..warg[i].."' -type f -regex '.*/cur/.*2,[^S]*$'") for line in f:lines() do count.cur = count.cur + 1 end f:close() end From 8f2f1559c1cfd56fef83888e40a09f9561e05b0e Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sat, 25 Aug 2012 22:18:12 +0200 Subject: [PATCH 4/5] Next release, tag 2.1.0 --- CHANGES | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGES b/CHANGES index 4b93c2a..5eac3b1 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,24 @@ Full changelog is available online: http://git.sysphere.org/vicious/log/?showmsg=1 --------------------------------------------------- +da37c09 mdir: add support for maildir whitespaces +eba6eb0 README: prefer vicious in global space +c28bac5 uptime: metatable bugfix after lua52 port fixed by Jorg Thalheim +3b161ff contrib: document how to enable contributed widgets +e1c7c47 os: change os.getenv init to allow standalone usage of os widget +1a7b430 contrib: initialization bugfix after lua52 port +4caf95b README: update initialization instructions +80d523a bat: metatable bugfix after lua52 port +e929bea widgets: cleanup behind the last commit 363c03e +363c03e Fixed io.lines() bug +8e35a98 Ported vicious.contrib to lua 5.2 +41cc2c0 Ported vicious.widgets module to lua 5.2 +b6b5290 Ported vicious module to lua 5.2 +0741531 cpufreq: skip redudant freq variable check +97e54d6 cpufreq: rework new exception handlers +30db4be cpufreq: handle not existing frequency/governer +13cec6d pkg: update 'Arch S' substitution lines +2d8d7d7 Next release, tag 2.0.4 f972955 README: update thermal documentation 5605030 thermal: change coretemp default, allow file as widget argument 7a3699c division by zero, if battery is full charged From d63343efda83a24c52abfd58159c212a918d951d Mon Sep 17 00:00:00 2001 From: Andrzej Bieniek Date: Sat, 1 Sep 2012 00:34:57 +0200 Subject: [PATCH 5/5] contrib: add buildbot monitoring widget Signed-off-by: Adrian C. (anrxc) --- contrib/README | 14 ++++ contrib/buildbot.lua | 186 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 contrib/buildbot.lua diff --git a/contrib/README b/contrib/README index 4be896b..665592e 100644 --- a/contrib/README +++ b/contrib/README @@ -85,6 +85,12 @@ vicious.contrib.rss vicious.contrib.sensors - +vicious.contrib.buildbot + - provides last build status for configured buildbot builders (http://trac.buildbot.net/) + - returns build status in the format: [..] + - if is the same as only one number is displayed + - colors: red - failed, green - successful, yellow - in progress + - it depends on lua json parser (e.g. liblua5.1-json on Ubuntu 12.04) Usage examples -------------- @@ -95,3 +101,11 @@ Pulse Audio widget 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) )) + +Buildbot widget + local buildbotwidget = widget({ type = "textbox" }) + local buildbotwidget_warg = { + {builder="coverage", url="http://buildbot.buildbot.net"}, + {builder="tarball-slave", url="http://buildbot.buildbot.net"} + } + vicious.register(buildbotwidget, vicious.contrib.buildbot, "$1,", 3600, buildbotwidget_warg) diff --git a/contrib/buildbot.lua b/contrib/buildbot.lua new file mode 100644 index 0000000..5743662 --- /dev/null +++ b/contrib/buildbot.lua @@ -0,0 +1,186 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2012, Andrzje Bieniek +--------------------------------------------------- + +-- {{{ Grab environment +local setmetatable = setmetatable +local pcall = pcall +local json_status, json = pcall(require, "json") +local io = { popen = io.popen } +local pairs = pairs +local assert = assert +-- }}} + +local bb = {} --list of all buildbot builders + +local bs = {OK=1, FAILED=2, RUNNING=3} +local bc = {"green", "red", "yellow"} + +module("vicious.contrib.buildbot") + + + + +BB = {} +BB.__index = BB + +function BB.create(url, builder) + local b = {} + setmetatable(b,BB) + b.url = url -- buildbot url + b.builder = builder -- builder name + b.lastChecked = 0 -- last checked build number + b.lastSuccessful = 0 -- last successful build number + b.lastResult = nil -- last json parsed result + b.lastError = nil -- last error string or nil if no error + return b +end + +function BB:_queryBuildbot(build_number) + local f = io.popen("curl --connect-timeout 1 "..self.url.."/json/builders/"..self.builder.."/builds/"..build_number) + local jsbuilder = f:read("*all") + f:close() + if #jsbuilder == 0 then + return false, "can't read from url" + end + + local result_status, result = pcall(json.decode, jsbuilder, false) + if not result_status then + return false, "can't parse json data" + end + return true, result +end + +function BB:_getBuildStatus(result) + if #result['text'] > 0 then + local text = result['text'] + if text[1] == "build" and text[2] == "successful" and #text == 2 then + --successful + return bs.OK + else + --failed + return bs.FAILED + end + else + --in progress + return bs.RUNNING + end +end + +-- Function queries buildbot to refresh builds status. +-- * if build is successful or failed it will not be queried again, number is stored in lasteChecked +-- * up to 10 last builds will be checked to find last successful build +function BB:refresh() + local last_pass_fail = 0 + local nr = -1 + local last_result + local iter_counter = 0 + + self.lastError = nil + self.lastResult = nil + --- there is a gap to fill in, iterate all not checked builds starting from latest + while nr > self.lastChecked or nr == -1 do + local r_status, r = self:_queryBuildbot(nr) + local s + + if not r_status then + self.lastError = r + return + end + + s = self:_getBuildStatus(r) + if not last_result then + last_result = r + end + nr = r['number'] + assert(nr > 0) + if last_pass_fail == 0 and (s == bs.OK or s == bs.FAILED) then + last_pass_fail = nr + end + if s == bs.OK then --successful + self.lastSuccessful = nr + break; + end + nr = nr - 1 + iter_counter = iter_counter + 1 + if iter_counter > 10 then --check max last 10 builds when searching for successful build + break; + end + end + if last_pass_fail ~= 0 then + self.lastChecked = last_pass_fail + end + if last_result then + self.lastResult = last_result + end +end + +function BB:getLastSuccessful() + return self.lastSuccessful +end + +function BB:getCurrent() + return self.lastResult['number'] +end + +function BB:getCurrentStatus() + return self:_getBuildStatus(self.lastResult) +end + +function BB:getBuilder() + return self.builder +end + +function BB:getError() + return self.lastError +end + + +local function getBuilderStatus(b) + local s = "[" .. b:getBuilder() + --check if json library was loaded correctly + if not json_status then + return s .. ".can't find libluaX.X-json]" + end + + local err = b:getError() + if err then + return s .. "." .. err .. "]" + end + + if b:getLastSuccessful() ~= 0 then + success_build_nr_str = "".. b:getLastSuccessful() .."" + else + success_build_nr_str = "-" + end + + local current_build_color = bc[b:getCurrentStatus()] + current_build_nr_str = ""..b:getCurrent().."" + + if current_build_color ~= "green" then + s = s .. "." .. current_build_nr_str + end + return s .. "." .. success_build_nr_str .. "]" +end + + +-- {{{ Buildbot widget type +local function worker(format, warg) + if #bb == 0 then --fill up bb with builders when worker function is run for the first time + for i,v in pairs(warg) do + bb[#bb+1] = BB.create(v["url"], v["builder"]) + end + end + + local str = "" + for i,v in pairs(bb) do + v:refresh() + str = str .. " " .. getBuilderStatus(v) + end + return {str .. " "} +end +-- }}} + +setmetatable(_M, { __call = function(_, ...) return worker(...) end }) +