2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-24 23:48:24 +00:00

Add download translations command

This commit is contained in:
Pratik Vyas 2015-05-26 13:58:00 +05:30
parent 2e25af203a
commit 39fbb25782
2 changed files with 52 additions and 4 deletions

View File

@ -14,7 +14,7 @@ from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_env_c
get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements,
backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root, set_mariadb_host, drop_privileges,
fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key, get_cmd_output, post_upgrade,
pre_upgrade, PatchError)
pre_upgrade, PatchError, download_translations_p)
from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade, switch_to_v4, switch_to_master, switch_to_develop
@ -235,15 +235,15 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
if pull:
pull_all_apps()
if requirements:
update_requirements()
if upgrade:
pre_upgrade(version_upgrade[0], version_upgrade[1])
import utils, app
reload(utils)
reload(app)
if requirements:
update_requirements()
if patch:
if not no_backup:
backup_all_sites()
@ -549,6 +549,12 @@ def _fix_file_perms():
patch.add_command(_fix_file_perms)
patch.add_command(_fix_prod_perms)
@click.command('download-translations')
def _download_translations():
"Download latest translations"
download_translations_p()
#Bench commands
bench.add_command(init)
@ -577,3 +583,4 @@ bench.add_command(_release)
bench.add_command(patch)
bench.add_command(set_url_root)
bench.add_command(retry_upgrade)
bench.add_command(_download_translations)

View File

@ -4,7 +4,10 @@ import sys
import subprocess
import getpass
import logging
import itertools
import requests
import json
import multiprocessing
from distutils.spawn import find_executable
import pwd, grp
@ -466,4 +469,42 @@ def post_upgrade(from_ver, to_ver, bench='.'):
print "sudo service nginx restart"
print "sudo supervisorctl reload"
def update_translations_p(args):
update_translations(*args)
def download_translations_p():
pool = multiprocessing.Pool(8)
langs = get_langs()
apps = ('frappe', 'erpnext')
args = list(itertools.product(apps, langs))
pool.map(update_translations_p, args)
def download_translations():
langs = get_langs()
apps = ('frappe', 'erpnext')
for app, lang in itertools.product(apps, langs):
update_translations(app, lang)
def get_langs():
lang_file = 'apps/frappe/frappe/data/languages.txt'
with open(lang_file) as f:
lang_data = f.read()
langs = [line.split('\t')[0] for line in lang_data.splitlines()]
langs.remove('en')
return langs
def update_translations(app, lang):
translations_dir = os.path.join('apps', app, app, 'translations')
csv_file = os.path.join(translations_dir, lang + '.csv')
r = requests.get("https://translate.erpnext.com/files/{}-{}.csv".format(app, lang))
r.raise_for_status()
with open(csv_file, 'wb') as f:
f.write(r.text.encode('utf-8'))
print 'downloaded for', app, lang
FRAPPE_VERSION = get_current_frappe_version()