blob: 1537d8aba7101f0866985d30e3fd9b82887c5c49 [file] [log] [blame] [edit]
"""Collection of utilities to work with Google Cloud Storage and gsutil."""
import os
def gsutil():
"""Returns the path to the gsutil binary."""
# Search the normal install path for gsutil first. This should succeed
# most of the time. (A notable exception being GCE instances, which
# have gsutil on the PATH somewhere else.)
gsutil_path = os.path.expanduser('~/gsutil/gsutil')
if os.path.exists(gsutil_path):
return gsutil_path
# Otherwise, assume that gsutil is on the PATH so that this will find it.
return 'gsutil'
def upload_directory_cmd(local_dir, gcs_dir):
"""Command to upload the contents of the local directory to the GCS bucket.
Note that this assumes a gsutil install located at ~/gsutil.
Args:
local_dir: local directory to upload the contents of (e.g. path/to/foo)
gcs_dir: directory on GCS to upload to (e.g. gs://my-bucket/foo)
Returns:
The command (as a list) to execute to upload a directory to GCS.
"""
return [gsutil(), 'cp', '-r', local_dir, gcs_dir]