error messages when backend is not found or if it does not implement

ICapMessagesReply
This commit is contained in:
Romain Bignon 2010-04-13 10:20:06 +02:00
commit 0c71eb643d

View file

@ -29,7 +29,7 @@ import time
import re import re
import sys import sys
from weboob.capabilities.messages import ICapMessages from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
from weboob.tools.application import ConsoleApplication from weboob.tools.application import ConsoleApplication
from weboob.tools.misc import html2text from weboob.tools.misc import html2text
@ -77,24 +77,19 @@ class Monboob(ConsoleApplication):
content = content.split(u'\n-- \n')[0] content = content.split(u'\n-- \n')[0]
bname, id = reply_to.split('.', 1) bname, id = reply_to.split('.', 1)
backend = self.weboob.backends[bname] try:
backend = self.weboob.backends[bname]
except KeyError:
print >>sys.stderr, 'Backend %s not found' % bname
return 1
if not backend.has_caps(ICapMessagesReply):
print >>sys.stderr, 'The backend %s does not implement ICapMessagesReply' % bname
return 1
thread_id, msg_id = id.rsplit('.', 1) thread_id, msg_id = id.rsplit('.', 1)
backend.post_reply(thread_id, msg_id, title, content) backend.post_reply(thread_id, msg_id, title, content)
MAIL_REGEXP = re.compile('(.*) <(.*)@(.*)>')
def get_mail(self, text):
if not text:
return None
m = self.MAIL_REGEXP.match(text)
if not m:
to = text.split('@')[0]
else:
to = m.group(2)
return to
@ConsoleApplication.command("run daemon") @ConsoleApplication.command("run daemon")
def command_run(self): def command_run(self):
self.weboob.repeat(self.config.get('interval'), self.process) self.weboob.repeat(self.config.get('interval'), self.process)