public
Last active

An appengine python console

  • Download Gist
console.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#!/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())

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.