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

Unified Diff: tools/android/loading/chrome_cache.py

Issue 1737103002: sandwich: Implements filter-cache sub-command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i10
Patch Set: Created 4 years, 10 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 | « no previous file | tools/android/loading/sandwich.py » ('j') | tools/android/loading/sandwich.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/chrome_cache.py
diff --git a/tools/android/loading/chrome_cache.py b/tools/android/loading/chrome_cache.py
index d6d65a265690fdc4a2fa9fea4a3238a4dd7511e6..16d83fbfcd280bc5591a605f908dbc5ed6f68f8a 100644
--- a/tools/android/loading/chrome_cache.py
+++ b/tools/android/loading/chrome_cache.py
@@ -8,6 +8,7 @@
from datetime import datetime
import json
import os
+import shutil
import subprocess
import sys
import tempfile
@@ -141,6 +142,8 @@ def ZipDirectoryContent(root_directory_path, archive_dest_path):
root_directory_path: The directory's path to archive.
archive_dest_path: Archive destination's path.
"""
+ if os.path.isfile(archive_dest_path):
mattcary 2016/02/26 09:33:08 This doesn't seem to be necessary---zipfile will s
pasko 2016/02/26 17:10:06 is it really necessary to remove before writing? A
gabadie 2016/03/01 10:40:48 Done.
+ os.remove(archive_dest_path)
with zipfile.ZipFile(archive_dest_path, 'w') as zip_output:
timestamps = {}
root_directory_stats = os.stat(root_directory_path)
@@ -278,6 +281,30 @@ class CacheBackend(object):
return stdout_data
+def ApplyUrlWhitelistToCacheArchive(cache_archive_path,
+ whitelisted_urls,
+ output_cache_archive_path):
+ """Generate a new cache archive containing only whitelisted urls.
+
+ Args:
+ cache_archive_path: Path of the cache archive to apply the white listing.
+ whitelisted_urls: Set of url to keep in cache.
+ output_cache_archive_path: Destination path of cache archive containing only
+ white-listed urls.
+ """
+ cache_temp_directory = tempfile.mkdtemp(suffix='.cache')
+ UnzipDirectoryContent(cache_archive_path, cache_temp_directory)
+ backend = CacheBackend(cache_temp_directory, 'simple')
+ cached_urls = backend.ListKeys()
+ for cached_url in cached_urls:
+ if cached_url not in whitelisted_urls:
+ backend.DeleteKey(cached_url)
+ for cached_url in backend.ListKeys():
+ assert cached_url in whitelisted_urls
+ ZipDirectoryContent(cache_temp_directory, output_cache_archive_path)
+ shutil.rmtree(cache_temp_directory)
pasko 2016/02/26 17:10:06 the try..finally would avoid polluting the filesys
gabadie 2016/03/01 10:40:48 Good point. I think we should just do a util like
+
+
if __name__ == '__main__':
import argparse
pasko 2016/02/26 17:10:06 why import here?
gabadie 2016/03/01 10:40:48 Because this is a lib manual test (in the mean tim
pasko 2016/03/01 16:01:11 isn't this against the style guide? To avoid the p
gabadie 2016/03/01 16:49:09 According to Benoit, that is a common practice. ht
pasko 2016/03/01 17:55:53 I disagree with Benoit here. In the Chromium codeb
parser = argparse.ArgumentParser(description='Tests cache back-end.')
pasko 2016/02/26 17:10:06 nit: backend in one word
gabadie 2016/03/01 10:40:48 Looks like the two are correct. Keeping it to be c
pasko 2016/03/01 16:01:11 They are both correct, but we should prefer using
gabadie 2016/03/01 16:49:09 Acknowledged.
« no previous file with comments | « no previous file | tools/android/loading/sandwich.py » ('j') | tools/android/loading/sandwich.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698