Kay has a management script named manage.py. This script covers most of the management tasks for your applications. Invoking it without any parameters gives you help text.
Some of the tasks will invoking the commands provided by Google App Engine SDK with little parameter adjustments, and some preparations for the task.
So do not think about invoking such scripts(appcfg.py, dev_appserver.py, bulkloader.py) directly from Google App Engine SDK.
This action adds a new language catalogue for specified application.
$ python manage.py add_translation [options]
This action is in charge of doing some tasks which appcfg.py does in a pure GAE environment. Here’s a usage of appcfg action:
$ python manage.py appcfg [options] <action>
Action must be one of:
- cron_info: Display information about cron jobs.
- download_data: Download entities from datastore.
- help: Print help for a specific action.
- request_logs: Write request logs in Apache common log format.
- rollback: Rollback an in-progress update.
- update: Create or update an app version.
- update_cron: Update application cron definitions.
- update_indexes: Update application indexes.
- update_queues: Update application task queue definitions.
- upload_data: Upload data records to datastore.
- vacuum_indexes: Delete unused indexes from application.
Help action followed by a particular action name will give you help text for that action. So, for example, you’ll get help texts for update action by typing as follows:
$ python manage.py appcfg help update
Kay supplements argument with current directory automatically. So you don’t need to specify app’s directory stated in action’s help text (Actually, it is a confusing behaviour, so it might be fixed in a future version). For example, you can upload your application by just typing as follows:
$ python manage.py appcfg update
Current version of Kay loads only preparsed jinja2 templates in GAE environment, so you have to preparse all of your jinja2 template files before deploying your application. The manage.py script automatically do this job, so you don’t have to worry about it usually. If you use launcher on MacOSX, please keep in mind that just push deploy button on it won’t care about preparsing jinja2 templates. In such a case, for preparsing jinja2 templates, you can execute manage.py preparse_apps.
Execute bulkloader script with appropriate parameters. For more details, please invoke ‘python manage.py bulkloader –help’.
$ python manage.py bulkloader [option]
Clear all data on appengine using remote APIs.
$ python manage.py clear_datastore
See also
Compile all i18n cagalog files of the application.
$ python manage.py compile_translations
Create a new user with remote APIs.
$ python manage.py create_user
Dump all data from the server.
See also
Extract the messages for i18n and create pot file.
$ python manage.py extract_messages [options]
This commands execute preparsing all of your jinja2 templates according to the values of your settings.INSTALLED_APPS.
$ python manage.py preparse_apps
Preparse the Jinja2 templates in Kay itself. This command is for Kay developers.
$ python manage.py preparse_bundle
Restore all data to the server.
$ python manage.py restore_all [options]
See also
Start a new interactive python session with RemoteDatastore stub.
$ python manage.py rshell [options]
Execute dev_appserver with appropriate parameters. For more details, please invoke ‘python manage.py runserver –help’.
$ python manage.py runserver [options]
Start a new interactive python session.
$ python manage.py shell [options]
Create a new project.
$ python manage.py startproject myproject
Run test for installed applications.
$ python manage.py test [options]
Specify the log level of progression with integer. The default is 0.
Update translation files using pot file.
$ python manage.py update_translations [options]
You can add your own management script by creating a module named management in your application directory and defining a function with a name prefixed with action_ (e.g. action_foo, action_bar). The latter part of the function becomes a name of subcommand when invoking manage.py. For example, if you add action_foo, you can call this function by invoking python manage.py foo.
Here is a simple example with a rather simple management script that will add foo subcommand to your project.
myapp/management.py
def action_foo(foo_arg=("f", ""), use_bar=True):
print"foo_arg: %s" % foo_arg
print"use_bar: %s" % use_bar
foo_arg in this example can be specified by using --foo-arg ARG or -f ARG from the shell. use_bar is set to True by default, but you can override it to False by specifying --no-use-bar from the shell.
This management script mechanism is based on the werkzeug’s one. So it might be helpful to refer werkzeug documentation for learning how it works.
This is a helper function for creating management scripts for accessing datastore on both of development environment and appspot environment.
| Parameters: |
|
|---|
Here is a simple example.
myapp/management.py:
# -*- coding: utf-8 -*-
from google.appengine.ext import db
from kay.management.utils import (
print_status, create_db_manage_script
)
from myapp.models import Prefecture
prefectures = {
1: u'Hokkaido',
2: u'Aomori',
3: u'Iwate',
# ..
# ..
}
def create_prefectures():
entities = []
for idnum, name in prefectures.iteritems():
entities.append(
Prefecture(name=name,
key=db.Key.from_path(Prefecture.kind(), idnum)))
db.put(entities)
print_status("Created prefectures.")
def delete_prefectures():
db.delete(Prefecture.all().fetch(100))
print_status("Deleted prefectures.")
action_create_prefectures = create_db_manage_script(
main_func=create_prefectures, clean_func=delete_prefectures,
description="Create Prefectures")
You can invoke this action by typing python manage.py create_prefectures. Available parameters are as follows:
$ python manage.py create_prefectures
You can use this action against a development server like:
$ python manage.py create_prefectures -h localhost:8080 --no-secure