summaryrefslogtreecommitdiffstats
path: root/appengine_django/management/commands
diff options
context:
space:
mode:
Diffstat (limited to 'appengine_django/management/commands')
-rwxr-xr-xappengine_django/management/commands/__init__.py0
-rw-r--r--appengine_django/management/commands/__init__.pycbin0 -> 167 bytes
-rwxr-xr-xappengine_django/management/commands/console.py49
-rwxr-xr-xappengine_django/management/commands/flush.py36
-rwxr-xr-xappengine_django/management/commands/reset.py32
-rwxr-xr-xappengine_django/management/commands/rollback.py52
-rwxr-xr-xappengine_django/management/commands/runserver.py77
-rw-r--r--appengine_django/management/commands/runserver.pycbin0 -> 2710 bytes
-rw-r--r--appengine_django/management/commands/startapp.py43
-rw-r--r--appengine_django/management/commands/startapp.pycbin0 -> 1690 bytes
-rwxr-xr-xappengine_django/management/commands/testserver.py71
-rwxr-xr-xappengine_django/management/commands/update.py51
-rwxr-xr-xappengine_django/management/commands/vacuum_indexes.py52
13 files changed, 463 insertions, 0 deletions
diff --git a/appengine_django/management/commands/__init__.py b/appengine_django/management/commands/__init__.py
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/appengine_django/management/commands/__init__.py
diff --git a/appengine_django/management/commands/__init__.pyc b/appengine_django/management/commands/__init__.pyc
new file mode 100644
index 0000000..48a948a
--- /dev/null
+++ b/appengine_django/management/commands/__init__.pyc
Binary files differ
diff --git a/appengine_django/management/commands/console.py b/appengine_django/management/commands/console.py
new file mode 100755
index 0000000..2c40697
--- /dev/null
+++ b/appengine_django/management/commands/console.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import code
+import getpass
+import os
+import sys
+
+from django.conf import settings
+from django.core.management.base import BaseCommand
+
+from google.appengine.ext.remote_api import remote_api_stub
+
+
+def auth_func():
+ return raw_input('Username:'), getpass.getpass('Password:')
+
+class Command(BaseCommand):
+ """ Start up an interactive console backed by your app using remote_api """
+
+ help = 'Start up an interactive console backed by your app using remote_api.'
+
+ def run_from_argv(self, argv):
+ app_id = argv[2]
+ if len(argv) > 3:
+ host = argv[3]
+ else:
+ host = '%s.appspot.com' % app_id
+
+ remote_api_stub.ConfigureRemoteDatastore(app_id,
+ '/remote_api',
+ auth_func,
+ host)
+
+ code.interact('App Engine interactive console for %s' % (app_id,),
+ None,
+ locals())
diff --git a/appengine_django/management/commands/flush.py b/appengine_django/management/commands/flush.py
new file mode 100755
index 0000000..c5f3f8c
--- /dev/null
+++ b/appengine_django/management/commands/flush.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import os
+import sys
+
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ """Overrides the default Django flush command.
+ """
+ help = 'Clears the current datastore and loads the initial fixture data.'
+
+ def run_from_argv(self, argv):
+ from django.db import connection
+ connection.flush()
+ from django.core.management import call_command
+ call_command('loaddata', 'initial_data')
+
+ def handle(self, *args, **kwargs):
+ self.run_from_argv(None)
diff --git a/appengine_django/management/commands/reset.py b/appengine_django/management/commands/reset.py
new file mode 100755
index 0000000..126f386
--- /dev/null
+++ b/appengine_django/management/commands/reset.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import logging
+import os
+import sys
+
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ """Overrides the default Django reset command.
+ """
+ help = 'Clears the current datastore.'
+
+ def run_from_argv(self, argv):
+ from django.db import connection
+ connection.flush()
diff --git a/appengine_django/management/commands/rollback.py b/appengine_django/management/commands/rollback.py
new file mode 100755
index 0000000..6ce9e4e
--- /dev/null
+++ b/appengine_django/management/commands/rollback.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+import logging
+
+from django.core.management.base import BaseCommand
+
+
+def run_appcfg():
+ # import this so that we run through the checks at the beginning
+ # and report the appropriate errors
+ import appcfg
+
+ # We don't really want to use that one though, it just executes this one
+ from google.appengine.tools import appcfg
+
+ # Reset the logging level to WARN as appcfg will spew tons of logs on INFO
+ logging.getLogger().setLevel(logging.WARN)
+
+ # Note: if we decide to change the name of this command to something other
+ # than 'rollback' we will have to munge the args to replace whatever
+ # we called it with 'rollback'
+ new_args = sys.argv[:]
+ new_args.append('.')
+ appcfg.main(new_args)
+
+
+class Command(BaseCommand):
+ """Calls the appcfg.py's rollback command for the current project.
+
+ Any additional arguments are passed directly to appcfg.py.
+ """
+ help = 'Calls appcfg.py rollback for the current project.'
+ args = '[any appcfg.py options]'
+
+ def run_from_argv(self, argv):
+ run_appcfg()
diff --git a/appengine_django/management/commands/runserver.py b/appengine_django/management/commands/runserver.py
new file mode 100755
index 0000000..7b91f65
--- /dev/null
+++ b/appengine_django/management/commands/runserver.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+import sys
+
+from appengine_django.db.base import get_datastore_paths
+
+from django.core.management.base import BaseCommand
+
+
+def start_dev_appserver():
+ """Starts the appengine dev_appserver program for the Django project.
+
+ The appserver is run with default parameters. If you need to pass any special
+ parameters to the dev_appserver you will have to invoke it manually.
+ """
+ from google.appengine.tools import dev_appserver_main
+ progname = sys.argv[0]
+ args = []
+ # hack __main__ so --help in dev_appserver_main works OK.
+ sys.modules['__main__'] = dev_appserver_main
+ # Set bind ip/port if specified.
+ if len(sys.argv) > 2:
+ addrport = sys.argv[2]
+ try:
+ addr, port = addrport.split(":")
+ except ValueError:
+ addr, port = None, addrport
+ if not port.isdigit():
+ print "Error: '%s' is not a valid port number." % port
+ sys.exit(1)
+ else:
+ addr, port = None, "8000"
+ if addr:
+ args.extend(["--address", addr])
+ if port:
+ args.extend(["--port", port])
+ # Add email settings
+ from django.conf import settings
+ args.extend(['--smtp_host', settings.EMAIL_HOST,
+ '--smtp_port', str(settings.EMAIL_PORT),
+ '--smtp_user', settings.EMAIL_HOST_USER,
+ '--smtp_password', settings.EMAIL_HOST_PASSWORD])
+ # Pass the application specific datastore location to the server.
+ p = get_datastore_paths()
+ args.extend(["--datastore_path", p[0], "--history_path", p[1]])
+ # Append the current working directory to the arguments.
+ dev_appserver_main.main([progname] + args + [os.getcwdu()])
+
+
+class Command(BaseCommand):
+ """Overrides the default Django runserver command.
+
+ Instead of starting the default Django development server this command
+ fires up a copy of the full fledged appengine dev_appserver that emulates
+ the live environment your application will be deployed to.
+ """
+ help = 'Runs a copy of the appengine development server.'
+ args = '[optional port number, or ipaddr:port]'
+
+ def run_from_argv(self, argv):
+ start_dev_appserver()
diff --git a/appengine_django/management/commands/runserver.pyc b/appengine_django/management/commands/runserver.pyc
new file mode 100644
index 0000000..38abf92
--- /dev/null
+++ b/appengine_django/management/commands/runserver.pyc
Binary files differ
diff --git a/appengine_django/management/commands/startapp.py b/appengine_django/management/commands/startapp.py
new file mode 100644
index 0000000..2648cbd
--- /dev/null
+++ b/appengine_django/management/commands/startapp.py
@@ -0,0 +1,43 @@
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+
+import django
+from django.core.management.commands import startapp
+
+import appengine_django
+
+
+class Command(startapp.Command):
+ def handle_label(self, *args, **kwds):
+ """Temporary adjust django.__path__ to load app templates from the
+ helpers directory.
+ """
+ old_path = django.__path__
+ django.__path__ = appengine_django.__path__
+ startapp.Command.handle_label(self, *args, **kwds)
+ django.__path__ = old_path
+
+
+class ProjectCommand(Command):
+ def __init__(self, project_directory):
+ super(ProjectCommand, self).__init__()
+ self.project_directory = project_directory
+
+ def handle_label(self, app_name, **options):
+ super(ProjectCommand, self).handle_label(app_name, self.project_directory,
+ **options)
+
diff --git a/appengine_django/management/commands/startapp.pyc b/appengine_django/management/commands/startapp.pyc
new file mode 100644
index 0000000..844eb68
--- /dev/null
+++ b/appengine_django/management/commands/startapp.pyc
Binary files differ
diff --git a/appengine_django/management/commands/testserver.py b/appengine_django/management/commands/testserver.py
new file mode 100755
index 0000000..bd2c6d1
--- /dev/null
+++ b/appengine_django/management/commands/testserver.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+import sys
+
+from appengine_django.db.base import destroy_datastore
+from appengine_django.db.base import get_test_datastore_paths
+
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ """Overrides the default Django testserver command.
+
+ Instead of starting the default Django development server this command fires
+ up a copy of the full fledged appengine dev_appserver.
+
+ The appserver is always initialised with a blank datastore with the specified
+ fixtures loaded into it.
+ """
+ help = 'Runs the development server with data from the given fixtures.'
+
+ def run_from_argv(self, argv):
+ fixtures = argv[2:]
+
+ # Ensure an on-disk test datastore is used.
+ from django.db import connection
+ connection.use_test_datastore = True
+ connection.test_datastore_inmemory = False
+
+ # Flush any existing test datastore.
+ connection.flush()
+
+ # Load the fixtures.
+ from django.core.management import call_command
+ call_command('loaddata', 'initial_data')
+ if fixtures:
+ call_command('loaddata', *fixtures)
+
+ # Build new arguments for dev_appserver.
+ datastore_path, history_path = get_test_datastore_paths(False)
+ new_args = argv[0:1]
+ new_args.extend(['--datastore_path', datastore_path])
+ new_args.extend(['--history_path', history_path])
+ new_args.extend([os.getcwdu()])
+
+ # Add email settings
+ from django.conf import settings
+ new_args.extend(['--smtp_host', settings.EMAIL_HOST,
+ '--smtp_port', str(settings.EMAIL_PORT),
+ '--smtp_user', settings.EMAIL_HOST_USER,
+ '--smtp_password', settings.EMAIL_HOST_PASSWORD])
+
+ # Start the test dev_appserver.
+ from google.appengine.tools import dev_appserver_main
+ dev_appserver_main.main(new_args)
diff --git a/appengine_django/management/commands/update.py b/appengine_django/management/commands/update.py
new file mode 100755
index 0000000..e489d5d
--- /dev/null
+++ b/appengine_django/management/commands/update.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+import logging
+
+from django.core.management.base import BaseCommand
+
+
+def run_appcfg():
+ # import this so that we run through the checks at the beginning
+ # and report the appropriate errors
+ import appcfg
+
+ # We don't really want to use that one though, it just executes this one
+ from google.appengine.tools import appcfg
+
+ # Reset the logging level to WARN as appcfg will spew tons of logs on INFO
+ logging.getLogger().setLevel(logging.WARN)
+
+ # Note: if we decide to change the name of this command to something other
+ # than 'update' we will have to munge the args to replace whatever
+ # we called it with 'update'
+ new_args = sys.argv[:]
+ new_args.append('.')
+ appcfg.main(new_args)
+
+class Command(BaseCommand):
+ """Calls the appcfg.py's update command for the current project.
+
+ Any additional arguments are passed directly to appcfg.py.
+ """
+ help = 'Calls appcfg.py update for the current project.'
+ args = '[any appcfg.py options]'
+
+ def run_from_argv(self, argv):
+ run_appcfg()
diff --git a/appengine_django/management/commands/vacuum_indexes.py b/appengine_django/management/commands/vacuum_indexes.py
new file mode 100755
index 0000000..ab276b4
--- /dev/null
+++ b/appengine_django/management/commands/vacuum_indexes.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+import logging
+
+from django.core.management.base import BaseCommand
+
+
+def run_appcfg():
+ # import this so that we run through the checks at the beginning
+ # and report the appropriate errors
+ import appcfg
+
+ # We don't really want to use that one though, it just executes this one
+ from google.appengine.tools import appcfg
+
+ # Reset the logging level to WARN as appcfg will spew tons of logs on INFO
+ logging.getLogger().setLevel(logging.WARN)
+
+ # Note: if we decide to change the name of this command to something other
+ # than 'vacuum_indexes' we will have to munge the args to replace whatever
+ # we called it with 'vacuum_indexes'
+ new_args = sys.argv[:]
+ new_args.append('.')
+ appcfg.main(new_args)
+
+
+class Command(BaseCommand):
+ """Calls the appcfg.py's vacuum_indexes command for the current project.
+
+ Any additional arguments are passed directly to appcfg.py.
+ """
+ help = 'Calls appcfg.py vacuum_indexes for the current project.'
+ args = '[any appcfg.py options]'
+
+ def run_from_argv(self, argv):
+ run_appcfg()