OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import logging | |
6 import re | |
7 import json | |
8 | |
9 from google.appengine.api import memcache | |
10 from google.appengine.api import urlfetch | |
11 | |
12 DEFAULT_CACHE_TIME = 300 | |
13 | |
14 class BranchUtility(object): | |
15 """Utility class for dealing with different doc branches. | |
16 """ | |
17 | |
18 def GetChannelNameFromURL(self, url): | |
cduvall
2012/05/22 00:07:40
Can probably make this shorter, but works for now.
Aaron Boodman
2012/05/22 00:20:34
It should only count if it's the first url compone
cduvall
2012/05/22 01:23:55
Done.
| |
19 if '/dev/' in url: | |
20 return 'dev' | |
21 if '/beta/' in url: | |
22 return 'beta' | |
23 if '/trunk/' in url: | |
24 return 'trunk' | |
25 return 'stable' | |
26 | |
27 def GetBranchNumberForChannelName(self, name): | |
28 """Returns an empty string if the branch number cannot be found. | |
29 """ | |
30 if name == 'trunk': | |
cduvall
2012/05/22 00:07:40
omahaproxy.appspot.com has no branch number for tr
Aaron Boodman
2012/05/22 00:20:34
There's no branch number for trunk because ... it'
cduvall
2012/05/22 01:23:55
Done.
| |
31 return 'trunk' | |
Aaron Boodman
2012/05/22 00:20:34
In this case I think you should throw an exception
cduvall
2012/05/22 01:23:55
I think its cleaner to handle trunk in here, since
| |
32 result = memcache.get(name) | |
Aaron Boodman
2012/05/22 00:20:34
We are going to be using memcache for all kinds of
cduvall
2012/05/22 01:23:55
Done.
| |
33 if result is not None: | |
34 return result | |
35 logging.info('Branch number cache miss: ' + name) | |
36 | |
37 result = urlfetch.fetch( | |
38 url="http://omahaproxy.appspot.com/json", | |
39 method=urlfetch.GET) | |
40 | |
41 # Throw exception or something instead? | |
42 if result.status_code != 200: | |
Aaron Boodman
2012/05/22 00:20:34
Yeah, exception makes sense.
cduvall
2012/05/22 01:23:55
Done.
| |
43 return '' | |
44 | |
45 version_json = json.loads(result.content) | |
46 branch_number = None | |
47 for entry in version_json: | |
48 if entry['os'] != 'cf': | |
cduvall
2012/05/22 00:07:40
Not sure what os: cf was, but assumed it was the d
Aaron Boodman
2012/05/22 00:20:34
It stands for 'chromeframe' - you can search what
cduvall
2012/05/22 01:23:55
Done.
| |
49 continue | |
50 for version in entry['versions']: | |
Aaron Boodman
2012/05/22 00:20:34
Can you look at what version each platform has and
cduvall
2012/05/22 01:23:55
Done.
| |
51 if version['channel'] == name: | |
52 branch_number = version['true_branch'] | |
53 | |
54 if branch_number == None: | |
55 return '' | |
56 | |
57 if not memcache.add(name, branch_number, DEFAULT_CACHE_TIME): | |
58 logging.error('Memcache set failed.') | |
59 return branch_number | |
OLD | NEW |