From: jordan Date: Mon, 25 Apr 2011 16:27:49 +0000 (+0000) Subject: listen for ExpatError exceptions in the startup.py file, they may occur if the UPDATE... X-Git-Tag: live~309 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/4e0ff8fea904bceac70375636410eed0c74012ae listen for ExpatError exceptions in the startup.py file, they may occur if the UPDATE_MESSAGES_XML setting is empty or if the update server didn't return any messages for some reason git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1004 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum_modules/updater/startup.py b/forum_modules/updater/startup.py index ca32986..f49d106 100644 --- a/forum_modules/updater/startup.py +++ b/forum_modules/updater/startup.py @@ -4,6 +4,7 @@ import logging import settings from xml.dom.minidom import parse, parseString +from xml.parsers.expat import ExpatError from forum.modules import ui, decorate from forum.settings import SVN_REVISION from django.contrib.auth.middleware import AuthenticationMiddleware @@ -18,31 +19,35 @@ def process_request(result, self, request): # Call the update trigger on every request update_trigger() - messages_dom = parseString(smart_str(settings.UPDATE_MESSAGES_XML.value)) - messages = messages_dom.getElementsByTagName('message') - - for message in messages: - # Get the SVN Revision - try: - svn_revision = int(SVN_REVISION.replace('SVN-', '')) - except ValueError: - # Here we'll have to find another way of getting the SVN revision - svn_revision = 0 - - message_body = message.getElementsByTagName('body')[0].firstChild.nodeValue - message_revision = int(message.getElementsByTagName('revision')[0].firstChild.nodeValue) - - # Add the message to the user messages set only if the Message Revision number is greater than the - # current installation SVN Revision number and only if the current user is a super user. - if message_revision >= svn_revision and request.user.is_superuser: - # We do not want to repeat ourselves. If the message already exists in the message list, we're not going to - # add it. That's why first of all we're going the check if it is there. + try: + messages_dom = parseString(smart_str(settings.UPDATE_MESSAGES_XML.value)) + messages = messages_dom.getElementsByTagName('message') + + for message in messages: + # Get the SVN Revision try: - # If the message doesn't exist in the RelatedManager ObjectsDoesNotExist is going to be raised. - request.user.message_set.all().get(message=message_body) - except ObjectDoesNotExist: - # Let's create the message. - request.user.message_set.create(message=message_body) - except: - pass + svn_revision = int(SVN_REVISION.replace('SVN-', '')) + except ValueError: + # Here we'll have to find another way of getting the SVN revision + svn_revision = 0 + + message_body = message.getElementsByTagName('body')[0].firstChild.nodeValue + message_revision = int(message.getElementsByTagName('revision')[0].firstChild.nodeValue) + + # Add the message to the user messages set only if the Message Revision number is greater than the + # current installation SVN Revision number and only if the current user is a super user. + if message_revision >= svn_revision and request.user.is_superuser: + # We do not want to repeat ourselves. If the message already exists in the message list, we're not going to + # add it. That's why first of all we're going the check if it is there. + try: + # If the message doesn't exist in the RelatedManager ObjectsDoesNotExist is going to be raised. + request.user.message_set.all().get(message=message_body) + except ObjectDoesNotExist: + # Let's create the message. + request.user.message_set.create(message=message_body) + except: + pass + except ExpatError: + pass + return result \ No newline at end of file