示例#1
0
def task_download_repository_apps(self, source = None):
    if source is None:
        source = 'sched-down'

    with my_app.app_context():
        sync_id = start_synchronization(source=source, cached=False)

    try:
        with my_app.app_context():
            changes = download_repository_apps()
            if changes:
                synchronize_apps_cache_wrapper.delay()
    finally:
        with my_app.app_context():
            end_synchronization(sync_id, number = 0)
示例#2
0
def synchronize_apps_cache_wrapper(self, source = None):
    if source is None:
        source = 'scheduled'

    with my_app.app_context():
        result = synchronize_apps_cache(source = source)
    task_sync_mongodb_recent.delay()
    return result
示例#3
0
def synchronize_apps_no_cache_wrapper(self, source = None, single_app_url = None, must_sync = True):
    if source is None:
        source = 'scheduled'
    with my_app.app_context():
        result = synchronize_apps_no_cache(source = source, single_app_url = single_app_url)
    if must_sync:
        sync(self, False)
    return result
示例#4
0
def task_synchronize_single_app(self, source = None, single_app_url = None):
    if source is None:
        source = 'scheduled'

    with my_app.app_context():
        update_content_hash(single_app_url)
        result = synchronize_single_app_no_cached(source = source, single_app_url = single_app_url)

    task_sync_mongodb_recent.delay()
    return result
示例#5
0
def synchronize_apps_no_cache_wrapper(self, source = None):
    if source is None:
        source = 'scheduled'

    # synchronize all the apps
    with my_app.app_context():
        result = synchronize_apps_no_cache(source = source)

    # Call mongodb
    task_sync_mongodb_all.delay()
    return result
示例#6
0
def delete_old_realtime_active_users(self):
    with my_app.app_context():
        two_hours_ago = datetime.datetime.utcnow() - datetime.timedelta(hours = 2)
        old_active_users = db.session.query(TranslationCurrentActiveUser).filter(TranslationCurrentActiveUser.last_check < two_hours_ago).all()
        for old_active_user in old_active_users:
            db.session.delete(old_active_user)
        if len(old_active_users):
            try:
                db.session.commit()
            except:
                db.session.rollback()
                raise
示例#7
0
def load_google_suggestions(self):
    with my_app.app_context():
        load_all_google_suggestions()
示例#8
0
def task_load_microsoft_suggestions(self):
    with my_app.app_context():
        load_all_microsoft_suggestions()
import glob
import json
import datetime

from bson.json_util import loads

from appcomposer import app
from appcomposer.translator.ops import get_golab_default_user, add_full_translation_to_app
from appcomposer.translator.utils import extract_local_translations_url

files = glob.glob("dump/*")

with app.app_context():
    user = get_golab_default_user()

    for f in files:
        print "Processing...",f,
        translation = loads(open(f).read())
        app_url = translation['spec']
        language, target = translation['bundle'].rsplit('_', 1)
        if language == 'all_ALL':
            print "Skipping all_ALL"
            continue
        elif language.startswith('af'):
            print "Skipping afghan and afrikaans"
            continue

        try:
            translated_messages = json.loads(json.loads(translation['data']))
        except (ValueError, TypeError):
            translated_messages = json.loads(translation['data'])
示例#10
0
def synchronize_apps_no_cache_wrapper(self):
    with my_app.app_context():
        result = synchronize_apps_no_cache()
    sync(self)
    return result
示例#11
0
def task_update_check_urls_status(self):
    with my_app.app_context():
        update_check_urls_status()
示例#12
0
            logger.warning("Google Translate returned %r for message %r. Stopping." % (translated, message))
            return False, counter

    return True, counter


# ORDERED_LANGUAGES: first the semi official ones (less likely to have translations in Microsoft Translator API), then the official ones and then the rest
ORDERED_LANGUAGES = SEMIOFFICIAL_EUROPEAN_UNION_LANGUAGES + OFFICIAL_EUROPEAN_UNION_LANGUAGES + OTHER_LANGUAGES

def load_all_google_suggestions():
    active_messages = set([ value for value, in db.session.query(ActiveTranslationMessage.value).filter(TranslationBundle.language == 'en_ALL', ActiveTranslationMessage.bundle_id == TranslationBundle.id).all() ])
    
    total_counter = 0

    for language in ORDERED_LANGUAGES:
        should_continue, counter = load_google_suggestions_by_lang(active_messages, language)
        total_counter += counter
        if total_counter > 1000:
            logger.info("Stopping the google suggestions API after performing %s queries until the next cycle" % total_counter)
            break

        if not should_continue:
            logger.info("Stopping the google suggestions API until the next cycle")
            # There was an error: keep in the next iteration ;-)
            break

if __name__ == '__main__':
    from appcomposer import app as my_app
    with my_app.app_context():
        synchronize_apps_cache()
示例#13
0
def task_download_repository_single_app(self, app_url):
    with my_app.app_context():
        changes = download_repository_single_app(app_url)
        if changes:
            task_sync_mongodb_recent.delay()
示例#14
0
def task_notify_updates(self):
    with my_app.app_context():
        return run_update_notifications()
示例#15
0
def notify_changes(self):
    with my_app.app_context():
        return run_notifications()
示例#16
0
def task_load_deepl_suggestions(self):
    with my_app.app_context():
        load_all_deepl_suggestions()
示例#17
0
def task_load_google_suggestions(self):
    with my_app.app_context():
        load_all_google_suggestions()
示例#18
0
def task_sync_repo_apps_all(self):
    with my_app.app_context():
        changes = sync_repo_apps(force=True)
        if changes:
            task_download_repository_apps.delay("changes-in-repo")
示例#19
0
def task_notify_changes(self):
    with my_app.app_context():
        return run_notifications()