-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
116 lines (86 loc) · 2.79 KB
/
commands.py
File metadata and controls
116 lines (86 loc) · 2.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
"""Command-line interface for managing Flow.Launcher plugin operations.
This script provides CLI commands for:
- Translation and localization: Extract, initialize, update, and compile language files
- Plugin management: Auto-generate plugin.json configuration files
The script uses Click framework to define command groups and individual commands
that can be executed from the command line.
"""
import json
import os
import click
from plugin import (
ICON_PATH,
PLUGIN_ACTION_KEYWORD,
PLUGIN_AUTHOR,
PLUGIN_EXECUTE_FILENAME,
PLUGIN_ID,
PLUGIN_PROGRAM_LANG,
PLUGIN_URL,
__long_description__,
__package_name__,
__short_description__,
__version__,
basedir,
)
@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 fuck_you():
click.echo("Fuck you!!")
print(f"os.getcwd(): {os.getcwd()} ")
exit(-1)
@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_name__.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__":
# import pdb; pdb.set_trace()
cli()