Skip to content

Instantly share code, notes, and snippets.

@thinrhino
Forked from djm/gae_shell.py
Last active August 29, 2015 14:13
Show Gist options
  • Save thinrhino/34cedd90a835c8786432 to your computer and use it in GitHub Desktop.
Save thinrhino/34cedd90a835c8786432 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python -i
"""
A local interactive IPython shell for Google App Engine on Mac OSX.
Usage:
cd /to/project/folder/with/app.yaml
python gae_shell.py
Notes:
This script assumes numerous things:
* The path to your GAE SDK install.
* That you run the dev server with the specified datastore path:
e.g dev_appserver.py src --datastore_path=src/tmp/datastore
"""
import os
import sys
modules = ['antlr3',
'argparse',
'cacerts',
'cherrypy',
'concurrent',
'deprecated_enum',
'distutils',
'django-1.5',
'docker',
'endpoints-1.0',
'fancy_urllib',
'google-api-python-client',
'graphy',
'grizzled',
'httplib2',
'ipaddr',
'jinja2-2.6',
'markupsafe-0.15',
'mox',
'oauth2',
'prettytable',
'protorpc-1.0',
'PyAMF-0.6.1',
'pyasn1',
'pyasn1_modules',
'python-gflags',
'requests',
'rsa',
'setuptools-0.6c11',
'simplejson',
'six',
'sqlcmd',
'webapp2-2.5.2',
'webob-1.2.3',
'websocket',
'yaml-3.10']
dir_path = '/usr/local/google_appengine'
for mod in modules:
sys.path.append(os.path.join(dir_path, 'lib', mod))
app_root = os.path.dirname(os.path.abspath(__file__))
location = lambda x: os.path.join(app_root, x)
sys.path.insert(0, app_root)
sys.path.insert(1, '/usr/local/google_appengine')
from google.appengine.api import apiproxy_stub_map
from google.appengine.datastore.datastore_sqlite_stub import (
DatastoreSqliteStub
)
from google.appengine.api.memcache.memcache_stub import MemcacheServiceStub
from google.appengine.api.taskqueue.taskqueue_stub import TaskQueueServiceStub
from google.appengine.api.urlfetch_stub import URLFetchServiceStub
from google.appengine.api import appinfo
ds_path = location("tmp/datastore")
# Load the app.yaml config.
app_ext_info = appinfo.LoadSingleAppInfo(file(location('app.yaml'), 'r'))
app_id = 'dev~%s' % app_ext_info.application
# Set the application ID to make stubs happy.
os.environ['APPLICATION_ID'] = app_id
# Init the proxy map and stubs.
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
# SQLite Datastore setup.
ds_opts = {
'require_indexes': True,
'verbose': True
}
ds_stub = DatastoreSqliteStub(app_id, ds_path, **ds_opts)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub)
# Memcache setup.
mc_stub = MemcacheServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub)
# Task queues setup.
tq_stub = TaskQueueServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', tq_stub)
# URLfetch service setup.
uf_stub = URLFetchServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', uf_stub)
# Pretty printing
import pprint
pp = pprint.PrettyPrinter(indent=4).pprint
# Perhaps load the models from your project
# so that they are already in the namespace.
# from project.models import *
from IPython import embed
embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment