Ejemplo n.º 1
0
def entry_point( the_study_object, the_output_dir, the_located_files = None, 
                 the_number_threads = 3, the_wait = True, the_remove = False, the_fresh = False, the_callback = None ) :
    a_spent_time = Timer()
    
    if the_output_dir == None :
        the_output_dir = os.path.join( os.curdir, the_study_object.name() )
        pass

    if the_located_files == None :
        download_files( the_study_object, the_output_dir,
                        the_number_threads, the_wait, the_remove, the_fresh, the_callback )
    else :
        a_worker_pool = TaggedWorkerPool( the_number_threads )
        
        for a_located_file in the_located_files :
            a_worker_pool.charge( a_located_file, file_entry_point, 
                                  ( the_study_object, the_output_dir, a_located_file, 
                                    the_number_threads, the_wait, the_remove, the_fresh, the_callback ) )
            pass
    
        a_worker_pool.shutdown()
        a_worker_pool.join()
        pass
    
    print_d( "a_spent_time = %s, sec\n" % a_spent_time )

    return the_study_object
Ejemplo n.º 2
0
def download_files( the_study_object, the_output_dir, the_number_threads, the_wait, the_remove, the_fresh, the_callback ) :
    a_worker_pool = TaggedWorkerPool( the_number_threads )

    if the_wait == False or the_study_object.sealed() :
        for a_file_object in the_study_object :
            a_worker_pool.charge( a_file_object.located_file(), download_file, 
                                  ( a_file_object, the_output_dir, the_number_threads, the_remove, the_fresh, the_callback ) )
            pass

        a_worker_pool.shutdown()
        a_worker_pool.join()
    else:
        print_d( "waiting ", 0 )

        while True :
            an_sealed = the_study_object.sealed()

            for a_file_object in the_study_object :
                a_worker_pool.charge( a_file_object.located_file(), download_file, 
                                      ( a_file_object, the_output_dir, the_number_threads, the_remove, the_fresh, the_callback ) )
                pass

            if an_sealed :
                break

            print_d( "." )
            pass

        a_worker_pool.shutdown()
        a_worker_pool.join()
        
        print_d( " compleated\n", 0 )
        return
    
    if the_remove == True :
        the_study_object.delete( the_number_threads, 0 )
        pass

    pass