-
Notifications
You must be signed in to change notification settings - Fork 2
/
commands.py
82 lines (59 loc) · 1.97 KB
/
commands.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
import json
import os
import click
@click.group()
def translate():
"""Translation and localization commands."""
...
@translate.command()
@click.argument("locale")
def init(locale):
"""Initialize a new language."""
if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."):
raise RuntimeError("extract command failed")
if os.system("pybabel init -i messages.pot -d plugin/translations -l " + locale):
raise RuntimeError("init command failed")
os.remove("messages.pot")
click.echo("Done.")
@translate.command()
def update():
"""Update all languages."""
if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."):
raise RuntimeError("extract command failed")
if os.system("pybabel update -i messages.pot -d plugin/translations"):
raise RuntimeError("update command failed")
os.remove("messages.pot")
click.echo("Done.")
@translate.command()
def compile():
"""Compile all languages."""
if os.system("pybabel compile -d plugin/translations"):
raise RuntimeError("compile command failed")
click.echo("Done.")
@click.group()
def plugin():
"""Translation and localization commands."""
...
@plugin.command()
def gen_plugin_info():
"""Auto generate the `plugin.json` file for Flow"""
plugin_infos = {
"ID": PLUGIN_ID,
"ActionKeyword": PLUGIN_ACTION_KEYWORD,
"Name": __package_title__,
"Description": __short_description__,
"Author": PLUGIN_AUTHOR,
"Version": __version__,
"Language": PLUGIN_PROGRAM_LANG,
"Website": PLUGIN_URL,
"IcoPath": ICON_PATH,
"ExecuteFileName": PLUGIN_EXECUTE_FILENAME,
}
json_path = os.path.join(basedir, "plugin.json")
with open(json_path, "w") as f:
json.dump(plugin_infos, f, indent=" " * 4)
click.echo("Done.")
cli = click.CommandCollection(sources=[plugin, translate])
if __name__ == "__main__":
cli()