--- a/mcevent.py Sat Jun 21 20:31:38 2008 +0200
+++ b/mcevent.py Sat Jun 21 21:15:00 2008 +0200
@@ -24,7 +24,7 @@
'snd_cmd_msg_in': '/usr/bin/play -V0 -v3 sound.wav',
}
-NOTIFY_TIMEOUT=4000
+NOTIFY_TIMEOUT = 4000
contact_map = { }
# Nickname used for the notification
@@ -41,14 +41,15 @@
blacklist = { }
# No notification for these JIDs
-CMD_ESPEAK="/usr/bin/espeak"
+CMD_ESPEAK = "/usr/bin/espeak"
+
+ENCODING = ''
def init_notify():
import locale
- global encoding
- global NOTIFY_LOADED
+ global ENCODING, NOTIFY_LOADED
pynotify.init('mcnotify')
- encoding = (locale.getdefaultlocale())[1]
+ ENCODING = (locale.getdefaultlocale())[1]
NOTIFY_LOADED = True
def read_conf_from_file():
@@ -77,24 +78,25 @@
opt['snd_cmd_msg_in'] = config.get("Notifications", "snd_cmd_msg_in")
if config.has_section("Contacts"):
- for id in config.options("Contacts"):
- contact_map[id] = config.get("Contacts", id)
+ for cid in config.options("Contacts"):
+ contact_map[cid] = config.get("Contacts", cid)
if config.has_section("Contact_Customized_Messages"):
- for id in config.options("Contact_Customized_Messages"):
- contact_custom_msg[id] = config.get("Contact_Customized_Messages", id)
+ for cid in config.options("Contact_Customized_Messages"):
+ contact_custom_msg[cid] = config.get("Contact_Customized_Messages",
+ cid)
if config.has_section("Alerts"):
- for id in config.options("Alerts"):
- online_alerts[id] = int(config.get("Alerts", id))
+ for cid in config.options("Alerts"):
+ online_alerts[cid] = int(config.get("Alerts", cid))
if config.has_section("Voicemap"):
- for id in config.options("Voicemap"):
- voicemap[id] = config.get("Voicemap", id)
+ for cid in config.options("Voicemap"):
+ voicemap[cid] = config.get("Voicemap", cid)
if config.has_section("Blacklist"):
- for id in config.options("Blacklist"):
- blacklist[id] = int(config.get("Blacklist", id))
+ for cid in config.options("Blacklist"):
+ blacklist[cid] = int(config.get("Blacklist", cid))
if opt['use_notify'] and not NOTIFY_LOADED:
init_notify()
@@ -107,8 +109,8 @@
child_stdin.close()
def notify(buddy, msg, timeout):
- msgbox = pynotify.Notification(unicode(buddy, encoding),
- unicode(msg, encoding))
+ msgbox = pynotify.Notification(unicode(buddy, ENCODING),
+ unicode(msg, ENCODING))
msgbox.set_timeout(timeout)
msgbox.set_urgency(pynotify.URGENCY_LOW)
msgbox.show()
@@ -135,20 +137,18 @@
print "Ignoring invalid event line."
return
elif argn == 2:
- event,arg1 = args[0:2]
- arg2 = None
- filename = None
+ event, arg1 = args[0:2]
+ arg2 = None
+ filename = None
elif argn == 3:
- event,arg1,arg2 = args[0:3]
- filename = None
+ event, arg1, arg2 = args[0:3]
+ filename = None
else:
# For now we simply ignore the file name
- event,arg1,arg2 = args[0:3]
- filename = None
+ event, arg1, arg2 = args[0:3]
+ filename = None
if event == 'MSG' and arg1 == 'IN':
- import os
-
jid = arg2
if not jid:
print "Ignoring invalid MSG event line."
@@ -188,17 +188,15 @@
elif event == 'STATUS':
jid = arg2
if arg1 == 'O' and jid in online_alerts:
- import os
-
- type = online_alerts[jid]
- if type > 0:
+ alert_type = online_alerts[jid]
+ if alert_type > 0:
if opt['use_sound']:
os.system(opt['snd_cmd_msg_in'] + '> /dev/null 2>&1')
buddy = get_nick(jid)
if opt['use_notify']:
- if type == 1:
+ if alert_type == 1:
timeout = NOTIFY_TIMEOUT
else:
timeout = pynotify.EXPIRES_NEVER
@@ -223,7 +221,7 @@
##### MAIN #####
try:
- opts, args = getopt.getopt(sys.argv[1:], "c:", ["help", "output="])
+ opts, cargs = getopt.getopt(sys.argv[1:], "c:", ["help", "output="])
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
@@ -242,7 +240,7 @@
read_conf_from_file()
-# read stdin line by line
+# Read stdin line by line, and process the commands
while 1:
try:
line = sys.stdin.readline()
@@ -264,4 +262,4 @@
sys.exit(0)
-# vim:set et sts=4 sw=4:
+# vim:set si et sts=4 sw=4: