deploying a pylons app to google app engine
Post on 18-Dec-2014
6.744 Views
Preview:
DESCRIPTION
TRANSCRIPT
Deploying a Pylons app to Google App Engine
Boston Python meetup - 6/18/08
Nate Aunewww.jazkarta.comwww.nateaune.com
1
Disclaimer #1"I just started using Pylons last week."
2
Disclaimer #2"I just started using Google App Engine last week."
3
App: Gigblastr
• Goal: make it easier to promote an event
• Fill out a form with event details
• Blast event to dozens of event listing sites
• Similar to TubeMogul but for events instead of videos.
4
Tubemogul.com
5
Add event
Title Poludaktulos Orchestra
Musician
The Poludaktulos Orchestra (the "Many-Fingered Orchestra") employs unique instrumentation in its lively performances of northern Greek brass band music.
URL http://myspace.com/poludaktulosorchestra
Description
Blast it!
Venue Johnny D's
Date 11/8/08
Start Time 9:00pm End 11:00pm
6
Brief history
Implemented using content rules for Plone
• version 0.1 @ DevHouseBoston3 2007
• posting to Twitter and Eventful
• version 0.2 @ Home
• posting to Upcoming.org
• version 0.3 @ DevHouseBoston4 2008
• rewrite as Pylons app deployed to GAE
7
Bootstrap with the appenginemonkey
$ svn co http://appengine-monkey.googlecode.com/svn/trunk ape-monkey$ cd ape-monkey$ python2.5 appengine-boot.py --paste-deploy ~/gae/gigblastr$ cd ~/gae/gigblastr$ source bin/activate(gigblastr)$ easy_install Mako==dev Pylons==dev Paste...(gigblastr)$ cd src(gigblastr)$ paster create --template=pylons GigBlastr(gigblastr)$ cd GigBlastr(gigblastr)$ python setup.py develop(gigblastr)$ python -m pth_relpath_fixup
8
Configure your environment
• Edit development.ini[app:the-app]use = config:src/GigBlastr/development.ini
$ /usr/bin/python2.5 /usr/local/google_appengine/dev_appserver.py \ ~/gae/gigblastr/
• Launch the application
• Visit http://localhost:8080/
9
Edit the routes
• In GigBlastr/config/routing.py
map.connect('', controller='hello', action='index')
• Create a 'hello' controller
$ paster controller hello
• Restart and visit http://localhost:8080/hello/index
10
Hello Worldimport logging
from pylons import request, response, sessionfrom pylons import tmpl_context as cfrom pylons.controllers.util import abort, redirect_to
from gigblaster.lib.base import BaseController, render#import gigblaster.model as model
log = logging.getLogger(__name__)
class HelloController(BaseController):
def index(self): # Return a rendered template # return render('/template.mako') # or, Return a response return 'Hello World'
11
• In GigBlastr/controller/hello.py
import twitter
def tweet(self): api = twitter.Api(username='natea', password='xxxxxxx')
status = api.PostUpdate('testing tweets from GAE') return status.text
(gigblastr)$ easy_install python_twitter
• Restart and visit http://localhost:8080/hello/tweet/index
12
Eventful
• In GigBlastr/controller/hello.py
import eventful
def evtful(self): api = eventful.API('xxxxxxxxxxxxx')
events = api.call('/events/search', q='music', l='Cambridge, MA') for event in events['events']['event']: print "%s at %s" % (event['title'], event['venue_name'])
(gigblastr)$ easy_install eventful
• Restart and visit http://localhost:8080/hello/evtful/index
13
Upload app to GAE
$ cd gigblastr$ /usr/bin/python2.5 /usr/local/google_appengine/appcfg.py update .
• 973 files - whew!
• If your app has more than 1000 files, you'll have to remove some unused eggs.
14
Remove _speedups
• Remove _speedups.py and _speedups.so from simplejson
• They are trying to cache on the file system, which is a no-no on GAE.
import simplejson File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/__init__.py", line 113, in <module> from encoder import JSONEncoder File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/encoder.py", line 6, in <module> from simplejson import _speedups File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/_speedups.py", line 7, in <module> __bootstrap__() File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/_speedups.py", line 5, in __bootstrap__ del __bootstrap__, __loader__NameError: global name '__loader__' is not defined
15
Guido, the creator of Python speaks!
16
ianbicking to the rescue!
Ian responds one week later
17
Use httplib on GAE
## If you want to use httplib but get socket errors, ## you should uncomment this line: appengine_monkey.install_httplib()
• In paste-deploy.py:
18
No Twitter from GAE:(
19
More info
• Google App Enginehttp://code.google.com/appengine/
• Pylonshttp://pylonshq.com
• Instructions for Pylons on GAEhttp://code.google.com/p/appengine-monkey/wiki/Pylons
• DevHouseBostonhttp://devhouseboston.org
20
Thanks!
• To Ian Bicking for making appengine-monkey, making the instructions, and helping on IRC.
• The kind folks in #pylons who helped me get my head around Pylons syntax
21
top related