Skip to content

Instantly share code, notes, and snippets.

@chrisfarms
Created August 10, 2011 14:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisfarms/1136958 to your computer and use it in GitHub Desktop.
Save chrisfarms/1136958 to your computer and use it in GitHub Desktop.
An appengine python console
#!/usr/bin/env python
import getopt
import os
import ae
import sys
import code
def usage():
print """
--ns set namespace
--production use production
"""
# fix realine
import readline
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
# parse opts
try:
opts, args = getopt.getopt(sys.argv[1:], "he:p:", ["help", "password=","production","ns="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
command = None
use_live = False
for o, v in opts:
if o == "-e":
command = v
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-p", "--password"):
os.environ['GAE_PASS'] = v
elif o in ("--production"):
use_live = True
elif o in ("--ns"):
os.environ['GAE_NAMESPACE'] = v
else:
assert False, "unhandled option"
# setup stbs
if use_live:
ae.connect_remote_datastore()
else:
ae.connect_local_datastore()
# if we have a command execute it then quite
if command:
exec(command)
sys.exit()
# import useful things
from google.appengine.ext import db
from google.appengine.ext.blobstore import BlobInfo
# go interactive!
code.interact('Google AppEngine Console', None, locals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment