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

Unified Diff: tools/telemetry/telemetry/util/cloud_storage.py

Issue 838253005: Refactor serving_dirs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests. Created 5 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
Index: tools/telemetry/telemetry/util/cloud_storage.py
diff --git a/tools/telemetry/telemetry/util/cloud_storage.py b/tools/telemetry/telemetry/util/cloud_storage.py
index 0e1ddc3f44ef8991eb36ea2820038fac7243d4b1..34bd477b7e7bffd9eba2abae702338edba218392 100644
--- a/tools/telemetry/telemetry/util/cloud_storage.py
+++ b/tools/telemetry/telemetry/util/cloud_storage.py
@@ -14,6 +14,7 @@ import sys
import tarfile
import urllib2
+from telemetry import decorators
from telemetry.core import util
from telemetry.util import path
@@ -217,10 +218,8 @@ def Insert(bucket, remote_path, local_path, publicly_readable=False):
def GetIfChanged(file_path, bucket):
- """Gets the file at file_path if it has a hash file that doesn't match.
-
- If the file is not in Cloud Storage, log a warning instead of raising an
- exception. We assume that the user just hasn't uploaded the file yet.
+ """Gets the file at file_path if it has a hash file that doesn't match or
+ if there is no local copy of file_path, but there is a hash file for it.
Returns:
True if the binary was changed.
@@ -241,6 +240,21 @@ def GetIfChanged(file_path, bucket):
Get(bucket, expected_hash, file_path)
return True
+@decorators.Cache
sullivan 2015/02/20 17:47:37 Since this function is moved, it's good to keep th
aiolos (Not reviewing) 2015/02/20 19:06:51 Acknowledged. I added a TODO for it.
+def GetFilesInDirectoryIfChanged(directory, bucket):
+ """ Scan the directory for .sha1 files, and download them from the given
+ bucket in cloud storage if the local and remote hash don't match or
+ there is no local copy.
+ """
+ if os.path.splitdrive(directory)[1] == '/':
+ raise ValueError('Trying to serve root directory from HTTP server.')
+ for dirpath, _, filenames in os.walk(directory):
+ for filename in filenames:
+ path_name, extension = os.path.splitext(
+ os.path.join(dirpath, filename))
+ if extension != '.sha1':
+ continue
+ GetIfChanged(path_name, bucket)
def CalculateHash(file_path):
"""Calculates and returns the hash of the file at file_path."""

Powered by Google App Engine
This is Rietveld 408576698