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)
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
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
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
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
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
def load_google_suggestions(self): with my_app.app_context(): load_all_google_suggestions()
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'])
def synchronize_apps_no_cache_wrapper(self): with my_app.app_context(): result = synchronize_apps_no_cache() sync(self) return result
def task_update_check_urls_status(self): with my_app.app_context(): update_check_urls_status()
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()
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()
def task_notify_updates(self): with my_app.app_context(): return run_update_notifications()
def notify_changes(self): with my_app.app_context(): return run_notifications()
def task_load_deepl_suggestions(self): with my_app.app_context(): load_all_deepl_suggestions()
def task_load_google_suggestions(self): with my_app.app_context(): load_all_google_suggestions()
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")
def task_notify_changes(self): with my_app.app_context(): return run_notifications()