views:

419

answers:

3

The interactive console accessible at localhost:8080/_ah/admin is very useful for debugging your App Engine app.

I always find myself importing the same modules over and over again, particularly models.

I've looked into monkey patching the interactive console to automatically import these models, and I'm stumped. Ideally, I could do it from my app so I wouldn't need to reapply the patch every time I update the SDK.

I'll investigate and hopefully find an answer, please let me know if you have any ideas about how to accomplish this.

+1  A: 

I'm not sure if this is at all what you're going for, but you can just edit the html template for the interactive console page to have different default text entered. It's located at:

./google_appengine/google/appengine/ext/admin/templates/interactive.html

This would apply to all your apps, and as you mentioned you'd have to goof with it every time the SDK updated.

jtb
+2  A: 

Good question! The relevant code for the interactive console is in InteractiveExecuteHandler at google/appengine/ext/admin/init.py:188. Specifically, it executes the code like this:

  try:
    compiled_code = compile(code, '<string>', 'exec')
    exec(compiled_code, globals())
  except Exception, e:
    traceback.print_exc(file=results_io)

Note that for the globals, it simply uses the globals of the module it's in. So in order to provide your own imports, all you need to do is this:

  1. Create your own module, where you import and subclass InteractivePageHandler and InteractiveExecuteHandler
  2. Import any additional modules and classes you want in your new module - they'll automatically be imported for any code that's executed by them.
  3. Override the generate() function from BaseRequestHandler in those classes so they look for the templates on google/appengine/ext/admin/templates instead of in the 'templates' subdir under your own module.
Nick Johnson
It doesn't look like this would work on a per-app basis. I was ideally looking for a way to do this by keeping the code within the scope of a single application.
jamtoday
What do you mean "on a per app basis"? What I'm outlining above consists only of writing some extra code for your app - it doesn't involve modifying the SDK.
Nick Johnson
Apologies, I misunderstood the gist of this approach. I'll post an update when I get this working...
jamtoday
+2  A: 

I ended up using the App Engine Console project which comes with an autoexec.py that provides the functionality I asked about.

jamtoday
Hi, jamtoday. I just found this question from Google Alerts. I am the author of App Engine Console. I am considering a major upgrade over the holidays so let me know if you have any bugs or features I should know about!
jhs