public
Last active

  • 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 67 68 69 70
#!/usr/bin/python
import sys
sys.path.append("/usr/local/google_appengine")
sys.path.append("/usr/local/google_appengine/lib/yaml/lib")
sys.path.append("/usr/local/google_appengine/lib/django_1_3")
sys.path.append("/usr/local/google_appengine/lib/fancy_urllib")
sys.path.append("/usr/local/google_appengine/lib/webob")
sys.path.append("/usr/local/google_appengine/lib/simplejson")
 
import os
import code
import getpass
import datetime
import logging
 
logging.disable(10) # disable debugging logs
 
import setup_django_version
from google.appengine.ext import db
from google.appengine.ext.remote_api import remote_api_stub
 
 
def auth_func():
return raw_input('Username:'), getpass.getpass('Password:')
 
 
def log_to_console(str):
import inspect
date = datetime.datetime.now()
module = inspect.stack()[1][3]
print ("%s %s] %s" % (date, module, str))
 
 
DEFAULT_APP_ID = 'your-app-id'
 
app_id = DEFAULT_APP_ID
host = DEFAULT_APP_ID + '.appspot.com'
 
if len(sys.argv) > 1 and sys.argv[1] != '':
input_app_id = sys.argv[1]
if input_app_id in ('local', 'localhost'):
host = 'localhost:8080'
else:
app_id = input_app_id
host = input_app_id + '.appspot.com'
 
 
if __name__ == "__main__":
 
# set logging to console
logging.info = logging.error = logging.warn = logging.exception = log_to_console
 
# Always use UTC here so entities timestamps get updated with UTC
os.environ['TZ'] = 'UTC'
 
remote_api_stub.ConfigureRemoteDatastore(None, '/_ah/remote_api', auth_func, host)
 
namespace = locals().copy()
banner = '\033[92m\nApp Engine interactive console for %s \033[0m' % app_id
 
try:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns=namespace, banner=banner)
ipshell()
except:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
shell.mainloop()
else:
code.interact(banner, None, namespace)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.