-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (46 loc) · 1.87 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import click
import db
from frontend import create_app
from config import config
app = create_app()
@app.cli.command(help="Clean database and remove uploaded files.")
def clean():
db.clean_db()
print("Database cleaned and uploaded files removed")
@app.cli.group(help="Translation commands.")
def translate():
pass
@translate.command(help="Initialize a new language.")
@click.argument('lang')
def init(lang):
pot_location = os.path.join(config.BABEL_TRANSLATIONS_LOCATION, 'messages.pot')
if os.system(f'pybabel extract -F {config.BABEL_CONFIG_LOCATION} -k _l -o {pot_location} .'):
raise RuntimeError('extract command failed')
if os.system(f'pybabel init -i {pot_location} -d {config.BABEL_TRANSLATIONS_LOCATION} -l ' + lang):
raise RuntimeError('init command failed')
os.remove(pot_location)
print("Language init success")
@translate.command(help="Update all languages.")
def update():
pot_location = os.path.join(config.BABEL_TRANSLATIONS_LOCATION, 'messages.pot')
if os.system(f'pybabel extract -F {config.BABEL_CONFIG_LOCATION} -k "_l _t" -o {pot_location} .'):
raise RuntimeError('extract command failed')
if os.system(f'pybabel update -i {pot_location} -d {config.BABEL_TRANSLATIONS_LOCATION}'):
raise RuntimeError('update command failed')
os.remove(pot_location)
print("Translations update success")
@translate.command(help="Compile all languages.")
def compile():
if os.system(f'pybabel compile -d {config.BABEL_TRANSLATIONS_LOCATION}'):
raise RuntimeError('compile command failed')
print("Compilation success")
@app.cli.command(help="Update example data file.")
@click.argument('name')
def example(name):
try:
db.example_pack_update(name)
except FileNotFoundError:
print("Unable to find file " + name)
else:
print("Updating example pack")