python中参数解析器的一个基于web的包装器
warped的Python项目详细描述
warped可用于执行单个python文件和python模块。 它捕获对python的argparse模块的调用,并呈现一个web 基于定义的选项和参数的gui。它还显示 程序在web gui中的输出,允许您停止、暂停 恢复程序,以及下载输出。
安装
从pypi获取稳定版本,或者安装当前版本 来自Git
# Installation from PyPI pip install warped # Installation from git pip install git+https://git.k-fortytwo.de/christofsteel/warped/
用法
warped [-h] [--port PORT] [--host HOST] [--module] file a Webbased frontend for ARgparse in Python positional arguments: file File to run optional arguments: -h, --help show this help message and exit --port PORT, -p PORT The port to listen on (default 5000) --host HOST The host to bind to (default 0.0.0.0) --module, -m If set, loads a module instead of a file
样品
为了测试warped的功能,包含了一个示例模块。 您可以这样运行:
warped -m warped.samples.hooked
由于warped也使用argparse模块,warped 它本身可以被扭曲。
warped -m warped.hook
它是如何工作的?
当执行warped时,它将启动flask web服务器。javascript ,读取服务器的/arguments资源,其中 argparser的配置返回。在一个单独的过程中 给定的程序使用runpy库执行,重定向 sys.stdin和sys.stdout到multiprocessing.Queue,其中 可以被warp进程读取,以便通过web gui显示它。
另外,warped在 sys.modules列表。python首先查看这个列表,每次 导入模块,以避免多次导入模块。这个 自定义argparse模块的行为与原始^{tt2}相似$ 模块事实上除了 ArgumentParser.parse_args()方法,它的工作方式与 原版的。一旦程序调用parse_args()方法,它就会阻塞 并等待用户通过web gui进行交互。一旦用户提交 数据,过程继续。