创建脚本运行程序的简单实用程序

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()

提供的命令

目前有两个提供的指挥工厂。

  1. ^{tt3}$ (see above note about requirements for runserver)
  2. ^{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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
面向批处理的java非阻塞队列   java如何基于HttpComponent获取html内容   java为什么我的程序会显示此错误?   java spring控制器如何处理应用程序/octetstream请求?   尝试将数据插入数据库时出现java常规错误   无法在java多线程处理中维护生产者任务的顺序   java为什么JSON数据无法访问ViewPager?   java获取Maven中特定分支的SVN buildnumber   java客户端无法从服务器接收信息   java等轴测地图绘制,生成   java无法调试ProcessBuilder   java热点JVM阵列分配   在数组中存储“inputdialog”数据的java   saml Java Inflater引发DataFormatException“无效代码长度集”   从集合(爬虫、Jsoup、Java)写入文件