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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gae/file_reader.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gae/pre_cacher.py
diff --git a/gae/pre_cacher.py b/gae/pre_cacher.py
index fbefe7b460631c8a737524edb995f99787949c1a..79074938b3cb72d504d1584989c41d2f8aefe78b 100644
--- a/gae/pre_cacher.py
+++ b/gae/pre_cacher.py
@@ -6,37 +6,41 @@ from google.appengine.api import urlfetch
import webapp2
import cache
+import cloudstorage
import config
+import content_type
+from urlparse import urlparse
class PreCacherFromUrl(webapp2.RequestHandler):
#
- # For local testing (since /gs paths are not available), precache the
- # meta-file (e.g. for revision 155046) from your browser:
+ # For local testing, put the revision file and the zip archive
+ # into the local GS server from your browser (e.g. for revision 155046):
#
- # http://localhost:8080/precache_url?path=revs/@155046&url=http://commondatastorage.googleapis.com/chrome-devtools-frontend/revs/@155046
+ # http://localhost:8080/precache_url?url=http://commondatastorage.googleapis.com/chrome-devtools-frontend/revs/@155046
#
# Then pre-cache the archive (you need to look up MD5 from the meta-file from the 'revs' metafile):
#
- # http://localhost:8080/precache_url?path=zips/e4eb112917d276dac7b43affa30422143f37fd26.zip&url=http://commondatastorage.googleapis.com/chrome-devtools-frontend/zips/e4eb112917d276dac7b43affa30422143f37fd26.zip
+ # http://localhost:8080/precache_url?url=http://commondatastorage.googleapis.com/chrome-devtools-frontend/zips/e4eb112917d276dac7b43affa30422143f37fd26.zip
#
# Then this works: http://localhost:8080/serve_rev/@155046/devtools.html
#
- # Remember to re-populate the cache after the server restarts (e.g. after
- # changing source files).
- #
def get(self):
if config.IS_DEV_APP_SERVER:
- path = self.request.GET['path']
url = self.request.GET['url']
self.response.headers['Content-Type'] = 'text/plain'
- self.response.write(precache_url(path, url))
+ self.response.write(precache_url(url))
else:
self.abort(403)
-def precache_url(file_name, url):
+def precache_url(url):
result = urlfetch.fetch(url)
+ file_name = urlparse(url).path
if result.status_code == 200:
- cache.set_content(file_name, result.content)
- return 'Cached %s as %s' % (url, file_name)
+ gcs_file = cloudstorage.open(file_name,
+ 'w',
+ content_type=content_type.from_path(file_name))
+ gcs_file.write(result.content)
+ gcs_file.close()
+ return 'Saved %s as %s' % (url, file_name)
else:
return 'Error: %d for %s' % (result.status_code, url)
« 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