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

Side by Side Diff: chrome/common/extensions/docs/server2/handler.py

Issue 13896007: Devserver: run the cron over the examples. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try again to avoid .svn Created 7 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 logging 5 import logging
6 import os 6 import os
7 from StringIO import StringIO 7 from StringIO import StringIO
8 8
9 from appengine_wrappers import webapp 9 from appengine_wrappers import webapp
10 from appengine_wrappers import memcache 10 from appengine_wrappers import memcache
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 self.headers = {} 90 self.headers = {}
91 self.path = path 91 self.path = path
92 self.url = '//localhost/%s' % path 92 self.url = '//localhost/%s' % path
93 93
94 channel = path.split('/')[-1] 94 channel = path.split('/')[-1]
95 logging.info('cron/%s: starting' % channel) 95 logging.info('cron/%s: starting' % channel)
96 96
97 server_instance = ServerInstance.GetOrCreateOnline(channel) 97 server_instance = ServerInstance.GetOrCreateOnline(channel)
98 98
99 def run_cron_for_dir(d, path_prefix=''): 99 def run_cron_for_dir(d, path_prefix=''):
100 error = None 100 success = True
101 start_time = time.time() 101 start_time = time.time()
102 files = [f for f in server_instance.content_cache.GetFromFileListing(d) 102 files = [f for f in server_instance.content_cache.GetFromFileListing(d)
103 if not f.endswith('/')] 103 if not f.endswith('/')]
104 for f in files: 104 for f in files:
105 error = None
105 path = '%s%s' % (path_prefix, f) 106 path = '%s%s' % (path_prefix, f)
106 try: 107 try:
107 response = MockResponse() 108 response = MockResponse()
108 server_instance.Get(path, MockRequest(path), response) 109 server_instance.Get(path, MockRequest(path), response)
109 if response.status != 200: 110 if response.status != 200:
110 error = 'Got %s response' % response.status 111 error = 'Got %s response' % response.status
111 except error: 112 except error:
112 pass 113 pass
113 if error: 114 if error:
114 logging.error('cron/%s: error rendering %s: %s' % ( 115 logging.error('cron/%s: error rendering %s: %s' % (
115 channel, path, error)) 116 channel, path, error))
117 success = False
116 logging.info('cron/%s: rendering %s files took %s seconds' % ( 118 logging.info('cron/%s: rendering %s files took %s seconds' % (
117 channel, len(files), time.time() - start_time)) 119 channel, len(files), time.time() - start_time))
118 return error 120 return success
119 121
120 # Don't use "or" since we want to evaluate everything no matter what. 122 # Don't use "or" since we want to evaluate everything no matter what.
121 was_error = any(( 123 success = any((
124 # Note: rendering the public templates will pull in all of the private
125 # templates.
122 run_cron_for_dir(svn_constants.PUBLIC_TEMPLATE_PATH), 126 run_cron_for_dir(svn_constants.PUBLIC_TEMPLATE_PATH),
123 run_cron_for_dir(svn_constants.STATIC_PATH, path_prefix='static/'))) 127 run_cron_for_dir(svn_constants.STATIC_PATH, path_prefix='static/'),
128 # Note: rendering the public templates will have pulled in the .js and
129 # manifest.json files (for listing examples on the API reference pages),
130 # but there are still images, CSS, etc.
131 run_cron_for_dir(svn_constants.EXAMPLES_PATH,
132 path_prefix='extensions/examples/')))
124 133
125 if was_error: 134 if success:
135 self.response.status = 200
136 self.response.out.write('Success')
137 else:
126 self.response.status = 500 138 self.response.status = 500
127 self.response.out.write('Failure') 139 self.response.out.write('Failure')
128 else:
129 self.response.status = 200
130 self.response.out.write('Success')
131 140
132 logging.info('cron/%s: finished' % channel) 141 logging.info('cron/%s: finished' % channel)
133 142
134 def _RedirectSpecialCases(self, path): 143 def _RedirectSpecialCases(self, path):
135 google_dev_url = 'http://developer.google.com/chrome' 144 google_dev_url = 'http://developer.google.com/chrome'
136 if path == '/' or path == '/index.html': 145 if path == '/' or path == '/index.html':
137 self.redirect(google_dev_url) 146 self.redirect(google_dev_url)
138 return True 147 return True
139 148
140 if path == '/apps.html': 149 if path == '/apps.html':
(...skipping 20 matching lines...) Expand all
161 if channel in path: 170 if channel in path:
162 position = path.index(channel) 171 position = path.index(channel)
163 path.pop(position) 172 path.pop(position)
164 path.insert(0, channel) 173 path.insert(0, channel)
165 new_url += '/'.join(path) 174 new_url += '/'.join(path)
166 self.redirect(new_url) 175 self.redirect(new_url)
167 return True 176 return True
168 177
169 def get(self): 178 def get(self):
170 path = self.request.path 179 path = self.request.path
180
181 if path in ['favicon.ico', 'robots.txt']:
182 response.set_status(404)
183 return
184
171 if self._RedirectSpecialCases(path): 185 if self._RedirectSpecialCases(path):
172 return 186 return
173 187
174 if path.startswith('/cron'): 188 if path.startswith('/cron'):
175 self._HandleCron(path) 189 self._HandleCron(path)
176 return 190 return
177 191
178 # Redirect paths like "directory" to "directory/". This is so relative 192 # Redirect paths like "directory" to "directory/". This is so relative
179 # file paths will know to treat this as a directory. 193 # file paths will know to treat this as a directory.
180 if os.path.splitext(path)[1] == '' and path[-1] != '/': 194 if os.path.splitext(path)[1] == '' and path[-1] != '/':
181 self.redirect(path + '/') 195 self.redirect(path + '/')
182 return 196 return
183 197
184 path = path.strip('/') 198 path = path.strip('/')
185 if self._RedirectFromCodeDotGoogleDotCom(path): 199 if self._RedirectFromCodeDotGoogleDotCom(path):
186 return 200 return
187 201
188 self._HandleGet(path) 202 self._HandleGet(path)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/fake_fetchers.py ('k') | chrome/common/extensions/docs/server2/integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698