コード例 #1
0
 def run(self):
     self.failing = False
     try:
         self.metadata_information = extract_metadata_information(self.app_url, self.cached_requests, self.force_reload)
     except Exception:
         logger.warning("Error extracting information from %s" % self.app_url, exc_info = True)
         self.metadata_information = {}
         self.failing = True
     self.finished = True
コード例 #2
0
 def run(self):
     self.failing = False
     try:
         self.metadata_information = extract_metadata_information(self.app_url, self.cached_requests, self.force_reload)
     except Exception:
         logger.warning("Error extracting information from %s" % self.app_url, exc_info = True)
         if DEBUG_VERBOSE:
             print("Error extracting information from %s" % self.app_url)
             traceback.print_exc()
         self.metadata_information = {}
         self.failing = True
     else:
         self.failing = self.metadata_information.get('failing', False)
     self.finished = True
コード例 #3
0
 def run(self):
     self.failing = False
     try:
         self.metadata_information = extract_metadata_information(
             self.app_url, self.cached_requests, self.force_reload)
     except Exception:
         logger.warning("Error extracting information from %s" %
                        self.app_url,
                        exc_info=True)
         if DEBUG_VERBOSE:
             print("Error extracting information from %s" % self.app_url)
             traceback.print_exc()
         self.metadata_information = {}
         self.failing = True
     else:
         self.failing = self.metadata_information.get('failing', False)
     self.finished = True
コード例 #4
0
def _add_or_update_app(cached_requests,
                       app_url,
                       force_reload,
                       repo_app=None,
                       task=None):
    now = datetime.datetime.utcnow()

    if DEBUG:
        logger.debug("Starting %s" % app_url)

    failing = False
    if task is None:
        try:
            metadata_information = extract_metadata_information(
                app_url, cached_requests, force_reload)
        except Exception:
            if DEBUG_VERBOSE:
                print("Error on %s" % app_url)
                traceback.print_exc()
            logger.warning("Error extracting information from %s" % app_url,
                           exc_info=True)
            metadata_information = {}
            failing = True
    else:
        metadata_information = task.metadata_information or {}
        failing = task.failing

    if repo_app is not None:
        if metadata_information.get('translatable') and len(
                metadata_information.get('default_translations', [])) > 0:
            repo_app.translatable = True
        else:
            # If it is translatable but there is no default translation; don't take it into account
            repo_app.translatable = False
        repo_app.adaptable = metadata_information.get('adaptable', False)
        repo_app.original_translations = u','.join(
            metadata_information.get('original_translations', {}).keys())
        repo_app.last_change = now
        repo_app.last_check = now

        if failing:
            if not repo_app.failing:
                # Don't override if it was not failing before
                repo_app.failing_since = now
            repo_app.failing = True

        else:
            if repo_app.failing:
                repo_app.failing = False

    default_user = get_golab_default_user()

    if metadata_information.get('translatable'):
        translation_url = metadata_information.get('default_translation_url')
        original_messages = metadata_information['default_translations']
        default_metadata = metadata_information['default_metadata']
        for language, translated_messages in metadata_information[
                'original_translations'].iteritems():
            add_full_translation_to_app(
                user=default_user,
                app_url=app_url,
                translation_url=translation_url,
                app_metadata=default_metadata,
                language=language,
                target=u'ALL',
                translated_messages=translated_messages,
                original_messages=original_messages,
                from_developer=True)

        namespaces = set([
            msg['namespace'] for msg in original_messages.values()
            if msg['namespace']
        ])
        processed_languages = []
        if namespaces:
            pairs = []
            for key, msg in original_messages.iteritems():
                if msg['namespace']:
                    pairs.append({
                        'key': key,
                        'namespace': msg['namespace'],
                    })

            for language_pack in get_bundles_by_key_namespaces(pairs):
                cur_language = language_pack['language']
                cur_target = language_pack['target']

                if cur_target == 'ALL' and cur_language in metadata_information[
                        'original_translations']:
                    # Already processed
                    continue

                processed_languages.append((cur_language, cur_target))
                add_full_translation_to_app(
                    user=default_user,
                    app_url=app_url,
                    translation_url=translation_url,
                    app_metadata=default_metadata,
                    language=cur_language,
                    target=cur_target,
                    translated_messages={},
                    original_messages=original_messages,
                    from_developer=False)

        db_translation_url = db.session.query(TranslationUrl).filter_by(
            url=translation_url).first()
        if db_translation_url:
            for translation_bundle in db.session.query(
                    TranslationBundle).filter_by(
                        translation_url=db_translation_url).all():
                if translation_bundle.target == u'ALL' and translation_bundle.language in metadata_information[
                        'original_translations']:
                    # Already processed
                    continue
                found = False
                for processed_language, processed_target in processed_languages:
                    if translation_bundle.target == processed_target and translation_bundle.language == processed_language:
                        found = True
                        break

                if found:
                    # Already processed
                    continue

                add_full_translation_to_app(
                    user=default_user,
                    app_url=app_url,
                    translation_url=translation_url,
                    app_metadata=default_metadata,
                    language=translation_bundle.language,
                    target=translation_bundle.target,
                    translated_messages=None,
                    original_messages=original_messages,
                    from_developer=False)

        translation_percent = retrieve_translations_percent(
            translation_url, original_messages)
        if repo_app is not None and translation_percent != repo_app.translation_percent:
            repo_app.translation_percent = json.dumps(translation_percent)

    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise
コード例 #5
0
def _add_or_update_app(cached_requests, app_url, force_reload, repo_app = None, task = None):
    now = datetime.datetime.utcnow()

    if DEBUG:
        logger.debug("Starting %s" % app_url)

    failing = False
    if task is None:
        try:
            metadata_information = extract_metadata_information(app_url, cached_requests, force_reload)
        except Exception:
            logger.warning("Error extracting information from %s" % app_url, exc_info = True)
            metadata_information = {}
            failing = True
    else:
        metadata_information = task.metadata_information or {}
        failing = task.failing

    if repo_app is not None:
        repo_app.translatable = metadata_information.get('translatable', False)
        repo_app.adaptable = metadata_information.get('adaptable', False)
        repo_app.original_translations = u','.join(metadata_information.get('original_translations', {}).keys())
        repo_app.last_change = now
        repo_app.last_check = now

        if failing:
            repo_app.failing = True
            repo_app.failing_since = now
        else:
            if repo_app.failing:
                repo_app.failing = False

    default_user = get_golab_default_user()

    if metadata_information.get('translatable'):
        translation_url = metadata_information.get('default_translation_url')
        original_messages = metadata_information['default_translations']
        default_metadata = metadata_information['default_metadata']
        for language, translated_messages in metadata_information['original_translations'].iteritems():
            add_full_translation_to_app(user = default_user, app_url = app_url, translation_url = translation_url, 
                                app_metadata = default_metadata,
                                language = language, target = u'ALL', translated_messages = translated_messages, 
                                original_messages = original_messages, from_developer = True)

        namespaces = set([ msg['namespace'] for msg in original_messages.values() if msg['namespace'] ])
        processed_languages = []
        if namespaces:
            pairs = []
            for key, msg in original_messages.iteritems():
                if msg['namespace']:
                    pairs.append({
                        'key' : key,
                        'namespace' : msg['namespace'],
                    })
        
            for language_pack in get_bundles_by_key_namespaces(pairs):
                cur_language = language_pack['language']
                cur_target = language_pack['target']

                if cur_target == 'ALL' and cur_language in metadata_information['original_translations']:
                    # Already processed
                    continue

                processed_languages.append((cur_language, cur_target))
                add_full_translation_to_app(user = default_user, app_url = app_url, translation_url = translation_url,
                                app_metadata = default_metadata,
                                language = cur_language, target = cur_target, translated_messages = {},
                                original_messages = original_messages, from_developer = False)

        db_translation_url = db.session.query(TranslationUrl).filter_by(url = translation_url).first()
        if db_translation_url:
            for translation_bundle in db.session.query(TranslationBundle).filter_by(translation_url = db_translation_url).all():
                if translation_bundle.target == u'ALL' and translation_bundle.language in metadata_information['original_translations']:
                    # Already processed
                    continue
                found = False
                for processed_language, processed_target in processed_languages:
                    if translation_bundle.target == processed_target and translation_bundle.language == processed_language:
                        found = True
                        break

                if found:
                    # Already processed
                    continue

                add_full_translation_to_app(user = default_user, app_url = app_url, translation_url = translation_url, 
                            app_metadata = default_metadata,
                            language = translation_bundle.language, target = translation_bundle.target, translated_messages = None,
                            original_messages = original_messages, from_developer = False)
                   

        translation_percent = retrieve_translations_percent(translation_url, original_messages)
        if repo_app is not None and translation_percent != repo_app.translation_percent:
            repo_app.translation_percent = json.dumps(translation_percent)
    
    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise