Factor out the setup() method in interactive
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 01 Apr 2009 00:29:50 +0000
changeset 2046 1fb1c628ad60
parent 2045 e7cf95cc4c18
child 2047 7e9656691c8e
Factor out the setup() method in interactive Also allow specifying a custom context dictionary in remote, which will be used by the stats module to add helper methods. Patch by: Sverre Rabbelier
scripts/interactive.py
--- a/scripts/interactive.py	Wed Apr 01 00:29:34 2009 +0000
+++ b/scripts/interactive.py	Wed Apr 01 00:29:50 2009 +0000
@@ -80,13 +80,20 @@
       key = results[-1].key()
 
 
-def remote(args):
+def remote(args, context=None):
   """Starts a shell with the datastore as remote_api_stub.
+
+  Args:
+    args: arguments from the user
+    context: locals that should be added to the shell
   """
 
   from google.appengine.ext import db
   from google.appengine.ext.remote_api import remote_api_stub
 
+  if not context:
+    context = {}
+
   app_id = args[0]
 
   if len(args) > 1:
@@ -96,14 +103,12 @@
 
   remote_api_stub.ConfigureRemoteDatastore(app_id, '/remote_api', auth_func, host)
 
-  context = {
-      'deepFetch': deepFetch,
-  }
+  context['deepFetch'] = deepFetch
 
   code.interact('App Engine interactive console for %s' % (app_id,), None, context)
 
 
-def main(args):
+def setup():
   """Sets up the sys.path and environment for development.
   """
 
@@ -127,6 +132,11 @@
 
   import main as app_main
 
+def main(args):
+  """Convenience wrapper that calls setup and remote.
+  """
+
+  setup()
   remote(args)