class PythonBosClient(object):
    
    def __init__(self):    
        #新建BOSClient
        self._client = BosClient(bos_conf.config)
                
    def list_buckets(self):
        response = self._client.list_buckets()
        for bucket in response.buckets:
            print bucket.name            
    
    def list_objects(self,bucket_name,prefix = ""):
        response = self._client.list_objects(bucket_name,1000,prefix)
        for object in response.contents:
           print object.key  
           
    def del_objects(self,bucket_name,key_name):            
        response = self._client.list_objects(bucket_name,1000,prefix)
        for object in response.contents:                             
            self._client.delete_object(bucket_name,object.key)  
            print object.key + " Deleted"  
                       
    def dels_objects(self,bucket_name,prefix):            
        response = self._client.list_objects(bucket_name,1000,prefix)
        for object in response.contents:                             
            self._client.delete_object(bucket_name,object.key)  
            print object.key + " Deleted"                                                                      
Exemple #2
0
class PythonBosClient(object):
    def __init__(self):
        #新建BOSClient
        self._client = BosClient(bos_conf.config)

    def list_buckets(self):
        response = self._client.list_buckets()
        for bucket in response.buckets:
            print bucket.name

    def list_objects(self, bucket_name, prefix=""):
        response = self._client.list_objects(bucket_name, 1000, prefix)
        for object in response.contents:
            print object.key

    def del_objects(self, bucket_name, key_name):
        response = self._client.list_objects(bucket_name, 1000, prefix)
        for object in response.contents:
            self._client.delete_object(bucket_name, object.key)
            print object.key + " Deleted"

    def dels_objects(self, bucket_name, prefix):
        response = self._client.list_objects(bucket_name, 1000, prefix)
        for object in response.contents:
            self._client.delete_object(bucket_name, object.key)
            print object.key + " Deleted"
Exemple #3
0
    # check if bucket exists
    if not bos_client.does_bucket_exist(bucket_name):
        bos_client.create_bucket(bucket_name)

    # delete a bucket(you can't  delete a bucket which is not empty)
    # clear it first
    for obj in bos_client.list_all_objects(bucket_name):
        bos_client.delete_object(bucket_name, obj.key)
    bos_client.delete_bucket(bucket_name)

    # create the bucket again
    bos_client.create_bucket(bucket_name)

    # list your buckets
    response = bos_client.list_buckets()
    for bucket in response.buckets:
        __logger.debug("[Sample] list buckets:%s", bucket.name)

    ######################################################################################################
    #            object operation samples
    ######################################################################################################

    # put a string as object
    bos_client.put_object_from_string(bucket_name, key, "This is string content.")

    # get a object as string
    content = bos_client.get_object_as_string(bucket_name, key)
    __logger.debug("[Sample] get object as string:%s", content)

    # put a file as object
    # check if bucket exists
    if not bos_client.does_bucket_exist(bucket_name):
        bos_client.create_bucket(bucket_name)

    # delete a bucket(you can't  delete a bucket which is not empty)
    # clear it first
    for obj in bos_client.list_all_objects(bucket_name):
        bos_client.delete_object(bucket_name, obj.key)
    bos_client.delete_bucket(bucket_name)

    # create the bucket again
    bos_client.create_bucket(bucket_name)

    # list your buckets
    response = bos_client.list_buckets()
    for bucket in response.buckets:
        __logger.debug("[Sample] list buckets:%s", bucket.name)

    ######################################################################################################
    #            object operation samples
    ######################################################################################################

    # put a string as object
    bos_client.put_object_from_string(bucket_name, key,
                                      "This is string content.")

    # get a object as string
    content = bos_client.get_object_as_string(bucket_name, key)
    __logger.debug("[Sample] get object as string:%s", content)