X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/f348841cd8271ffe37e819042c912fbda35cce62..9b8e2e53b0f70f91868b4c16e130967c7da5a958:/forum_modules/updates/base.py diff --git a/forum_modules/updates/base.py b/forum_modules/updates/base.py index 366ce4d..fe7a003 100644 --- a/forum_modules/updates/base.py +++ b/forum_modules/updates/base.py @@ -1,5 +1,8 @@ +# -*- coding: utf-8 -*- + import os import sys +import platform import bz2 import urllib2, urllib import binascii @@ -14,10 +17,9 @@ import logging from xml.dom.minidom import parse, parseString from forum.base import get_database_engine -from forum.models import Question, User -from forum.settings import APP_URL, SVN_REVISION, APP_TITLE, APP_DESCRIPTION +from forum.models import Question, Answer, Comment, User +from forum.settings import APP_URL, VCS_REVISION, APP_TITLE, APP_DESCRIPTION from django import VERSION as DJANGO_VERSION -from django.utils import simplejson from django.utils.html import escape from django.utils.encoding import smart_unicode from django.conf import settings as django_settings @@ -79,7 +81,7 @@ def get_admin_emails(): def check_for_updates(): # Get the SVN Revision try: - svn_revision = int(SVN_REVISION.replace('SVN-', '')) + svn_revision = int(VCS_REVISION.replace('SVN-', '')) except ValueError: # Here we'll have to find another way of getting the SVN revision svn_revision = 0 @@ -91,13 +93,16 @@ def check_for_updates(): database_type = get_database_engine() - statistics = """ + statistics = u""" + + + @@ -113,15 +118,19 @@ def check_for_updates(): 'svn_revision' : svn_revision, 'site_views' : get_site_views(), 'server_name' : get_server_name(), + 'questions_count' : Question.objects.filter_state(deleted=False).count(), + 'answers_count' : Answer.objects.filter_state(deleted=False).count(), + 'comments_count' : Comment.objects.filter_state(deleted=False).count(), 'active_users' : get_active_users(), 'python_version' : ''.join(sys.version.splitlines()), 'django_version' : str(DJANGO_VERSION), 'database' : database_type, - 'os' : str(os.uname()), + 'os' : str(platform.uname()), 'emails' : admin_emails_xml, } # Compress the statistics XML dump + statistics = statistics.encode('ascii', 'xmlcharrefreplace') statistics_compressed = bz2.compress(statistics) # Pass the compressed statistics to the update server @@ -168,7 +177,10 @@ def update_trigger(): # Trigger the update process now = datetime.datetime.now() if (now - settings.LATEST_UPDATE_DATETIME) > datetime.timedelta(days=1): - update_status = check_for_updates() - - logging.error(smart_unicode("Update process has been triggered: %s" % update_status)) - settings.LATEST_UPDATE_DATETIME.set_value(now) + try: + update_status = check_for_updates() + logging.log(logging.INFO, smart_unicode("Update process has been triggered: %s" % update_status)) + except Exception, e: + logging.errror(smart_unicode(e)) + finally: + settings.LATEST_UPDATE_DATETIME.set_value(now)