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

Unified Diff: build/android/pylib/utils/google_storage_helper.py

Issue 2876183003: Add content addressed uploading helper function for render tests. (Closed)
Patch Set: Add content addressed uploading helper function for render tests. Created 3 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 | « build/android/pylib/local/device/local_device_instrumentation_test_run.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/google_storage_helper.py
diff --git a/build/android/pylib/utils/google_storage_helper.py b/build/android/pylib/utils/google_storage_helper.py
index 7a993a162f9d3290a9f61bf93864096c97e2373f..3e4aa455a3b1106c89bbaff0e558c61069508248 100644
--- a/build/android/pylib/utils/google_storage_helper.py
+++ b/build/android/pylib/utils/google_storage_helper.py
@@ -19,6 +19,7 @@ from pylib.utils import decorators
if host_paths.DEVIL_PATH not in sys.path:
sys.path.append(host_paths.DEVIL_PATH)
+from devil.android import md5sum
jbudorick 2017/05/12 17:13:59 Using this is fine (if not a bit unusual for a pur
mikecase (-- gone --) 2017/05/12 17:39:04 done. I agree this is definitely better
from devil.utils import cmd_helper
_GSUTIL_PATH = os.path.join(
@@ -45,10 +46,7 @@ def upload(name, filepath, bucket, content_type=None, authenticated_link=True):
Returns:
Web link to item uploaded to Google Storage bucket.
"""
- if bucket.startswith('gs://'):
- bucket = bucket[len('gs://'):]
- if bucket.endswith('/'):
- bucket = bucket[:-1]
+ bucket = _format_bucket_name(bucket)
gs_path = 'gs://%s/%s' % (bucket, name)
logging.info('Uploading %s to %s', filepath, gs_path)
@@ -60,8 +58,30 @@ def upload(name, filepath, bucket, content_type=None, authenticated_link=True):
cmd_helper.RunCmd(cmd)
- url_template = _AUTHENTICATED_URL if authenticated_link else _PUBLIC_URL
- return os.path.join(url_template % bucket, name)
+ return get_url_link(name, bucket, authenticated_link)
+
+
+def upload_content_addressed(
+ filepath, bucket, content_type=None, authenticated_link=True):
+ """Uploads data to Google Storage with filename as md5sum hash. If file
jbudorick 2017/05/12 17:13:59 nit: """Summary on one line. Other lines. """
mikecase (-- gone --) 2017/05/12 17:39:04 Done
+ already exists in bucket with hash name, nothing is uploaded."""
+ md5 = md5sum.CalculateHostMd5Sums(filepath)[filepath]
+ if not exists(md5, bucket):
+ upload(md5, filepath, bucket, content_type, authenticated_link)
+ return get_url_link(md5, bucket, authenticated_link)
+
+
+@decorators.NoRaiseException(default_return_value=False)
+def exists(name, bucket):
+ bucket = _format_bucket_name(bucket)
+ gs_path = 'gs://%s/%s' % (bucket, name)
+
+ cmd = [_GSUTIL_PATH, '-q', 'stat', gs_path]
+ return_code = cmd_helper.RunCmd(cmd)
+ if return_code == 0:
+ return True
+ else:
+ return False
def unique_name(basename, suffix='', timestamp=True, device=None):
@@ -94,9 +114,14 @@ def get_url_link(name, bucket, authenticated_link=True):
Returns:
Web link to item to be uploaded to Google Storage bucket
"""
+ bucket = _format_bucket_name(bucket)
+ url_template = _AUTHENTICATED_URL if authenticated_link else _PUBLIC_URL
+ return os.path.join(url_template % bucket, name)
+
+
+def _format_bucket_name(bucket):
if bucket.startswith('gs://'):
bucket = bucket[len('gs://'):]
if bucket.endswith('/'):
bucket = bucket[:-1]
- url_template = _AUTHENTICATED_URL if authenticated_link else _PUBLIC_URL
- return os.path.join(url_template % bucket, name)
+ return bucket
« no previous file with comments | « build/android/pylib/local/device/local_device_instrumentation_test_run.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698