Source

tracko / app / main.py

from __future__ import with_statement

import os, cgi, urllib, pprint, logging

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import wsgiref.handlers

import models, settings
from logic import process_announce_request


class MainHandler(webapp.RequestHandler):
  def get(self):
    template_values = {}
    try:
      template_values['ga_token'] = settings.ga_token
    except:
      pass
    template_values['announce_url'] = 'http://%s%s/announce' % (
      self.request.server_name,
      ':%d' % self.request.server_port if self.request.server_port != 80 else '')
    path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html')
    self.response.out.write(template.render(path, template_values))    

class AnnounceHandler(webapp.RequestHandler):
  def get(self):
    if not self.request.query_string:
      # empty query string,
      # most probably someone opened announce url in browser
      self.redirect('/')
    request_params = dict(
      (name, urllib.unquote_plus(values[-1]))
      for (name, values) in cgi.parse_qs(self.request.query_string).items())
    logging.debug(pprint.pformat(request_params))
    response_body = process_announce_request(
        request_params, self.request.remote_addr, settings)
    #
    self.response.headers['content-type'] = 'text/plain'
    self.response.out.write(response_body)


def create_application():
  return webapp.WSGIApplication(
    [('/', MainHandler),
     ('/announce', AnnounceHandler)],
    debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(create_application())

if __name__ == '__main__':
  main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.