Beispiel #1
0
def process_request(result, self, request):
    # Call the update trigger on every request
    update_trigger()

    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:
                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

            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
Beispiel #2
0
def process_request(result, self, request):
    # Call the update trigger on every request
    update_trigger()

    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:
                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

            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
Beispiel #3
0
def check_for_updates():
    # Get the SVN Revision
    try:
        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

    admin_emails_xml = '<emails>'
    for email in get_admin_emails():
        admin_emails_xml += '<email value="%s" />' % email
    admin_emails_xml += '</emails>'

    database_type = get_database_engine()

    statistics = u"""<check>
    <key value="%(site_key)s" />
    <app_url value="%(app_url)s" />
    <app_title value="%(app_title)s" />
    <app_description value="%(app_description)s" />
    <svn_revision value="%(svn_revision)d" />
    <views value="%(site_views)d" />
    <questions_count value="%(questions_count)d" />
    <answers_count value="%(answers_count)d" />
    <comments_count value="%(comments_count)d" />
    <active_users value="%(active_users)d" />
    <server value="%(server_name)s" />
    <python_version value="%(python_version)s" />
    <django_version value="%(django_version)s" />
    <database value="%(database)s" />
    <os value="%(os)s" />
    %(emails)s
</check> """ % {
        'site_key' : settings.SITE_KEY,
        'app_url' : APP_URL,
        'app_title' : escape(APP_TITLE.value),
        'app_description' : escape(APP_DESCRIPTION.value),
        '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(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
    post_data = {
        'statistics' : binascii.b2a_base64(statistics_compressed),
    }
    data = urllib.urlencode(post_data)

    # We simulate some browser, otherwise the server can return 403 response
    user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/5'
    headers={ 'User-Agent' : user_agent,}

    try:
        check_request = urllib2.Request('%s%s' % (settings.UPDATE_SERVER_URL, '/site_check/'), data, headers=headers)
        check_response = urllib2.urlopen(check_request)
        content = check_response.read()
    except urllib2.HTTPError, error:
        content = error.read()
Beispiel #4
0
def check_for_updates():
    # Get the SVN Revision
    try:
        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

    admin_emails_xml = '<emails>'
    for email in get_admin_emails():
        admin_emails_xml += '<email value="%s" />' % email
    admin_emails_xml += '</emails>'

    database_type = get_database_engine()

    statistics = u"""<check>
    <key value="%(site_key)s" />
    <app_url value="%(app_url)s" />
    <app_title value="%(app_title)s" />
    <app_description value="%(app_description)s" />
    <svn_revision value="%(svn_revision)d" />
    <views value="%(site_views)d" />
    <questions_count value="%(questions_count)d" />
    <answers_count value="%(answers_count)d" />
    <comments_count value="%(comments_count)d" />
    <active_users value="%(active_users)d" />
    <server value="%(server_name)s" />
    <python_version value="%(python_version)s" />
    <django_version value="%(django_version)s" />
    <database value="%(database)s" />
    <os value="%(os)s" />
    %(emails)s
</check> """ % {
        'site_key': settings.SITE_KEY,
        'app_url': APP_URL,
        'app_title': escape(APP_TITLE.value),
        'app_description': escape(APP_DESCRIPTION.value),
        '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(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
    post_data = {
        'statistics': binascii.b2a_base64(statistics_compressed),
    }
    data = urllib.urlencode(post_data)

    # We simulate some browser, otherwise the server can return 403 response
    user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/5'
    headers = {
        'User-Agent': user_agent,
    }

    try:
        check_request = urllib2.Request(
            '%s%s' % (settings.UPDATE_SERVER_URL, '/site_check/'),
            data,
            headers=headers)
        check_response = urllib2.urlopen(check_request)
        content = check_response.read()
    except urllib2.HTTPError, error:
        content = error.read()