PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/google_app/versionhandler.py

https://code.google.com/p/dwarftherapist/
Python | 32 lines | 27 code | 4 blank | 1 comment | 1 complexity | a2b0f44847b34492a8c9dcdad8873556 MD5 | raw file
 1import logging
 2import pprint
 3import re
 4from google.appengine.ext import webapp
 5from metricentry import MetricEntry
 6from utils import ip_info
 7
 8CURRENT_VERSION = "0.6.12"
 9RX_VERSION_CHUNKER = re.compile(r"\s*DwarfTherapist\s+(\d+)\.(\d+)\.(\d+)\s*")
10class VersionHandler(webapp.RequestHandler):
11    def get(self, *args):
12        info = ip_info(self.request.remote_addr)
13        
14        entry = MetricEntry.get_or_insert("ip_%s" % self.request.remote_addr)
15        entry.ip = self.request.remote_addr
16        entry.city = info['city']
17        entry.country = info['country']
18        entry.region_name = info['region_name']
19        entry.region_code = info['region_code']
20        entry.dt_version_string = self.request.headers["User-Agent"]
21        #logging.info("user-agent: %s" % self.request.headers["User-Agent"])
22        m = re.match(RX_VERSION_CHUNKER, self.request.headers["User-Agent"])
23        if m:
24            print "MATCH GROUPS", m.groups()
25            entry.dt_version_major = int(m.group(1))
26            entry.dt_version_minor = int(m.group(2))
27            entry.dt_version_patch = int(m.group(3))
28        
29        entry.put()
30        
31        self.response.headers['Content-Type'] = 'text/plain'
32        self.response.out.write(CURRENT_VERSION);