aboutsummaryrefslogtreecommitdiff
path: root/test-infra/s3_cache.py
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-04-03 11:34:15 -0700
committerChris Rebert <[email protected]>2014-04-03 11:34:15 -0700
commit9c7e86be994145b06ddfa2c6d184da3d63bb596b (patch)
tree2396a61b54bd872ae776e8464f594713bcf032cf /test-infra/s3_cache.py
parent4c2626fecb60f7f31f248ac10597294f2cd2471b (diff)
downloadbootstrap-9c7e86be994145b06ddfa2c6d184da3d63bb596b.tar.xz
bootstrap-9c7e86be994145b06ddfa2c6d184da3d63bb596b.zip
add timing logic+output to s3_cache.py
Diffstat (limited to 'test-infra/s3_cache.py')
-rwxr-xr-xtest-infra/s3_cache.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/test-infra/s3_cache.py b/test-infra/s3_cache.py
index adc466e00..7008d839c 100755
--- a/test-infra/s3_cache.py
+++ b/test-infra/s3_cache.py
@@ -6,6 +6,8 @@ from os import environ, stat, remove as _delete_file
from os.path import isfile, dirname, basename, abspath
from hashlib import sha256
from subprocess import check_call as run
+from contextlib import contextmanager
+from datetime import datetime
from boto.s3.connection import S3Connection
from boto.s3.key import Key
@@ -20,6 +22,15 @@ except KeyError:
raise SystemExit("TWBS_S3_BUCKET environment variable not set!")
+@contextmanager
+def timer():
+ start = datetime.utcnow()
+ yield
+ end = datetime.utcnow()
+ elapsed = end - start
+ print("\tDone. Took", int(elapsed.total_seconds()), "seconds.")
+
+
def _sha256_of_file(filename):
hasher = sha256()
with open(filename, 'rb') as input_file:
@@ -47,19 +58,22 @@ def _tarball_filename_for(directory):
def _create_tarball(directory):
print("Creating tarball of {}...".format(directory))
- run(['tar', '-czf', _tarball_filename_for(directory), '-C', dirname(directory), basename(directory)])
+ with timer():
+ run(['tar', '-czf', _tarball_filename_for(directory), '-C', dirname(directory), basename(directory)])
def _extract_tarball(directory):
print("Extracting tarball of {}...".format(directory))
- run(['tar', '-xzf', _tarball_filename_for(directory), '-C', dirname(directory)])
+ with timer():
+ run(['tar', '-xzf', _tarball_filename_for(directory), '-C', dirname(directory)])
def download(directory):
_delete_file_quietly(NEED_TO_UPLOAD_MARKER)
try:
print("Downloading {} tarball from S3...".format(friendly_name))
- key.get_contents_to_filename(_tarball_filename_for(directory))
+ with timer():
+ key.get_contents_to_filename(_tarball_filename_for(directory))
except S3ResponseError as err:
open(NEED_TO_UPLOAD_MARKER, 'a').close()
print(err)
@@ -72,7 +86,8 @@ def download(directory):
def upload(directory):
_create_tarball(directory)
print("Uploading {} tarball to S3... ({})".format(friendly_name, _tarball_size(directory)))
- key.set_contents_from_filename(_tarball_filename_for(directory))
+ with timer():
+ key.set_contents_from_filename(_tarball_filename_for(directory))
print("{} cache successfully updated.".format(friendly_name))
_delete_file_quietly(NEED_TO_UPLOAD_MARKER)