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

Side by Side Diff: gae/pre_cacher.py

Issue 1150463002: [chrome-devtools-frontend] Migrate to cloudstorage client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chrome-devtools-frontend
Patch Set: Created 5 years, 7 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
« no previous file with comments | « gae/file_reader.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 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 from google.appengine.api import urlfetch 5 from google.appengine.api import urlfetch
6 import webapp2 6 import webapp2
7 7
8 import cache 8 import cache
9 import cloudstorage
9 import config 10 import config
11 import content_type
12 from urlparse import urlparse
10 13
11 class PreCacherFromUrl(webapp2.RequestHandler): 14 class PreCacherFromUrl(webapp2.RequestHandler):
12 # 15 #
13 # For local testing (since /gs paths are not available), precache the 16 # For local testing, put the revision file and the zip archive
14 # meta-file (e.g. for revision 155046) from your browser: 17 # into the local GS server from your browser (e.g. for revision 155046):
15 # 18 #
16 # http://localhost:8080/precache_url?path=revs/@155046&url=http://commondatast orage.googleapis.com/chrome-devtools-frontend/revs/@155046 19 # http://localhost:8080/precache_url?url=http://commondatastorage.googleapis.c om/chrome-devtools-frontend/revs/@155046
17 # 20 #
18 # Then pre-cache the archive (you need to look up MD5 from the meta-file from the 'revs' metafile): 21 # Then pre-cache the archive (you need to look up MD5 from the meta-file from the 'revs' metafile):
19 # 22 #
20 # http://localhost:8080/precache_url?path=zips/e4eb112917d276dac7b43affa304221 43f37fd26.zip&url=http://commondatastorage.googleapis.com/chrome-devtools-fronte nd/zips/e4eb112917d276dac7b43affa30422143f37fd26.zip 23 # http://localhost:8080/precache_url?url=http://commondatastorage.googleapis.c om/chrome-devtools-frontend/zips/e4eb112917d276dac7b43affa30422143f37fd26.zip
21 # 24 #
22 # Then this works: http://localhost:8080/serve_rev/@155046/devtools.html 25 # Then this works: http://localhost:8080/serve_rev/@155046/devtools.html
23 # 26 #
24 # Remember to re-populate the cache after the server restarts (e.g. after
25 # changing source files).
26 #
27 def get(self): 27 def get(self):
28 if config.IS_DEV_APP_SERVER: 28 if config.IS_DEV_APP_SERVER:
29 path = self.request.GET['path']
30 url = self.request.GET['url'] 29 url = self.request.GET['url']
31 self.response.headers['Content-Type'] = 'text/plain' 30 self.response.headers['Content-Type'] = 'text/plain'
32 self.response.write(precache_url(path, url)) 31 self.response.write(precache_url(url))
33 else: 32 else:
34 self.abort(403) 33 self.abort(403)
35 34
36 def precache_url(file_name, url): 35 def precache_url(url):
37 result = urlfetch.fetch(url) 36 result = urlfetch.fetch(url)
37 file_name = urlparse(url).path
38 if result.status_code == 200: 38 if result.status_code == 200:
39 cache.set_content(file_name, result.content) 39 gcs_file = cloudstorage.open(file_name,
40 return 'Cached %s as %s' % (url, file_name) 40 'w',
41 content_type=content_type.from_path(file_name))
42 gcs_file.write(result.content)
43 gcs_file.close()
44 return 'Saved %s as %s' % (url, file_name)
41 else: 45 else:
42 return 'Error: %d for %s' % (result.status_code, url) 46 return 'Error: %d for %s' % (result.status_code, url)
OLDNEW
« no previous file with comments | « gae/file_reader.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698