Gae
Upcoming SlideShare
Loading in...5
×
 

Gae

on

  • 1,533 views

 

Statistics

Views

Total Views
1,533
Views on SlideShare
1,533
Embed Views
0

Actions

Likes
0
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Gae Gae Presentation Transcript

  • Google App Engine入門課程 國網中心格網技術組 專案助理研究員 鄭宗碩, Zong-shuo Jheng zsjheng@nchc.org.tw 參考網頁: http://nchc-gae.blogspot.com
  • Outline • What is Google App Engine • Prerequirements for a new pilot • Hello Google App Engine! • Pieces of a flying GAE • Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009
  • What is Google App Engine • Hosting services on Google cloud platform • Benefited by Google File System, BigTable • Free for limited accessing (10 free Web AP, up to 500MB of storage, up to 5 million page views a month, 2 billion CPU clock cycles one day) NCHC, Google App Engine experience course. 2009
  • Outline • What is Google App Engine • Prerequirements for a new pilot • Hello Google App Engine! • Pieces of a flying GAE • Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009
  • Prerequirements for a new pilot • Python runtime http://python.org/ • Google App Engine SDK http://code.google.com/appengine/ ~/:> upzip google_appengine_1.2.2.zip appcfg.py, dev_appserver.py • Eclipse with PyDev http://nchc-gae.blogspot.com/2009/05/eclipse-pydev-google-app-engine.html • Applying for a free account http://nchc-gae.blogspot.com/2009/05/google-app-engine.html NCHC, Google App Engine experience course. 2009
  • Outline • What is Google App Engine • Prerequirements for a new pilot • Hello Google App Engine! • Pieces of a flying GAE • Storing data in Google DataStore NCHC, Google App Engine experience course. 2009
  • Hello Google App Engine! <<app.yaml>> << hello.py >> application: HelloGAE from google.appengine.ext import webapp version: 1 from google.appengine.ext.webapp.util import run_wsgi_app runtime: python api_version: 1 class MainPage(webapp.RequestHandler): def get(self): handlers: self.response.headers['Content-Type'] = 'text/html; charset=UTF-8' - url: /.* self.response.out.write(quot;Hello Google App Engine!quot;) script: hello.py application = webapp.WSGIApplication([('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == quot;__main__quot;: main() NCHC, Google App Engine experience course. 2009
  • Outline • What is Google App Engine • Prerequirements for a new pilot • Hello Google App Engine! • Pieces of a flying GAE • Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009
  • Pieces of a flying GAE • Configuration files • MVC design pattern • webapp framework • Template • Google User service API • Dashboard NCHC, Google App Engine experience course. 2009
  • Configuration files • app.yaml • cron.yaml • index.yaml NCHC, Google App Engine experience course. 2009
  • MVC design pattern <<User-defined Handler class>> <<DataStore>> Eg. class Main_handler(webapp.RequestHandler) from google.appengine.ext import db <<Template>> from google.appengine.ext.webapp import template NCHC, Google App Engine experience course. 2009
  • webapp framework << hello.py >> from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class MainPage(webapp.RequestHandler): def get(self): 3 self.response.headers['Content-Type'] = 'text/html; charset=UTF-8' self.response.out.write(quot;Hello Google App Engine!quot;) application = webapp.WSGIApplication([('/', MainPage)], debug=True) def main(): 2 3 run_wsgi_app(application) 1 2 1 if __name__ == quot;__main__quot;: main() NCHC, Google App Engine experience course. 2009
  • Template Reference : http://nchc-gae.blogspot.com/2009/05/google-app-engine-template-tutorial.html <<template/index.htm>> <html> <head><title>Hello Template</title></head> <body> {{ Welcome_msg }} </body> </html> <<index.py>> import os from google.appengine.ext.webapp import template class Main_handler(webapp.RequestHandler): def get(self): template_value = { 'Welcome_msg': 'Hello, Template!' } path = os.path.join(os.path.dirname(__file__),'template/index.htm') outstr = template.render(path, template_value) self.response.out.write(outstr) NCHC, Google App Engine experience course. 2009
  • Google User service API from google.appengine.api import users create_login_url(dest_url) User class: create_logout_url(dest_url) class MyHandler(webapp.RequestHandler): email get_current_user() def get(self): nickname() is_current_user_admin() user = users.get_current_user() email() if user: user_id() greeting = (quot;Welcome, %s! (<a href=quot;%squot;>sign out</a>)quot; % (user.nickname(), users.create_logout_url(quot;/quot;))) else: greeting = (quot;<a href=quot;%squot;>Sign in or register</a>.quot; % users.create_login_url(quot;/quot;)) self.response.out.write(quot;<html><body>%s</body></html>quot; % greeting) user = users.get_current_user() if user: print quot;Welcome, %s!quot; % user.nickname() if users.is_current_user_admin(): print quot;<a href=quot;/admin/quot;>Go to admin area</a>quot; NCHC, Google App Engine experience course. 2009
  • Outline • What is Google App Engine • Prerequirements for a new pilot • Hello Google App Engine! • Pieces of a flying GAE • Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009
  • Data-storing black box - Google DataStore • Types and Property Classes http://code.google.com/intl/en/appengine/docs/python/datastore/typesandpropertyclasses.html • Entity and Model from google.appengine.ext import db class Pet(db.Model): name = db.StringProperty(required=True) type = db.StringProperty(required=True, choices=set([quot;catquot;, quot;dogquot;, quot;birdquot;])) birthdate = db.DateProperty() weight_in_pounds = db.IntegerProperty() pet = Pet(name=quot;Fluffyquot;, type=quot;catquot;, owner=users.get_current_user()) pet.weight_in_pounds = 24 NCHC, Google App Engine experience course. 2009
  • Data-storing black box - Google DataStore • Creating and Deleting Data pet.put() / db.put(pet), pet.delete() / db.delete(pet) • Getting data class Story(db.Model): title = db.StringProperty() date = db.DateTimeProperty() query = Story.all() query.filter('title =', 'Foo') query.order('-date') query.ancestor(key) query.filter('title =', 'Foo').order('-date').ancestor(key) NCHC, Google App Engine experience course. 2009
  • Data-storing black box - Google DataStore query = db.GqlQuery(quot;SELECT * FROM Story WHERE title = :1 quot; quot;AND ANCESTOR IS :2 quot; quot;ORDER BY date DESCquot;, 'Foo', key) query = Story.gql(quot;WHERE title = :title quot; quot;AND ANCESTOR IS :parent quot; quot;ORDER BY date DESCquot;, title='Foo', parent=key) NCHC, Google App Engine experience course. 2009