创建脚本运行程序的简单实用程序
clue_script的Python项目详细描述
概述
clue_脚本用于定义子命令,特别关注 网络风格的应用程序。该功能的灵感来自于djangomanage.py 脚本。
要求
- Python 2.6 or 2.7 (not tested with Python 3.x)
运行服务器支持(可选)
- Paste
- argparse (if deploying on Python < 2.7)
用法
添加打印“hello world”命令的简单示例:
from clue_script import command, Commander @command def helloworld(): print 'hello world' if __name__ == '__main__': Commander.scan(globals()).run()
要执行更复杂的命令,可以使用类似于 python 2.7的argparse(也可在2.6上获得)。
import argparse from clue_script import command, Commander @command def foo(*argv): parser = argparse.ArgumentParser() parser.add_argument('-x', help='simple test', default='yes', metavar='x') ns = parser.parse_args(argv) # do something if __name__ == '__main__': Commander.scan(globals()).run()
提供的命令
目前有两个提供的指挥工厂。
- ^{tt3}$ (see above note about requirements for runserver)
- ^{tt4}$
典型的web应用程序可以使用以下命令:
if __name__ == '__main__': def createtables(session): models.Base.metadata.create_all(session.bind) settings = init_settings() commander = script.Commander([script.make_reloadable_server_command(make_app), script.make_syncdb_command(settings['spitter.db_session_factory'], createtables)]) commander.scan(globals()) commander.run()
运行没有参数的脚本将产生类似于:
Commands: runserver Run a reloadable development web server. syncdb Update the database.
学分
- Developed and maintained by Rocky Burt <rocky AT serverzen DOT com>
更改
0.3.1(2011年7月27日)
- Fixed silly bug where print_usage() was being called wrong
0.3(2011年7月10日)
- Added rfoo support for launching a shell to connect with live-running server http://code.google.com/p/rfoo/
- Improved formatting of command usage
- Removed mostly useless make_syncdb command
- Made Commander.commands a little more exposed
0.2.4(2011年3月3日)
- Fixed problem where the non-reloader portion would shut down the app if code was changed
0.2.3(2011年2月20日)
- Renamed from ^{tt5}$ to ^{tt6}$
0.2.2(2011年2月16日)
- Updated project urls
0.2.1(2011年1月26日)
- Fixed scan() method to return commander instance
0.2(2011年1月3日)
- first release