GoogleCloudStorageBucket.gcs_bucket → _gcs_bucket

Added a few FIXME comments where _gcs_bucket is used outside of the class.
This commit is contained in:
2016-11-09 11:43:52 +01:00
committed by Francesco Siddi
parent 27df603299
commit e5b4ce0890
3 changed files with 15 additions and 13 deletions

View File

@@ -45,8 +45,9 @@ def size_descriptor(width, height):
@skip_when_testing @skip_when_testing
def rename_on_gcs(bucket_name, from_path, to_path): def rename_on_gcs(bucket_name, from_path, to_path):
gcs = GoogleCloudStorageBucket(str(bucket_name)) gcs = GoogleCloudStorageBucket(str(bucket_name))
blob = gcs.gcs_bucket.blob(from_path) # FIXME: don't use internal property, but use our bucket/blob API.
gcs.gcs_bucket.rename_blob(blob, to_path) blob = gcs._gcs_bucket.blob(from_path)
gcs._gcs_bucket.rename_blob(blob, to_path)
@encoding.route('/zencoder/notifications', methods=['POST']) @encoding.route('/zencoder/notifications', methods=['POST'])

View File

@@ -172,7 +172,8 @@ def after_inserting_project(project, db_user):
else: else:
try: try:
gcs_storage = GoogleCloudStorageBucket(str(project_id)) gcs_storage = GoogleCloudStorageBucket(str(project_id))
if gcs_storage.gcs_bucket.exists(): # FIXME: don't use internal property, but use our bucket/blob API.
if gcs_storage._gcs_bucket.exists():
log.info('Created GCS instance for project %s', project_id) log.info('Created GCS instance for project %s', project_id)
else: else:
log.warning('Unable to create GCS instance for project %s', project_id) log.warning('Unable to create GCS instance for project %s', project_id)

View File

@@ -54,11 +54,11 @@ class GoogleCloudStorageBucket(Bucket):
def __init__(self, name, subdir='_/'): def __init__(self, name, subdir='_/'):
super(GoogleCloudStorageBucket, self).__init__(name=name) super(GoogleCloudStorageBucket, self).__init__(name=name)
try: try:
self.gcs_bucket = gcs.get_bucket(name) self._gcs_bucket = gcs.get_bucket(name)
except NotFound: except NotFound:
self.gcs_bucket = gcs.bucket(name) self._gcs_bucket = gcs.bucket(name)
# Hardcode the bucket location to EU # Hardcode the bucket location to EU
self.gcs_bucket.location = 'EU' self._gcs_bucket.location = 'EU'
# Optionally enable CORS from * (currently only used for vrview) # Optionally enable CORS from * (currently only used for vrview)
# self.gcs_bucket.cors = [ # self.gcs_bucket.cors = [
# { # {
@@ -68,7 +68,7 @@ class GoogleCloudStorageBucket(Bucket):
# "maxAgeSeconds": 3600 # "maxAgeSeconds": 3600
# } # }
# ] # ]
self.gcs_bucket.create() self._gcs_bucket.create()
self.subdir = subdir self.subdir = subdir
@@ -87,7 +87,7 @@ class GoogleCloudStorageBucket(Bucket):
prefix = os.path.join(self.subdir, path) prefix = os.path.join(self.subdir, path)
fields_to_return = 'nextPageToken,items(name,size,contentType),prefixes' fields_to_return = 'nextPageToken,items(name,size,contentType),prefixes'
req = self.gcs_bucket.list_blobs(fields=fields_to_return, prefix=prefix, req = self._gcs_bucket.list_blobs(fields=fields_to_return, prefix=prefix,
delimiter='/') delimiter='/')
files = [] files = []
@@ -138,7 +138,7 @@ class GoogleCloudStorageBucket(Bucket):
:param to_dict: Return the object as a dictionary. :param to_dict: Return the object as a dictionary.
""" """
path = os.path.join(self.subdir, path) path = os.path.join(self.subdir, path)
blob = self.gcs_bucket.blob(path) blob = self._gcs_bucket.blob(path)
if blob.exists(): if blob.exists():
if to_dict: if to_dict:
return self.blob_to_dict(blob) return self.blob_to_dict(blob)
@@ -151,7 +151,7 @@ class GoogleCloudStorageBucket(Bucket):
"""Create new blob and upload data to it. """Create new blob and upload data to it.
""" """
path = path if path else os.path.join('_', os.path.basename(full_path)) path = path if path else os.path.join('_', os.path.basename(full_path))
blob = self.gcs_bucket.blob(path) blob = self._gcs_bucket.blob(path)
if blob.exists(): if blob.exists():
return None return None
blob.upload_from_filename(full_path) blob.upload_from_filename(full_path)
@@ -183,10 +183,10 @@ class GoogleCloudStorageBucket(Bucket):
""" """
assert isinstance(to_bucket, GoogleCloudStorageBucket) assert isinstance(to_bucket, GoogleCloudStorageBucket)
return self.gcs_bucket.copy_blob(blob, to_bucket.gcs_bucket) return self._gcs_bucket.copy_blob(blob, to_bucket._gcs_bucket)
def get_blob(self, internal_fname, chunk_size=256 * 1024 * 2): def get_blob(self, internal_fname, chunk_size=256 * 1024 * 2):
return self.gcs_bucket.blob('_/' + internal_fname, chunk_size) return self._gcs_bucket.blob('_/' + internal_fname, chunk_size)
class GoogleCloudStorageBlob(Blob): class GoogleCloudStorageBlob(Blob):