making use of case sensitivity
[svn42.git] / play-sound-status.py
index cbb6321..752a2ea 100755 (executable)
@@ -28,6 +28,8 @@ class UWSConfig:
   def __init__(self,configfile=None):
     self.configfile=configfile
     self.config_parser=ConfigParser.ConfigParser()
+    #make option variable names case sensitive
+    self.config_parser.optionxform = str
     self.config_parser.add_section('cmdlog')
     self.config_parser.set('cmdlog','cmd',"logger %ARG%")
     self.config_parser.set('cmdlog','timeout',"2.0")
@@ -64,12 +66,16 @@ class UWSConfig:
     self.config_parser.add_section('gladosreplaced')
     self.config_parser.set('gladosreplaced','arg',"/home/glados_replaced_with_life_fire.mp3")
     self.config_parser.set('gladosreplaced','type',"slugplaymp3")
+    self.config_parser.add_section('nothing')
+    self.config_parser.set('nothing','type',"nothing")
     self.config_parser.add_section('mapping')
-    self.config_parser.set('mapping','default',"halflife2")
-    self.config_parser.set('mapping','panic',"monkeyscream")
+    self.config_parser.set('mapping','DEFAULT',"halflife2")
+    self.config_parser.set('mapping','PANIC',"monkeyscream")
+    self.config_parser.set('mapping','ERROR',"nothing")
     self.config_parser.set('mapping','stratos',"tardis")
     self.config_parser.set('mapping','xro',"gladosreplaced")
     self.config_parser.set('mapping','equinox',"gladosparty")
+    self.config_parser.set('mapping','Rachel',"nothing")
     self.config_parser.add_section('debug')
     self.config_parser.set('debug','enabled',"False")
     self.config_parser.add_section('tracker')
@@ -197,15 +203,17 @@ def executeAction(action_name, args=[]):
     return runRemoteCommand(uwscfg.getValue(action_name+"_remote_host"), uwscfg.getValue(action_name+"_remote_shell"), args)
   elif action_type == "shellcmd":
     return runShellCommand(cmd=uwscfg.getValue(action_name+"_cmd"), ptimeout=uwscfg.getValue(action_name+"_timeout"), stdinput=uwscfg.getValue(action_name+"_stdinput"), args=args)
+  elif action_type == "nothing":
+    return True
   else:
     return executeAction(action_type,args)
   
-def playThemeOf(user):
+def playThemeOf(user,fallback_default):
   global uwscfg
   uwscfg.checkConfigUpdates()
   config=uwscfg.getValue("mapping_"+str(user))
   if config is None:
-    config=uwscfg.getValue("mapping_default")
+    config=uwscfg.getValue("mapping_"+str(fallback_default))
   logging.debug("playThemeOf: action for user %s: %s" % (user,config))
   executeAction(config,[])
 
@@ -292,7 +300,9 @@ else:
 #socket.setdefaulttimeout(10.0) #affects all new Socket Connections (urllib as well)
 RE_PRESENCE = re.compile(r'Presence: (yes|no)(?:, (opened|closed), (.+))?')
 RE_BUTTON = re.compile(r'PanicButton|button\d?')
-RE_REQUEST = re.compile(r'Request: (\w+) (?:(Card|Phone) )?(.+)')
+#RE_REQUEST = re.compile(r'Request: (\w+) (?:(Card|Phone) )?(.+)')
+RE_ERROR = re.compile(r'Error: (.+)')
+
 while True:
   try:
     if not os.path.exists(uwscfg.tracker_socket):
@@ -321,12 +331,17 @@ while True:
         last_status=(status == "yes")
         unixts_panic_button=None
         if last_status:
-          playThemeOf(user=m.group(3))
+          playThemeOf(user=m.group(3), fallback_default="DEFAULT")
         continue
         
       m = RE_BUTTON.match(line)
       if not m is None:
-        playThemeOf(user="panic")
+        playThemeOf(user="PANIC")
+      continue
+
+      m = RE_ERROR.match(line)
+      if not m is None:
+        playThemeOf(user="ERROR")
       continue
                 
   except Exception, ex: