sanderl-mediamonks
11/18/2015 - 9:47 AM

Google App Engine interactive python shell

Google App Engine interactive python shell

"""
Opens a python shell with an active app engine environment which allows 
querying the local datastore.

Usage:
    python -i appengine_shell.py [path-to-datastore-file]
"""

import sys
import os

sys.path.append(os.path.expanduser('~/bin/google_appengine'))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'src/')))


def main(datastore_file_path):
    from google.appengine.ext import testbed
    tb = testbed.Testbed()
    tb.activate()
    tb.init_datastore_v3_stub(datastore_file=datastore_file_path, use_sqlite=True)
    tb.init_memcache_stub()


if __name__ == '__main__':
    run = len(sys.argv) == 2

    if len(sys.argv) < 2:
        print 'Not enough arguments. Specify the path to the datastore file.'
    elif len(sys.argv) > 2:
        print 'To many arguments. Only specify the path to the datastore file.'

    if run:
        main(sys.argv[1])
    else:
        exit()