Skip to content

@chrisfarms /console.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.