1 Star 0 Fork 0

守望半吊子/faceswap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tools.py 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
torzdf 提交于 2021-02-18 23:53 . Add Locale support for cli arguments
#!/usr/bin/env python3
""" The master tools.py script """
import gettext
import os
import sys
from importlib import import_module
# Importing the various tools
from lib.cli.args import FullHelpArgumentParser
# LOCALES
_LANG = gettext.translation("tools", localedir="locales", fallback=True)
_ = _LANG.gettext
# Python version check
if sys.version_info[0] < 3:
raise Exception("This program requires at least python3.7")
if sys.version_info[0] == 3 and sys.version_info[1] < 7:
raise Exception("This program requires at least python3.7")
def bad_args(*args): # pylint:disable=unused-argument
""" Print help on bad arguments """
PARSER.print_help()
sys.exit(0)
def _get_cli_opts():
""" Optain the subparsers and cli options for available tools """
base_path = os.path.realpath(os.path.dirname(sys.argv[0]))
tools_dir = os.path.join(base_path, "tools")
for tool_name in sorted(os.listdir(tools_dir)):
cli_file = os.path.join(tools_dir, tool_name, "cli.py")
if os.path.exists(cli_file):
mod = ".".join(("tools", tool_name, "cli"))
module = import_module(mod)
cliarg_class = getattr(module, "{}Args".format(tool_name.title()))
help_text = getattr(module, "_HELPTEXT")
yield tool_name, help_text, cliarg_class
if __name__ == "__main__":
print(_("Please backup your data and/or test the tool you want to use with a smaller data set "
"to make sure you understand how it works."))
PARSER = FullHelpArgumentParser()
SUBPARSER = PARSER.add_subparsers()
for tool, helptext, cli_args in _get_cli_opts():
cli_args(SUBPARSER, tool, helptext)
PARSER.set_defaults(func=bad_args)
ARGUMENTS = PARSER.parse_args()
ARGUMENTS.func(ARGUMENTS)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huiyanxian/faceswap.git
git@gitee.com:huiyanxian/faceswap.git
huiyanxian
faceswap
faceswap
master

搜索帮助

Cb406eda 1850385 E526c682 1850385