# HG changeset patch # User Sandro Knauß # Date 1259024561 -3600 # Node ID 0d7ffb9b2c7fa8a316def9b0c6b215a2354f480b # Parent fcf8489f1c2f18c0270f1327fb9d485c893b917a logging started diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/.eric4project/iro.e4q --- a/iro/.eric4project/iro.e4q Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/.eric4project/iro.e4q Tue Nov 24 02:02:41 2009 +0100 @@ -1,7 +1,7 @@ - + \ No newline at end of file diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/.eric4project/iro.e4t --- a/iro/.eric4project/iro.e4t Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/.eric4project/iro.e4t Tue Nov 24 02:02:41 2009 +0100 @@ -1,6 +1,6 @@ - + \ No newline at end of file diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/anbieter/sipgate.py --- a/iro/anbieter/sipgate.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/anbieter/sipgate.py Tue Nov 24 02:02:41 2009 +0100 @@ -41,6 +41,8 @@ def sendSMS(self,sms,recipients): """send SMS with $sms to $recipients""" + import logging + logging.debug('sipgate.sendSMS(%s,%s)'%(sms, str(recipients))) args={ "TOS" : "text", "Content" : sms.content @@ -49,6 +51,8 @@ def sendFAX(self,fax,recipients): """send the PDF file $fax to $recipients""" + import logging + logging.debug('sipgate.sendFAX(%s,%s)'%(fax, str(recipients))) pdf=open(fax.attachments[0],"rb") args={ "TOS" : "fax", diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/anbieter/smstrade.py --- a/iro/anbieter/smstrade.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/anbieter/smstrade.py Tue Nov 24 02:02:41 2009 +0100 @@ -88,6 +88,8 @@ def sendSMS(self,sms,recipients): """send SMS with $sms to $recipients""" + import logging + logging.debug('smstrade.sendSMS(%s,%s)'%(sms, str(recipients))) sended = [] key = self.key route = unicode(self.route) @@ -100,7 +102,7 @@ if tel in sended: #only send message once per recipient continue sended.append(tel) - to = unicode(tel.land+tel.number).strip() + to ='00'+tel.land+tel.number if tel.land == '49': route=unicode("basic") else: @@ -117,6 +119,8 @@ """ This function is the main part of the request to the sms service. The function has to return a unicode formated string that will represent the answer of the sms service to the request.""" + import logging + logging.debug('smstrade._send(%s,%s,%s,%s,%s,%s)'%( key, route, to, message, from_, timestamp)) parameters= {"key": key, "route": route, "to": to, @@ -133,6 +137,7 @@ parameters["concat_sms"] = "1" if len(message) > 160 else "0" params = "&".join( ["%s=%s" % (urllib.quote(k),urllib.quote(v.encode("utf-8"))) for (k, v) in parameters.items()]) + logging.debug('smstrade._send-parameters:%s\n\t->%s'%(str(parameters), str(params)) ) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("%s:%i" % (self.gateway, self.gatewayPort)) @@ -142,7 +147,7 @@ data = response.read() except socket.gaierror: raise InternetConnectionError("%s:%i" % (self.gateway, self.gatewayPort)) - else: + finally: conn.close() try: diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/anbieter/smtp.py --- a/iro/anbieter/smtp.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/anbieter/smtp.py Tue Nov 24 02:02:41 2009 +0100 @@ -16,7 +16,6 @@ import smtplib import ConfigParser - class SMTP(): def __init__(self,config_filename=None,section="smtp"): self.config_filename=config_filename @@ -66,6 +65,8 @@ self.bStart=True def sendMail(self,mail,recipients): + import logging + logging.debug('SMTP.sendMail(%s,%s)'%(mail, str(recipients))) if not self.bStart: self.prepareSMTP() @@ -73,6 +74,8 @@ while len(recipients) > 0: tmp_recipients=recipients[:self.max_recipients] + mail.content['To']=", ".join(tmp_recipients) + logging.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from, str(tmp_recipients), mail.as_string())) self.smtp.sendmail(self.send_from, tmp_recipients, mail.as_string()) self.updateStatus( arranged=tmp_recipients) recipients = recipients[self.max_recipients:] diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/iro.py --- a/iro/iro.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/iro.py Tue Nov 24 02:02:41 2009 +0100 @@ -11,8 +11,12 @@ #You should have received a copy of the GNU General Public License #along with this program; if not, see . +import multiprocessing, logging +#logging anfangen +logging.basicConfig(level=logging.DEBUG, format='%(levelname)s-[%(asctime)s %(processName)s (%(threadName)s)]%(message)s') + + # Server code - from xmlrpc import SecureUserDBXMLRPCServer,UserDB from user import User, Admin @@ -83,6 +87,8 @@ def start(userlist): from multiprocessing import Queue from multiprocessing.managers import BaseManager + import multiprocessing, logging + class MyManager(BaseManager): pass @@ -136,10 +142,17 @@ certificate=cert,privatekey=key) server.relam="xmlrpc" - print "Server started..." - server.serve_forever() - - worker.terminate() + logging.info('Server gestartet...') + try: + server.serve_forever() + except KeyboardInterrupt: + pass + except: + logging.exception('Äh, ein Fehler ist aufgetreten') + finally: + logging.info('Server wird beendet...') + queue.close() + worker.terminate() if __name__ == '__main__': userlist=[{"name":"test","password":"test", "class":User}, diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/job.py --- a/iro/job.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/job.py Tue Nov 24 02:02:41 2009 +0100 @@ -22,6 +22,7 @@ self.name=name self.status = "init" self.dStatus={"good":[], "failed":[]} + self.id=None def start(self): self.status = "started" @@ -41,12 +42,16 @@ return None def addGood(self, good): + import logging + logging.debug('Job(%d)-send to %s'%(self.id, str(good))) if type(good) == list: self.dStatus['good']=self.dStatus['good']+good else: self.dStatus['good'].append(good) def addFailed(self, failed): + import logging + logging.debug('Job(%d)-faild to send to %s'%(self.id, str(failed))) if type(failed) == list: self.dStatus['failed']=self.dStatus['failed']+failed else: @@ -64,7 +69,8 @@ def stop(self): pass - def start(self): + def start(self, id=None): + self.id=id Job.start(self) self.getProvider().setJob(self) self.message.sendto(self.getProvider(), self.recipients) @@ -83,9 +89,6 @@ def getProvider(self): return self.providerlist.getProvider("sms", self.provider) - - def start(self): - MessageJob.start(self) class FAXJob(MessageJob): def __init__(self,providerlist,provider, name, message,recipients): diff -r fcf8489f1c2f -r 0d7ffb9b2c7f iro/worker.py --- a/iro/worker.py Mon Nov 23 00:18:04 2009 +0100 +++ b/iro/worker.py Tue Nov 24 02:02:41 2009 +0100 @@ -2,6 +2,7 @@ # Worker code from multiprocessing import Process +import logging import time class Worker(Process): @@ -10,8 +11,16 @@ self.queue=queue def run(self): + logging.info('Worker thread läuft nun...') + id=0 while 1: job=self.queue.get() if job is None: break # reached end of queue - job.start() + id+=1 + logging.info('ein neuer Job(%d)' %(id)) + try: + job.start(id) + logging.info('Job(%d) fertig ;)'%(id)) + except: + logging.exception('Job(%d) fehlgeschlagen :('%(id))