Permalink
Browse files

Use python 2.7, and webapp2

  • Loading branch information...
1 parent a06c215 commit c70796a6809332b30a1ef8a74338f066abdb5ade @jasoncartwright jasoncartwright committed Oct 22, 2011
Showing with 26 additions and 24 deletions.
  1. +5 −4 app.yaml
  2. +13 −20 main.py → getfvco/__init__.py
  3. +8 −0 getfvco/application.py
View
@@ -1,8 +1,9 @@
-application: getfavicon
-version: 2
-runtime: python
+application: getfavicon27
+version: 3
+runtime: python27
api_version: 1
+threadsafe: true
handlers:
- url: .*
- script: main.py
+ script: getfvco.application
@@ -1,7 +1,6 @@
import os,re,logging
-from google.appengine.ext import webapp
-from google.appengine.ext.webapp import util
+from google.appengine.ext import webapp as webapp2
from google.appengine.ext.webapp import template
from google.appengine.api import memcache
from google.appengine.api import urlfetch
@@ -19,7 +18,7 @@
from models import *
-class BaseHandler(webapp.RequestHandler):
+class BaseHandler(webapp2.RequestHandler):
def htc(self,m):
return chr(int(m.group(1),16))
@@ -31,7 +30,7 @@ def urldecode(self,url):
def printTemplate(self,templateFile,templateVars):
# Find the full system path
- templateFile = os.path.join(os.path.dirname(__file__), "templates/%s.html" % (templateFile))
+ templateFile = os.path.join(os.path.dirname(__file__), "../templates/%s.html" % (templateFile))
# Write it out
self.response.out.write(template.render(templateFile,templateVars))
@@ -106,13 +105,17 @@ def get(self):
if stats.GlobalStat.all().get():
iconsCached = stats.GlobalStat.all().get().count
else:
- iconsCached = None
+ iconsCached = 0
# Icon calculations
favIconsServedM = round(float(favIconsServed) / 1000000,2)
iconsCachedM = round(float(iconsCached) / 1000000,2)
- percentReal = round(float(favIconsServedDefault) / float(favIconsServed) * 100,2)
- percentCache = round(float(iconFromCache) / float(iconFromCache + iconNotFromCache) * 100,2)
+ try:
+ percentReal = round(float(favIconsServedDefault) / float(favIconsServed) * 100,2)
+ percentCache = round(float(iconFromCache) / float(iconFromCache + iconNotFromCache) * 100,2)
+ except ZeroDivisionError:
+ percentReal = 0
+ percentCache = 0
self.printTemplate("index",{
"isHomepage":True,
@@ -458,14 +461,9 @@ def get(self):
if not self.iconInPage():
self.writeDefault()
-
-def main():
-
- logging.getLogger().setLevel(logging.DEBUG)
-
- application = webapp.WSGIApplication(
+application = webapp2.WSGIApplication(
[
('/', IndexPage),
('/decache/', Decache),
@@ -475,10 +473,5 @@ def main():
('/_deleteall', deleteAll),
('/.*', PrintFavicon),
],
- debug=False
- )
- util.run_wsgi_app(application)
-
-
-if __name__ == '__main__':
- main()
+ debug=True
+)
View
@@ -0,0 +1,8 @@
+from getfvco import application
+from google.appengine.ext.webapp.util import run_wsgi_app
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == '__main__':
+ main()

0 comments on commit c70796a

Please sign in to comment.