parallel_change_blob_access_tier.py [53:125]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def pinit(c):
    
    global cnt
    cnt = c
    
class Counter(object):
    
    def __init__(self, total):
        # 'i' means integer
        self.val = multiprocessing.Value('i', 0)
        self.total = multiprocessing.Value('i', total)
        self.last_print = multiprocessing.Value('i', 0)

    def increment(self, n=1):
        b_print = False
        with self.val.get_lock():
            self.val.value += n
            if ((self.val.value - self.last_print.value) >= n_print):
                self.last_print.value = self.val.value
                b_print = True           
        if b_print:
            total_string = ''
            if self.total.value > 0:
                 total_string = ' of {}'.format(self.total.value)
            print('{}: iteration {}{}'.format(time.strftime("%Y-%m-%d %H:%M:%S"), 
                                                                 self.val.value,total_string),flush=True)
    @property
    def value(self):
        return self.val.value
    def last_print_value(self):
        return self.last_print.value
    
pinit(Counter(-1))


#%% Support functions

def get_container_client(account_name,container_name,sas_token_file):
    
    storage_account_url_blob = 'https://' + account_name + '.blob.core.windows.net'
    
    assert(os.path.isfile(sas_token_file))
    
    with open(sas_token_file) as f:
        content = f.readlines()
        content = [x.strip() for x in content] 
    
    # Not required
    # ro_sas_token = content[0]
    # assert ro_sas_token.startswith('?')
    
    rw_sas_token = content[1]    
    assert rw_sas_token.startswith('?')
    
    blob_service_client = BlobServiceClient(account_url=storage_account_url_blob, 
                                            credential=rw_sas_token)
    
    container_client = blob_service_client.get_container_client(container_name)

    return container_client
    

def blob_exists(container_client,blob_path):
    """
    Checks whether [blob_path] exists in the blob container [container_client]
    """
    
    blob_client = container_client.get_blob_client(blob_path)
    try:
        blob_client.get_blob_properties()
    except ResourceNotFoundError:
        return False
    return True
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



parallel_delete_blobs.py [41:115]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def pinit(c):
    
    global cnt
    cnt = c
    
class Counter(object):
    
    def __init__(self, total):
        # 'i' means integer
        self.val = multiprocessing.Value('i', 0)
        self.total = multiprocessing.Value('i', total)
        self.last_print = multiprocessing.Value('i', 0)

    def increment(self, n=1):
        b_print = False
        with self.val.get_lock():
            self.val.value += n
            if ((self.val.value - self.last_print.value) >= n_print):
                self.last_print.value = self.val.value
                b_print = True           
        if b_print:
            total_string = ''
            if self.total.value > 0:
                 total_string = ' of {}'.format(self.total.value)
            print('{}: iteration {}{}'.format(time.strftime("%Y-%m-%d %H:%M:%S"), 
                                                                 self.val.value,total_string),flush=True)
    @property
    def value(self):
        return self.val.value
    def last_print_value(self):
        return self.last_print.value
    
pinit(Counter(-1))


#%% Load credentials and create client objects

def get_container_client(account_name,container_name,sas_token_file):
    
    storage_account_url_blob = 'https://' + account_name + '.blob.core.windows.net'
    
    assert(os.path.isfile(sas_token_file))
    
    with open(sas_token_file) as f:
        content = f.readlines()
        content = [x.strip() for x in content] 
    
    # Not required
    # ro_sas_token = content[0]
    # assert ro_sas_token.startswith('?')
    
    rw_sas_token = content[1]    
    assert rw_sas_token.startswith('?')
    
    blob_service_client = BlobServiceClient(account_url=storage_account_url_blob, 
                                            credential=rw_sas_token)
    
    container_client = blob_service_client.get_container_client(container_name)

    return container_client
    

#%% Blob functions

def blob_exists(container_client,blob_path):
    """
    Checks whether [blob_path] exists in the blob container [container_client]
    """
    
    blob_client = container_client.get_blob_client(blob_path)
    try:
        blob_client.get_blob_properties()
    except ResourceNotFoundError:
        return False
    return True
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



