sregistry/main/google_build/push.py
def upload(self, source, 
                 destination, 
                 bucket,
                 chunk_size = 2 * 1024 * 1024, 
                 metadata=None,
                 keep_private=True):

    '''upload a file from a source to a destination. The client is expected
       to have a bucket (self._bucket) that is created when instantiated.
     
       This would be the method to do the same using the storage client,
       but not easily done for resumable

       blob = self._bucket.blob(destination)
       blob.upload_from_filename(filename=source, 
                                 content_type="application/zip",
                                 client=self._service)

       url = blob.public_url
       if isinstance(url, six.binary_type):
           url = url.decode('utf-8')

       return url
    '''
    env = 'SREGISTRY_GOOGLE_STORAGE_PRIVATE'
    keep_private = self._get_and_update_setting(env) or keep_private

    media = MediaFileUpload(source, chunksize=chunk_size, resumable=True)
    request = self._storage_service.objects().insert(bucket=bucket.name, 
                                                     name=destination,
                                                     media_body=media)

    response = None
    total = request.resumable._size / (1024*1024.0)

    bar = ProgressBar(expected_size=total, filled_char='=', hide=self.quiet)

    while response is None:
        error = None
        try:
            progress, response = request.next_chunk()
            if progress:
                bar.show(progress.resumable_progress / (1024*1024.0))
        except:
            raise

    # When we finish upload, get as blob
    blob = bucket.blob(destination)
    if blob.exists():

        if not keep_private:
            blob.make_public()
    
        # If the user has a dictionary of metadata to update
        if metadata is not None:
            body = prepare_metadata(metadata)
            blob.metadata = metadata   
            blob._properties['metadata'] = metadata
            blob.patch()

    return response
def upload(self, source, 
                 destination, 
                 bucket,
                 chunk_size = 2 * 1024 * 1024, 
                 metadata=None,
                 keep_private=True):

    '''upload a file from a source to a destination. The client is expected
       to have a bucket (self._bucket) that is created when instantiated.
     
       This would be the method to do the same using the storage client,
       but not easily done for resumable

       blob = self._bucket.blob(destination)
       blob.upload_from_filename(filename=source, 
                                 content_type="application/zip",
                                 client=self._service)

       url = blob.public_url
       if isinstance(url, six.binary_type):
           url = url.decode('utf-8')

       return url
    '''
    env = 'SREGISTRY_GOOGLE_STORAGE_PRIVATE'
    keep_private = self._get_and_update_setting(env) or keep_private

    media = MediaFileUpload(source, chunksize=chunk_size, resumable=True)
    request = self._storage_service.objects().insert(bucket=bucket.name, 
                                                     name=destination,
                                                     media_body=media)

    response = None
    total = request.resumable._size / (1024*1024.0)

    bar = ProgressBar(expected_size=total, filled_char='=', hide=self.quiet)

    while response is None:
        error = None
        try:
            progress, response = request.next_chunk()
            if progress:
                bar.show(progress.resumable_progress / (1024*1024.0))
        except:
            raise

    # When we finish upload, get as blob
    blob = bucket.blob(destination)
    if blob.exists():

        if not keep_private:
            blob.make_public()
    
        # If the user has a dictionary of metadata to update
        if metadata is not None:
            body = prepare_metadata(metadata)
            blob.metadata = metadata   
            blob._properties['metadata'] = metadata
            blob.patch()

    return response
def upload ( self , source , destination , bucket , chunk_size = 2 * 1024 * 1024 , metadata = None , keep_private = True ) : env = 'SREGISTRY_GOOGLE_STORAGE_PRIVATE' keep_private = self . _get_and_update_setting ( env ) or keep_private media = MediaFileUpload ( source , chunksize = chunk_size , resumable = True ) request = self . _storage_service . objects ( ) . insert ( bucket = bucket . name , name = destination , media_body = media ) response = None total = request . resumable . _size / ( 1024 * 1024.0 ) bar = ProgressBar ( expected_size = total , filled_char = '=' , hide = self . quiet ) while response is None : error = None try : progress , response = request . next_chunk ( ) if progress : bar . show ( progress . resumable_progress / ( 1024 * 1024.0 ) ) except : raise # When we finish upload, get as blob blob = bucket . blob ( destination ) if blob . exists ( ) : if not keep_private : blob . make_public ( ) # If the user has a dictionary of metadata to update if metadata is not None : body = prepare_metadata ( metadata ) blob . metadata = metadata blob . _properties [ 'metadata' ] = metadata blob . patch ( ) return response
upload a file from a source to a destination. The client is expected
       to have a bucket (self._bucket) that is created when instantiated.
     
       This would be the method to do the same using the storage client,
       but not easily done for resumable

       blob = self._bucket.blob(destination)
       blob.upload_from_filename(filename=source, 
                                 content_type="application/zip",
                                 client=self._service)

       url = blob.public_url
       if isinstance(url, six.binary_type):
           url = url.decode('utf-8')

       return url
upload a file from a source to a destination . The client is expected to have a bucket ( self . _bucket ) that is created when instantiated . This would be the method to do the same using the storage client but not easily done for resumable