Example #1
0
    def process_request(self, request):
        """
        load site config, return a dummy response if database seems
        uninitialized
        """
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(config.get(
                'BUILDVERSION', DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(config.get(
                'TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))
            if db_tt_buildversion < code_tt_buildversion:
                """
                Toolkit build version changed. clear stale quality checks data
                """
                logging.info(
                    "New Translate Toolkit version, flushing quality checks")
                dbupdate.flush_quality_checks()
                config.set('TT_BUILDVERSION', code_tt_buildversion)
                config.save()
                response.tt_buildversion = db_tt_buildversion

            if (response.db_buildversion, response.tt_buildversion) != (
                sys.maxint, sys.maxint):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in (
                'OperationalError', 'ProgrammingError', 'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
Example #2
0
    def process_request(self, request):
        """Load site config, return a dummy response if database seems
        uninitialized.
        """
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(config.get('BUILDVERSION',
                                             DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(config.get('TT_BUILDVERSION',
                                                DEFAULT_TT_BUILDVERSION))
            if (response.db_buildversion == sys.maxint and
                db_tt_buildversion < code_tt_buildversion):
                # Toolkit build version changed. Stale quality checks need to
                # be cleared. We can only do that safely when the db schema is
                # already up to date. The new toolkit version will be set by
                # dbupdate after it fixed things.
                response.tt_buildversion = db_tt_buildversion

            if ((response.db_buildversion, response.tt_buildversion) !=
                (sys.maxint, sys.maxint)):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if (e.__class__.__name__ in
                ('OperationalError', 'ProgrammingError', 'DatabaseError')):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
Example #3
0
    def process_request(self, request):
        """load site config, return a dummy response if database seems uninitialized"""
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(
                config.get('BUILDVERSION', DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(
                config.get('TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))
            if response.db_buildversion == sys.maxint and db_tt_buildversion < code_tt_buildversion:
                # Toolkit build version changed. Stale quality checks need to
                # be cleared. We can only do that safely when the db schema is
                # already up to date. The new toolkit version will be set by
                # dbupdate after it fixed things.
                response.tt_buildversion = db_tt_buildversion

            if (response.db_buildversion,
                    response.tt_buildversion) != (sys.maxint, sys.maxint):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in ('OperationalError', 'ProgrammingError',
                                        'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
    def process_request(self, request):
        """load site config, return a dummy response if database seems uninitialized"""
        #FIXME: can't we find a more efficient method?
        try:
            config = siteconfig.load_site_config()
            db_buildversion = config.get('BUILDVERSION', DEFAULT_BUILDVERSION)
            if db_buildversion < code_buildversion:
                response = HttpResponse()
                response.status_code = UPDATE_STATUS_CODE
                response.db_buildversion = db_buildversion
                return response

            db_tt_buildversion = config.get('TT_BUILDVERSION',
                                            DEFAULT_TT_BUILDVERSION)
            if db_tt_buildversion < code_tt_buildversion:
                """Toolkit build version changed. clear stale quality checks data"""
                logging.info(
                    "New Translate Toolkit version, flushing quality checks")
                from pootle_store.models import Store, QualityCheck, CHECKED, PARSED
                Store.objects.filter(state=CHECKED).update(state=PARSED)
                QualityCheck.objects.filter(false_positive=False).delete()
                config.set('TT_BUILDVERSION', code_tt_buildversion)
                config.save()

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in ('OperationalError', 'ProgrammingError',
                                        'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response