Clue_script is a project mainly written in Python, it's free.
.. --rst--
clue_script is used for defining subcommands with a special focus on
web-style apps. The functionality is inspired by the Django manage.py
script.
A simple example to add a command that prints "hello world"::
from clue_script import command, Commander
@command def helloworld(): print 'hello world'
if name == 'main': Commander.scan(globals()).run()
To do a more complicated command you can use something similar to
Python 2.7's argparse
(also available on 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)
if name == 'main': Commander.scan(globals()).run()
There are currently two provided command factories.
make_reloadable_server_command
(see above note about requirements for runserver)
make_syncdb_command
A typical web app could use these commands as follows::
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()
Running the script with no args will yield something similar to::
Commands: runserver Run a reloadable development web server. syncdb Update the database.