Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: appengine/findit/lib/gitiles/gitiles_repository.py

Issue 2557553002: [Culprit-Finder] Seperate gae related part in cache_decorator and gitile repository to gae_libs/ (Closed)
Patch Set: Fix nits. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import base64 5 import base64
6 from datetime import datetime 6 from datetime import datetime
7 from datetime import timedelta 7 from datetime import timedelta
8 import json 8 import json
9 import re 9 import re
10 10
11 # TODO(http://crbug.com/660466): We should try to break dependencies.
12 from lib.cache_decorator import Cached
13 from lib.cache_decorator import CompressedMemCacher
14 from lib.gitiles import commit_util 11 from lib.gitiles import commit_util
15 from lib.gitiles import diff 12 from lib.gitiles import diff
16 from lib.gitiles.blame import Blame 13 from lib.gitiles.blame import Blame
17 from lib.gitiles.blame import Region 14 from lib.gitiles.blame import Region
18 from lib.gitiles.change_log import ChangeLog 15 from lib.gitiles.change_log import ChangeLog
19 from lib.gitiles.change_log import FileChangeInfo 16 from lib.gitiles.change_log import FileChangeInfo
20 from lib.gitiles.git_repository import GitRepository 17 from lib.gitiles.git_repository import GitRepository
21 from lib.time_util import TimeZoneInfo 18 from lib.time_util import TimeZoneInfo
22 19
23 COMMIT_POSITION_PATTERN = re.compile( 20 COMMIT_POSITION_PATTERN = re.compile(
(...skipping 27 matching lines...) Expand all
51 self._repo_url = repo_url 48 self._repo_url = repo_url
52 49
53 @property 50 @property
54 def http_client(self): 51 def http_client(self):
55 return self._http_client 52 return self._http_client
56 53
57 @property 54 @property
58 def identifier(self): 55 def identifier(self):
59 return self.repo_url 56 return self.repo_url
60 57
61 @Cached(namespace='Gitiles-json-view', expire_time=CACHE_EXPIRE_TIME_SECONDS,
62 cacher=CompressedMemCacher())
63 def _SendRequestForJsonResponse(self, url, params=None): 58 def _SendRequestForJsonResponse(self, url, params=None):
64 if params is None: # pragma: no cover 59 if params is None: # pragma: no cover
65 params = {} 60 params = {}
66 params['format'] = 'json' 61 params['format'] = 'json'
67 62
68 # Gerrit prepends )]}' to json-formatted response. 63 # Gerrit prepends )]}' to json-formatted response.
69 prefix = ')]}\'\n' 64 prefix = ')]}\'\n'
70 65
71 status_code, content = self.http_client.Get(url, params) 66 status_code, content = self.http_client.Get(url, params)
72 if status_code != 200: 67 if status_code != 200:
73 return None 68 return None
74 elif not content or not content.startswith(prefix): 69 elif not content or not content.startswith(prefix):
75 raise Exception('Response does not begin with %s' % prefix) 70 raise Exception('Response does not begin with %s' % prefix)
76 71
77 return json.loads(content[len(prefix):]) 72 return json.loads(content[len(prefix):])
78 73
79 @Cached(namespace='Gitiles-text-view', expire_time=CACHE_EXPIRE_TIME_SECONDS)
80 def _SendRequestForTextResponse(self, url): 74 def _SendRequestForTextResponse(self, url):
81 status_code, content = self.http_client.Get(url, {'format': 'text'}) 75 status_code, content = self.http_client.Get(url, {'format': 'text'})
82 if status_code != 200: 76 if status_code != 200:
83 return None 77 return None
84 return base64.b64decode(content) 78 return base64.b64decode(content)
85 79
86 def _GetDateTimeFromString(self, datetime_string, 80 def _GetDateTimeFromString(self, datetime_string,
87 date_format='%a %b %d %H:%M:%S %Y'): 81 date_format='%a %b %d %H:%M:%S %Y'):
88 if TIMEZONE_PATTERN.findall(datetime_string): 82 if TIMEZONE_PATTERN.findall(datetime_string):
89 # Need to handle timezone conversion. 83 # Need to handle timezone conversion.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 215
222 for log in data['log']: 216 for log in data['log']:
223 changelogs.append(self._ParseChangeLogFromLogData(log)) 217 changelogs.append(self._ParseChangeLogFromLogData(log))
224 218
225 if 'next' in data: 219 if 'next' in data:
226 next_end_revision = data['next'] 220 next_end_revision = data['next']
227 else: 221 else:
228 next_end_revision = None 222 next_end_revision = None
229 223
230 return changelogs 224 return changelogs
OLDNEW
« no previous file with comments | « appengine/findit/lib/cache_decorator.py ('k') | appengine/findit/lib/gitiles/test/gitiles_repository_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698