[PATCH] collate multiple cpus with the same frequenz

5 views
Skip to first unread message

que...@gmail.com

unread,
Oct 23, 2008, 4:30:36 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <qu...@informatik.uni-oldenburg.de>

---
plugins/cpu.lua | 84 ++++++++++++++++++++++++++++++------------------------
1 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/plugins/cpu.lua b/plugins/cpu.lua
index 43bb003..353eb16 100644
--- a/plugins/cpu.lua
+++ b/plugins/cpu.lua
@@ -67,57 +67,67 @@ local function cpu_list()
return list
end

+
function read_file(path)
- local fd = io.open(path, "r")
- if fd == nil then
- return nil
- end
+ local fd = io.open(path, "r")
+ if fd == nil then
+ return nil
+ end

- local text = fd:read("*a")
- fd:close()
+ local text = fd:read("*a")
+ fd:close()

- if type(text) == 'string' then
- text = text:match('(%w+)')
- end
+ if type(text) == 'string' then
+ text = text:match('(%w+)')
+ end

- return text
+ return text
end

-local function create_string(cpu)
- local govfile = cpu .. '/cpufreq/scaling_governor'
- local gov = read_file(govfile) or ""
-
- local frqfile = cpu .. '/cpufreq/scaling_cur_freq'
- local frq = read_file(frqfile) or ""
-
- if type(frq) == 'string' then
- local mhz = frq:match('(.*)000')
- if mhz then
- frq = mhz .. "MHz"
- else
- frq = frq .. "kHz"
- end
- else
- frq = ""
- end

- return gov .. " " .. frq
+local function create_string(cpu)
+ local govfile = cpu .. '/cpufreq/scaling_governor'
+ local gov = read_file(govfile) or ""
+
+ local frqfile = cpu .. '/cpufreq/scaling_cur_freq'
+ local frq = read_file(frqfile) or ""
+
+ if type(frq) == 'string' then
+ local mhz = frq:match('(.*)000')
+ if mhz then
+ frq = mhz .. " MHz"
+ else
+ frq = frq .. "kHz"
+ end
+ else
+ frq = ""
+ end
+
+ return frq .. "(" .. gov .. ")"
end

+
function update ( new_vol )
- local txt = ""
- local _, cpu
- local list = cpu_list()
- for _,cpu in pairs(list) do
- txt = txt .. create_string(cpu) .. " "
- end
+ local txt = ""
+ local _, cpu
+ local list = cpu_list()
+ local space = ""
+ for _,cpu in pairs(list) do
+ local str = create_string(cpu)
+ if txt == str then
+ txt = "2x " .. txt
+ else
+ txt = txt .. create_string(cpu) .. space
+ end
+ space = " "
+ end

widget:show(txt)
end

-local function cpu_timer(timer)
- update(0)
- return 10
+local function cpu_timer ( timer )
+ update(0)
+ return 10
end

timer = wmii.timer:new (cpu_timer, 1)
--
1.6.0.2

que...@gmail.com

unread,
Oct 23, 2008, 4:30:37 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <qu...@informatik.uni-oldenburg.de>

- it now displays the current rate
- it calculates the remaining charging/discharging time.
---
plugins/battery.lua | 364 ++++++++++++++++-----------------------------------
1 files changed, 116 insertions(+), 248 deletions(-)

diff --git a/plugins/battery.lua b/plugins/battery.lua
index c5eec45..1920ab2 100644
--- a/plugins/battery.lua
+++ b/plugins/battery.lua
@@ -1,275 +1,143 @@
---[[
-=pod
-
-=head1 NAME
-
-battery.lua - wmiirc-lua plugin for battery percentage
-
-=head1 SYNOPSIS
-
- -- in your wmiirc
- wmii.load_plugin("battery")
-
- -- To configure (after loading plugin)
-
- -- Multiple batteries
- wmii.set_conf("battery.names", "BAT0,BAT1");
-
- -- Polling rate (in seconds)
- wmii.set_conf("battery.poll_rate", 30)
-
-=head1 DESCRIPTION
-
-This plugin module provides a battery usage display.
-
-=head1 CONFIGURATION AND ENVIRONMENT
-
-There are several configurable options at the moment, most of which will not
-need to be modified from the defaults for most users.
-
-=over 4
-
-=item battery.names
-
-A comma-separated list of battery names to poll for status. This allows the
-widget to display multiple battery names.
-
-Defaults to "BAT0"
-
-=item battery.poll_rate
-
-Time in seconds to wait between checks for battery status.
-
-Defaults to 30
-
-=item battery.low
-
-Provide a "low battery" warning at this percentage of remaining capacity.
-Colour of widget will change to the defined value, and the low_action, if any,
-will be invoked.
-
-Defaults to 15
-
-=item battery.low_fgcolor
-
-Foreground colour of widget when in low battery state.
-
-Defaults to #000000
-
-=item battery.low_bgcolor
-
-Background colour of widget when in low battery state.
-
-Defaults to #FFFF66
-
-=item battery.low_action
-
-Shell command to invoke on entering low battery state.
-
-Defaults to
-
- echo "Low battery" | xmessage -center -buttons quit:0 -default quit -file -
-
-=item battery.critical
-
-Provide a "critical battery" warning at this percentage of remaining capacity.
-Colour of widget will change to the defined value, and the critical_action, if any,
-will be invoked.
-
-Defaults to 5
-
-=item battery.critical_fgcolor
-
-Foreground colour of widget when in critical battery state.
-
-Defaults to #000000
-
-=item battery.critical_bgcolor
-
-Background colour of widget when in critical battery state.
-
-Defaults to #FF0000
-
-=item battery.critical_action
-
-Shell command to invoke on entering critical battery state.
-
-Defaults to
-
- echo "Critical battery" | xmessage -center -buttons quit:0 -default quit -file -
-
-=back
-
-=head1 BUGS AND LIMITATIONS
-
-Please report problems to the author.
-Patches are welcome.
-
-=over 4
-
-=item *
-
-You can't have different low/critical warning thresholds or colours per
-battery. If you actually want this, please send a patch.
-
-=back
-
-=head1 SEE ALSO
-
-L<wmii(1)>, L<lua(1)>
-
-=head1 AUTHOR
-
-Dave O'Neill <d...@dmo.ca>
-
-Based on a port by Stefan Riegler <s...@bigfatflat.net> of the ruby-wmiirc
-standard-plugin.rb battery handling originally written Mauricio Fernandez.
-
-=head1 LICENCE AND COPYRIGHT
-
-Copyright (c) 2007, Stefan Riegler <s...@bigfatflat.net>
-Copyright (c) 2008, Dave O'Neill <d...@dmo.ca>
-
-This is free software. You may redistribute copies of it under the terms of
-the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
-is NO WARRANTY, to the extent permitted by law.
-
-=cut
-
---]]
-
-local wmii = require("wmii")
-local io = require("io")
-local os = require("os")
-local string = require("string")
-
-module("battery")
-api_version=0.1
-
--
--- Configuration Settings
+-- Copyright (c) 2007, Stefan Riegler <s...@bigfatflat.net>
--
-wmii.set_conf ("battery.poll_rate", 30)
-
-wmii.set_conf ("battery.names", "BAT0")
-
-wmii.set_conf ("battery.low", 15)
-wmii.set_conf ("battery.low_fgcolor", "#000000")
-wmii.set_conf ("battery.low_bgcolor", "#FFFF66")
-wmii.set_conf ("battery.low_action", 'echo "Low battery" | xmessage -center -buttons quit:0 -default quit -file -')
-
-wmii.set_conf ("battery.critical", 5)
-wmii.set_conf ("battery.critical_fgcolor", "#000000")
-wmii.set_conf ("battery.critical_bgcolor", "#FF0000")
-wmii.set_conf ("battery.critical_action", 'echo "Critical battery" | xmessage -center -buttons quit:0 -default quit -file -')
-
--- Should not need to be modified on Linux
-wmii.set_conf ("battery.statefile", "/proc/acpi/battery/%s/state")
-wmii.set_conf ("battery.infofile", "/proc/acpi/battery/%s/info")
-
+-- Battery Monitor Plugin, based on the implementation for ruby-wmiirc,
+-- standard-plugin.rb by Mauricio Fernandez <m...@acm.org>
+-- http://eigenclass.org/hiki.rb?wmii+ruby
--
--- Local Variables
+-- Licensed under the terms and conditions of the GPL
--
-local batteries = { }

--- The actual work performed here.
--- parses info, state file and preps for display
-local function update_single_battery ( battery )
+local wmii = require("wmii")
+local io = require("io")
+local os = require("os")
+local string = require("string")
+local tonumber = tonumber

- local printout = "N/A"
- local colors = wmii.get_ctl("normcolors")
+module("battery_monitor")
+api_version=0.1

- local fbatt = io.open(string.format(wmii.get_conf("battery.statefile"), battery["name"] ),"r")
- if fbatt == nil then
- return battery["widget"]:show(printout, colors)
- end
+-- ------------------------------------------------------------
+-- Configuration Settings
+wmii.set_conf ("batmon.statefile", "/proc/acpi/battery/BAT0/state")
+wmii.set_conf ("batmon.infofile", "/proc/acpi/battery/BAT0/info")

- local batt = fbatt:read("*a")
- fbatt:close()
+wmii.set_conf ("batmon.low", 8)
+wmii.set_conf ("batmon.low_action", 'echo "Low battery" | xmessage -center -buttons quit:0 -default quit -file -')

- local battpresent = batt:match('present:%s+(%w+)')
- if battpresent ~= "yes" then
- return battery["widget"]:show(printout, colors)
- end
+wmii.set_conf ("batmon.critical", 2)
+wmii.set_conf ("batmon.critical_action", 'echo "Critical battery" | xmessage -center -buttons quit:0 -default quit -file -')

- local low = wmii.get_conf ("battery.low")
- local critical = wmii.get_conf ("battery.critical")
+wmii.set_conf ("batmon.warned_low", "false")
+wmii.set_conf ("batmon.warned_critical", "false")

- local fbattinfo = io.open(string.format(wmii.get_conf("battery.infofile"), battery["name"]),"r")
- local battinfo = fbattinfo:read("*a")
- fbattinfo:close()
+-- ------------------------------------------------------------
+-- Local Variables
+local warned_low = false
+local warned_critical = false

- local batt_percent = batt:match('remaining capacity:%s+(%d+)')
- / battinfo:match('last full capacity:%s+(%d+)') * 100
- local batt_state = batt:match('charging state:%s+(%w+)')
-
- -- Take action in case battery is low/critical
- if batt_percent <= critical then
- if batt_state == "discharging" and not battery["warned_crit"] then
- wmii.log("Warning about critical battery.")
- os.execute(wmii.get_conf("battmon.critical_action"), "&")
- battery["warned_crit"] = true
- end
- colors = string.gsub(colors, "^%S+ %S+",
- wmii.get_conf ("battery.critical_fgcolor")
- .. " "
- .. wmii.get_conf ("battery.critical_bgcolor"),
- 1)
- elseif batt_percent <= low then
- if batt_state == "discharging" and not battery["warned_low"] then
- wmii.log("Warning about low battery.")
- os.execute(wmii.get_conf("battmon.low_action"), "&")
- battery["warned_low"] = true
- end
- colors = string.gsub(colors, "^%S+ %S+",
- wmii.get_conf ("battery.low_fgcolor")
- .. " "
- .. wmii.get_conf ("battery.low_bgcolor"),
- 1)
- else
- battery["warned_low"] = true
- battery["warned_crit"] = true
- end
+local low = wmii.get_conf ("batmon.low")
+local critical = wmii.get_conf ("batmon.critical")

+local batt = nil
+local battinfo = nil
+local battpresent = nil

- -- If percent is 100 and state is discharging then
- -- the battery is full and not discharging.
- if (batt_state == "charged") or (batt_state == "discharging" and batt_percent >= 97) then
- batt_state = "="
- end
- if batt_state == "charging" then
- batt_state = "^"
- end
- if batt_state == "discharging" then
- batt_state = "v"
- end
+local printout, text = nil

- printout = batt_state .. string.format("%.0f",batt_percent) .. batt_state
+-- ------------------------------------------------------------
+-- Init Plugin
+local widget = wmii.widget:new ("901_battery_monitor")

- battery["widget"]:show(printout, colors)
-end

-- ------------------------------------------------------------
-- The battery status update function (wmii.timer function)
+-- parses info, state file and preps for display
+--
local function update_batt_data (time_since_update)

- local batt_names = wmii.get_conf("battery.names");
-
- for battery in batt_names:gmatch("%w+") do
- if( not batteries[battery] ) then
- batteries[battery] = {
- name = battery,
- widget = wmii.widget:new ("901_battery_" .. battery),
- warned_low = false,
- warned_crit = false,
- }
+ local fbatt = io.open(wmii.get_conf("batmon.statefile"),"r")
+ local fbattinfo = io.open(wmii.get_conf("batmon.infofile"),"r")
+
+ if fbatt ~= nil then
+ batt = fbatt:read("*a")
+ battinfo = fbattinfo:read("*a")
+
+ battpresent = batt:match('present:%s+(%w+)')
+
+ if battpresent == "yes" then
+ batt_percent = batt:match('remaining capacity:%s+(%d+)') /
+ battinfo:match('last full capacity:%s+(%d+)') * 100
+ batt_state = batt:match('charging state:%s+(%w+)')
+
+ --
+ -- Take action in case battery is low/critical
+ --
+ if batt_state == "discharging" and batt_percent <= critical then
+ if not warned_critical then
+ wmii.log("Warning about critical battery.")
+ os.execute(wmii.get_conf("battmon.critical_action"), "&")
+ warned_critical = true
+ end
+ elseif batt_state == "discharging" and batt_percent <= low then
+ if not warned_low then
+ wmii.log("Warning about low battery.")
+ os.execute(wmii.get_conf("battmon.low_action"), "&")
+ warned_low = true
+ end
+ else
+ warned_low = false
+ warned_critical = false
+ end
+
+
+ -- If percent is 100 and state is discharging then
+ -- the battery is full and not discharging.
+ if (batt_state == "charged") or (batt_state == "discharging" and batt_percent >= 97) then
+ batt_state = "="
+ end
+ if batt_state == "charging" then
+ batt_state = "^"
+ end
+ if batt_state == "discharging" then
+ batt_state = "v"
+ end
+
+ local batt_rate = batt:match('present rate:%s+(%d+)') * 1
+
+ local batt_time = "inf"
+ if batt_rate > 0 then
+ if batt_state == "^" then
+ batt_time = (battinfo:match('last full capacity:%s+(%d+)') - batt:match('remaining capacity:%s+(%d+)')) / batt_rate
+ else
+ batt_time = batt:match('remaining capacity:%s+(%d+)') / batt_rate
+ end
+ local hour = string.format("%d",batt_time)
+ local min = (batt_time - hour) * 60
+
+ if min > 59 then
+ min = min - 60
+ hour = hour + 1
+ end
+ if min < 0 then
+ min = 0
+ end
+ batt_time = hour .. ':'
+ batt_time = batt_time .. string.format("%.2d",min)
+ end
+
+ batt_rate = batt_rate/1000
+ printout = string.format("%.2f",batt_rate) .. 'W -> ' .. batt_time .. '(' .. batt_state .. string.format("%.0f",batt_percent) .. batt_state .. ')'
+ else
+ printout = "N/A"
end
- update_single_battery( batteries[battery] )
end

- return wmii.get_conf("battery.poll_rate")
-end
-
+ widget:show(printout)
+ return 5
+end
+-- function update_batt_data
+-- ----------------------------------------------

local timer = wmii.timer:new (update_batt_data, 1)

--
1.6.0.2

que...@gmail.com

unread,
Oct 23, 2008, 4:30:38 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <qu...@informatik.uni-oldenburg.de>

- the script monitors the song currently played in mpd on a given host
- it supplies wrapper methods for stop/pause/prev/next
---
plugins/mpd.lua | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 94 insertions(+), 0 deletions(-)
create mode 100644 plugins/mpd.lua

diff --git a/plugins/mpd.lua b/plugins/mpd.lua
new file mode 100644
index 0000000..f7a8969
--- /dev/null
+++ b/plugins/mpd.lua
@@ -0,0 +1,94 @@
+--[[
+=pod
+
+=head1 NAME
+
+mpd.lua - wmiirc-lua plugin for monitoring and controlling mpd (music player daemon)
+
+=head1 SYNOPSIS
+
+ -- in your wmiirc.lua:
+ wmii.load_plugin("cpu")
+
+
+=head1 DESCRIPTION
+
+=head1 SEE ALSO
+
+L<wmii(1)>, L<lua(1)>
+
+=head1 AUTHOR
+
+Jan-David Quesel <j...@gmx.net>
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright (c) 2008, Jan-David Quesel <j...@gmx.net>
+
+This is free software. You may redistribute copies of it under the terms of
+the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
+is NO WARRANTY, to the extent permitted by law.
+
+=cut
+--]]


+local wmii = require("wmii")
+local io = require("io")
+local os = require("os")
+local string = require("string")
+local tonumber = tonumber

+
+module("mpd")
+api_version=0.1
+


+-- ------------------------------------------------------------
+-- Configuration Settings

+wmii.set_conf ("mpd.server", "127.0.0.1")
+wmii.set_conf ("mpd.port", "6600")
+


+-- ------------------------------------------------------------
+-- Init Plugin

+local widget = wmii.widget:new ("301_mpd_status")
+
+local function _command ( cmd )
+
+ if (cmd) then
+ wmii.log( "about to run " .. cmd)
+ local file = io.popen( cmd)
+ local status = file:read("*a")
+ file:close()
+
+ return status:match("[^\n]*")
+ else
+ return ""
+ end
+end
+
+local function update_mpd_status (time_since_update)
+ local printout = _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc")
+


+ widget:show(printout)
+ return 5
+end
+

+function next_song()
+ _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc next")
+ update_mpd_status(0)
+end
+
+function prev_song()
+ _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc prev")
+ update_mpd_status(0)
+end
+
+function toggle_pause()
+ _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc toggle")
+ update_mpd_status(0)
+end
+
+function stop()
+ _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc stop")
+ update_mpd_status(0)
+end
+
+local timer = wmii.timer:new (update_mpd_status, 1)
+
--
1.6.0.2

que...@gmail.com

unread,
Oct 23, 2008, 4:30:39 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <qu...@informatik.uni-oldenburg.de>

The plugin monitors the current state of the devices wlan0 and eth0. For
the wlan devices it gives the network currently connected to and the IP
address. For the eth device only the latter one.
---
plugins/network.lua | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 100 insertions(+), 0 deletions(-)
create mode 100644 plugins/network.lua

diff --git a/plugins/network.lua b/plugins/network.lua
new file mode 100644
index 0000000..a918eb3
--- /dev/null
+++ b/plugins/network.lua
@@ -0,0 +1,100 @@


+--[[
+=pod
+
+=head1 NAME
+

+network.lua - wmiirc-lua plugin for monitoring network interfaces

+local os = require("os")

+local posix = require("posix")


+local io = require("io")

+local type = type
+local error = error
+local pairs = pairs
+local tostring = tostring
+
+module("network")
+api_version = 0.1
+
+-- ------------------------------------------------------------
+-- MODULE VARIABLES
+local widget = nil
+local timer = nil
+
+widget = wmii.widget:new ("350_network")


+
+local function _command ( cmd )
+
+ if (cmd) then
+ wmii.log( "about to run " .. cmd)
+ local file = io.popen( cmd)
+ local status = file:read("*a")
+ file:close()
+
+ return status:match("[^\n]*")
+ else
+ return ""
+ end
+end
+

+function update ( new_vol )
+ local txt = ""
+ local ssid = "iwconfig wlan0 |grep ESSID | awk -F: '{print $2}'"
+ local wlan0ip = "ifconfig wlan0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
+ local eth0ip = "ifconfig eth0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
+ local str_ssid = _command(ssid)
+ str_ssid = str_ssid.sub(str_ssid, 2, str_ssid.len(str_ssid)-3)
+ local str = _command(wlan0ip)
+ str = str.sub(str, 1, str.len(str))
+
+ if wlan0ip == "" then
+ txt = "wlan0: down eth: "
+ else
+ txt = "wlan0: " .. str .. "@(" .. str_ssid .. ") eth0: "
+ end
+
+ local str_eth0 = _command(eth0ip)
+ str_eth0 = str_eth0.sub(str_eth0, 1, str_eth0.len(str_eth0))
+ if str_eth0 == "" then
+ txt = txt .. "down"
+ else
+ txt = txt .. str_eth0
+ end
+
+ widget:show(txt)
+end
+
+local function network_timer ( timer )
+ update(0)
+ return 60
+end
+
+timer = wmii.timer:new (network_timer, 1)
--
1.6.0.2

Bart Trojanowski

unread,
Oct 23, 2008, 8:17:10 PM10/23/08
to wmii...@googlegroups.com, Jan-David Quesel
Just FYI, I had problems reading the patch because most of it is not
actually changing the content, so I am going to base my review on the
output of...

git show --ignore-all-space ':/collate multiple'

... ran against the pu branch. This reduces the patch from 84 modified
lines to 12; see below.

In general please avoid formatting changes (unless there is good reason
for them).

I see how this idea benefits users with either narrow screens, lots of
plugins, or lots of CPUs. The only concern I have is with a flickering
display when I am running a build and using a varied number of CPUs.

I am opened to suggestions or convincing. Maybe there is something
clever that we can do with colours (which would probably require a
widget per CPU) or with compressing the governor name.

I am also open to making this feature configurable.

But onto the actual patch:

> @@ -101,15 +103,23 @@ local function create_string(cpu)
> frq = ""


> end
>
> - return gov .. " " .. frq

> + return frq .. "(" .. gov .. ")"
> end

That's probably ok. Again if it's too verbose we could have a
lookup table to convert "ondemand" to "od" or something similar.

> function update ( new_vol )

> local txt = ""
> local _, cpu


> local list = cpu_list()
> + local space = ""

> for _,cpu in pairs(list) do
> - txt = txt .. create_string(cpu) .. " "

> + local str = create_string(cpu)
> + if txt == str then
> + txt = "2x " .. txt

This does not scale to more than 2 CPUs.

> + else
> + txt = txt .. create_string(cpu) .. space
> + end
> + space = " "

> end
>
> widget:show(txt)

Thanks.

-Bart

--
WebSig: http://www.jukie.net/~bart/sig/

Bart Trojanowski

unread,
Oct 23, 2008, 8:39:33 PM10/23/08
to wmii...@googlegroups.com, Jan-David Quesel
> +mpd.lua - wmiirc-lua plugin for monitoring and controlling mpd (music player daemon)
> +
> +=head1 SYNOPSIS
> +
> + -- in your wmiirc.lua:
> + wmii.load_plugin("cpu")

That's not entirely true :)

Could the header also include the how next/prev/pause/stop should be
bound to events?

You could for example suggest using keys bound via

mpd = wmii.load_plugin('mpd')
wmii.add_key_handler('XF86AudioStop', mpd.stop())

The above is untested, but should work... if you have XF86AudioStop
defined properly.

> +local function _command ( cmd )
> +
> + if (cmd) then
> + wmii.log( "about to run " .. cmd)
> + local file = io.popen( cmd)
> + local status = file:read("*a")
> + file:close()
> +
> + return status:match("[^\n]*")
> + else
> + return ""
> + end
> +end

How about we teach this _command function about MPD_HOST and MPD_PORT?

> + local printout = _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc")

Also, I think it would be sufficient to run a command that looks like
this:

MPD_HOST=localhost MPD_PORT=6600 mpc status

... i.e. there is no need to export.

Is it just me or there an interface to mpd missing?

I guess my preference would be for the default interface (implemented by
the plugin) to trigger a wmii:menu() using Alt-a mpd which gives you
'play', 'pause', 'stop', 'next', 'prev'.

Maybe something like:

wmii.add_action_handler ("mpd",
function(act,args)
local actions = { 'play', 'pause', 'stop', 'next', 'prev' }
local act = wmii.menu(actions, "mpd: ")
local fn = function_handlers[act]
if fn then
local r, err = pcall (fn)
end
end)

I have not tested the above.

Thanks,
-Bart


> +function next_song()
> + _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc next")
> + update_mpd_status(0)
> +end
> +
> +function prev_song()
> + _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc prev")
> + update_mpd_status(0)
> +end
> +
> +function toggle_pause()
> + _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc toggle")
> + update_mpd_status(0)
> +end
> +
> +function stop()
> + _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc stop")
> + update_mpd_status(0)
> +end
> +
> +local timer = wmii.timer:new (update_mpd_status, 1)
> +
> --
> 1.6.0.2
>
>
>

--
WebSig: http://www.jukie.net/~bart/sig/

Dave O'Neill

unread,
Oct 23, 2008, 9:18:57 PM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
que...@gmail.com wrote:
> The plugin monitors the current state of the devices wlan0 and eth0. For
> the wlan devices it gives the network currently connected to and the IP
> address. For the eth device only the latter one.

Great idea! It might be nice to have it configurable similar to
battery.lua, where you can specify the interfaces you're interested in
with a config like:

wmii.set_conf("net.names", "eth0,eth1")

> + -- in your wmiirc.lua:
> + wmii.load_plugin("cpu")

s/cpu/network/, but Bart's already mentioned that.

> +local os = require("os")
> +local posix = require("posix")

Do you use anything from the "os" or "posix" modules? If not, there's
no need to require them.

> +local type = type
> +local error = error
> +local pairs = pairs
> +local tostring = tostring

None of these appear to be necessary, so they can be removed

> +local function _command ( cmd )
> +
> + if (cmd) then
> + wmii.log( "about to run " .. cmd)
> + local file = io.popen( cmd)
> + local status = file:read("*a")
> + file:close()
> +
> + return status:match("[^\n]*")
> + else
> + return ""
> + end
> +end

We should probably look at making a generic replacement for '_command'
that lives in core/wmii.lua, since it's used so frequently in plugins.

> +function update ( new_vol )

That should probably just be

function update ( )

since new_vol isn't used (cut-and-paste from volume.lua?)

> + local txt = ""
> + local ssid = "iwconfig wlan0 |grep ESSID | awk -F: '{print $2}'"
> + local wlan0ip = "ifconfig wlan0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
> + local eth0ip = "ifconfig eth0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"

Piping to awk is probably not necessary. It's more efficient to read
the command's results in as a whole, and do the parsing in lua with a
match() or two.

> + update(0)

update() doesn't need the arg, as mentioned above.

Cheers,
Dave

Bart Trojanowski

unread,
Oct 23, 2008, 9:29:11 PM10/23/08
to wmii...@googlegroups.com, Jan-David Quesel
* Dave O'Neill <d...@dmo.ca> [081023 21:19]:

> > +local function _command ( cmd )
> > +
> > + if (cmd) then
> > + wmii.log( "about to run " .. cmd)
> > + local file = io.popen( cmd)
> > + local status = file:read("*a")
> > + file:close()
> > +
> > + return status:match("[^\n]*")
> > + else
> > + return ""
> > + end
> > +end
>
> We should probably look at making a generic replacement for '_command'
> that lives in core/wmii.lua, since it's used so frequently in plugins.

That's a good idea.

I am eventually hoping to break out core/wmii.lua into a bunch of files.
How about we start with this as core/wmii/util.lua

If I am not mistaken, require "wmii.util" will import that in.

I wonder if we can set module("wmii") in wmii/util.lua to merge the
scope into one.

Thoughts?

Thanks,

Jan-David Quesel

unread,
Oct 24, 2008, 9:34:56 AM10/24/08
to wmii...@googlegroups.com
Hi,

On Thu, Oct 23, 2008 at 08:39:33PM -0400, Bart Trojanowski wrote:
> Could the header also include the how next/prev/pause/stop should be
> bound to events?
>
> You could for example suggest using keys bound via
>
> mpd = wmii.load_plugin('mpd')
> wmii.add_key_handler('XF86AudioStop', mpd.stop())
>
> The above is untested, but should work... if you have XF86AudioStop
> defined properly.

done.

> > + local printout = _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc")
>
> Also, I think it would be sufficient to run a command that looks like
> this:
>
> MPD_HOST=localhost MPD_PORT=6600 mpc status
>
> ... i.e. there is no need to export.

I thought so too, but for some reason this doesnt work for me. it
works in my shell, but not from inside the lua script... dont
know which shell it executes there... login shell is zsh.

Regards,
Jan

--
Jan-David Quesel
Carl von Ossietzky Universität Oldenburg
Department of Computing Science
Correct System Design
D-26111 Oldenburg, Germany

Phone: +49 (0)441 798-2376
Fax: +49 (0)441 798-2965

Reply all
Reply to author
Forward
0 new messages