Former-commit-id:a02aeb236c
[formerly9f19e3f712
] [formerlya02aeb236c
[formerly9f19e3f712
] [formerly06a8b51d6d
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]] Former-commit-id:06a8b51d6d
Former-commit-id:8e80217e59
[formerly3360eb6c5f
] Former-commit-id:377dcd10b9
62 lines
1.6 KiB
ReStructuredText
Executable file
62 lines
1.6 KiB
ReStructuredText
Executable file
===========================
|
|
Management Script Utilities
|
|
===========================
|
|
|
|
.. automodule:: werkzeug.script
|
|
|
|
|
|
Writing Actions
|
|
===============
|
|
|
|
Writing new action functions is pretty straightforward. All you have to do is
|
|
to name the function `action_COMMAND` and it will be available as
|
|
`./manage.py COMMAND`. The docstring of the function is used for the help
|
|
screen and all arguments must have defaults which the `run` function can
|
|
inspect. As a matter of fact you cannot use ``*args`` or ``**kwargs``
|
|
constructs.
|
|
|
|
An additional feature is the definition of tuples as defaults. The first item
|
|
in the tuple could be a short name for the command and the second the default
|
|
value::
|
|
|
|
def action_add_user(username=('u', ''), password=('p', '')):
|
|
"""Docstring goes here."""
|
|
...
|
|
|
|
|
|
Action Discovery
|
|
================
|
|
|
|
Per default, the `run` function looks up variables in the current locals.
|
|
That means if no arguments are provided, it implicitly assumes this call::
|
|
|
|
script.run(locals(), 'action_')
|
|
|
|
If you don't want to use an action discovery, you can set the prefix to an
|
|
empty string and pass a dict with functions::
|
|
|
|
script.run(dict(
|
|
runserver=script.make_runserver(make_app, use_reloader=True),
|
|
shell=script.make_shell(lambda: {'app': make_app()}),
|
|
initdb=on_initdb
|
|
), '')
|
|
|
|
|
|
Reference
|
|
=========
|
|
|
|
.. autofunction:: run
|
|
|
|
.. autofunction:: make_shell
|
|
|
|
.. autofunction:: make_runserver
|
|
|
|
|
|
Example Scripts
|
|
===============
|
|
|
|
In the Werkzeug `example folder`_ there are some ``./manage-APP.py`` scripts
|
|
using `werkzeug.script`.
|
|
|
|
|
|
.. _example folder: http://dev.pocoo.org/projects/werkzeug/browser/examples
|