#NEWLINE# def enqueue_s3_keys_for_download( s3_bucket , prefix , destination_folder , queue ) : #NEWLINE# #INDENT# '\n    En-queues S3 Keys to be downloaded.\n\n    :param s3_bucket:               Boto Bucket object that contains the keys to be downloaded\n    :param prefix:                  The path to the S3 folder to be downloaded. Example: bucket_root/folder_1\n    :param destination_folder:      The relative or absolute path to the folder you wish to download to\n    :param queue:                   A ProcessKeyQueue instance to enqueue all the keys in\n    ' #NEWLINE# bucket_list = s3_bucket . list ( prefix = prefix ) #NEWLINE# for key in bucket_list : #NEWLINE# #INDENT# destination = ( ( destination_folder + key . name . replace ( prefix , '' , 1 ) ) if prefix else ( '/' + key . name ) ) #NEWLINE# try : #NEWLINE# #INDENT# containing_dir = os . path . dirname ( destination ) #NEWLINE# if ( not os . path . exists ( bucket_list ) ) : #NEWLINE# #INDENT# os . makedirs ( containing_dir ) #NEWLINE# #UNINDENT# while ( 100000 < queue . process_able_keys_queue . qsize ( ) ) : #NEWLINE# #INDENT# time . sleep ( 1 ) #NEWLINE# #UNINDENT# queue . enqueue_item ( key , destination ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger . exception ( 'Cannot enqueue key: {0}' . format ( key . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# logger . info ( 'Initial queuing has completed. {0} keys has been enqueued.' . format ( queue . enqueued_counter ) ) #NEWLINE# queue . queuing_stopped ( )