-def sendXmppMsg(recipients, msg, resource = "torwaechter", addtimestamp = True, noofflinemsg = False):
- if type(recipients) == types.ListType:
- recipients = " ".join(recipients)
- if type(recipients) == types.UnicodeType:
- recipients = recipients.decode("utf-8")
- if type(recipients) != types.StringType:
- raise Exception("list of recipients in unknown format, can't send message")
- if recipients == "" or msg == "":
- return
-
- sendxmpp_cmd = "sendxmpp -u realrauminfo -p 5SPjTdub -j jabber.tittelbach.at -t "
- if resource:
- sendxmpp_cmd += "-r %s " % resource
- if noofflinemsg:
- sendxmpp_cmd += "--headline "
- sendxmpp_cmd += recipients
-
- if addtimestamp:
- msg += time.strftime(" (%Y-%m-%d %T)")
+ def writeConfigFile(self):
+ if self.configfile is None:
+ return
+ logging.debug("Writing Configfile "+self.configfile)
+ try:
+ cf_handle = open(self.configfile,"w")
+ self.config_parser.write(cf_handle)
+ cf_handle.close()
+ self.config_mtime=os.path.getmtime(self.configfile)
+ except IOError, io_ex:
+ logging.error("Error writing Configfile: "+str(io_ex))
+ self.configfile=None
+
+ def __getattr__(self, name):
+ underscore_pos=name.find('_')
+ if underscore_pos < 0:
+ raise AttributeError
+ try:
+ return self.config_parser.get(name[0:underscore_pos], name[underscore_pos+1:])
+ except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
+ raise AttributeError
+
+def popenTimeout1(cmd, pinput, returncode_ok=[0], ptimeout = 20.0, pcheckint = 0.25):
+ logging.debug("popenTimeout1: starting: " + cmd)
+ try:
+ sppoo = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True)
+ sppoo.communicate(input=pinput)
+ timeout_counter=ptimeout
+ while timeout_counter > 0:
+ time.sleep(pcheckint)
+ timeout_counter -= pcheckint
+ if not sppoo.poll() is None:
+ logging.debug("popenTimeout2: subprocess %d finished, returncode: %d" % (sppoo.pid,sppoo.returncode))
+ return (sppoo.returncode in returncode_ok)
+ #timeout reached
+ logging.error("popenTimeout1: subprocess took too long (>%fs), sending SIGTERM to pid %d" % (ptimeout,sppoo.pid))
+ if sys.hexversion >= 0x020600F0:
+ sppoo.terminate()
+ else:
+ subprocess.call(["kill",str(sppoo.pid)])
+ time.sleep(1.0)
+ if sppoo.poll() is None:
+ logging.error("popenTimeout1: subprocess still alive, sending SIGKILL to pid %d" % (sppoo.pid))
+ if sys.hexversion >= 0x020600F0:
+ sppoo.kill()
+ else:
+ subprocess.call(["kill","-9",str(sppoo.pid)])
+ return False
+ except Exception, e:
+ logging.error("popenTimeout1: "+str(e))
+ return False