send error implementation

send an error to a user only if he has not already been notified

darcs-hash:20070222172740-86b55-7032fdab46f54932c222c36a68bad0915120e92c.gz
This commit is contained in:
David Rousselie
2007-02-22 18:27:40 +01:00
parent 826d045b41
commit d83ad1debe
5 changed files with 72 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ import time
import logging
import signal
import re
import traceback
from Queue import Queue
@@ -328,11 +329,12 @@ class JCLComponent(Component, object):
def get_reg_form_for_account(_account_class, name, base_from_jid):
self.db_connect()
# TODO : do it only one time
for _account in _account_class.select(\
_accounts = _account_class.select(\
AND(_account_class.q.name == name, \
_account_class.q.user_jid == base_from_jid)):
_account_class.q.user_jid == base_from_jid))
if _accounts is not None:
self.get_reg_form_init(lang_class, \
_account).as_xml(query)
_accounts[0]).as_xml(query)
self.db_disconnect()
self.__logger.debug("GET_REGISTER")
@@ -719,6 +721,23 @@ class JCLComponent(Component, object):
(_account.name))
self.stream.send(msg)
def _send_error(self, _account, exception):
"""Send an error message only one time until _account.in_error
has been reset to False"""
if _account.in_error == False:
_account.in_error = True
msg = Message(from_jid = _account.jid, \
to_jid = _account.user_jid, \
stanza_type = "error", \
subject = _account.default_lang_class.check_error_subject, \
body = _account.default_lang_class.check_error_body \
% (exception))
self.stream.send(msg)
type, value, stack = sys.exc_info()
self.__logger.debug("Error while first checking mail : %s\n%s" \
% (exception, "".join(traceback.format_exception
(type, value, stack, 5))))
def get_jid(self, _account):
"""Return account jid based on account instance and component jid
"""

View File

@@ -107,8 +107,8 @@ class Lang:
# connection_label = u"%s connection '%s'"
# update_account_message_subject = u"Updated account '%s'"
# update_account_message_body = u"Updated account"
# check_error_subject = u"Error while checking emails."
# check_error_body = u"An error appears while checking emails:\n\t%s"
check_error_subject = u"Error while checking emails."
check_error_body = u"An error appears while checking emails:\n\t%s"
# new_mail_subject = u"New email from %s"
# new_digest_subject = u"%i new email(s)"

View File

@@ -27,7 +27,7 @@
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
from sqlobject.inheritance import InheritableSQLObject
from sqlobject.col import StringCol, EnumCol, IntCol
from sqlobject.col import StringCol, EnumCol, IntCol, BoolCol
from sqlobject.dbconnection import ConnectionHub
from jcl.lang import Lang
@@ -68,6 +68,7 @@ class Account(InheritableSQLObject):
jid = StringCol()
## Not yet used first_check = BoolCol(default = True)
__status = StringCol(default = OFFLINE, dbName = "status")
in_error = BoolCol(default = False)
## Use these attributs to support volatile password
## login = StringCol(default = "")
@@ -211,3 +212,17 @@ class PresenceAccount(Account):
is_action_possible, mandatory_field)]
get_register_fields = classmethod(_get_register_fields)
def get_action(self):
"""Get apropriate action depending on current status"""
mapping = {"online": self.online_action,
"chat": self.chat_action,
"away": self.away_action,
"xa": self.xa_action,
"dnd": self.dnd_action,
"offline": self.offline_action}
if mapping.has_key(self.status):
return mapping[self.status]
return PresenceAccount.DO_NOTHING
action = property(get_action)