def upload_file( the_file_object, the_number_threads, the_printing_depth ) : a_working_dir = generate_uploading_dir( the_file_object.file_path() ) if not os.path.exists( a_working_dir ) : return True print_d( "a_working_dir = '%s'\n" % a_working_dir, the_printing_depth ) return upload_seeds( the_file_object, a_working_dir, the_number_threads, the_printing_depth + 1 )
def upload_file( the_worker_pool, the_file_path, the_file_location, the_study_object, the_upload_seed_size, the_printing_depth ) : a_working_dir = generate_uploading_dir( the_file_path ) import shutil shutil.rmtree( a_working_dir, True ) os.makedirs( a_working_dir ) print_d( "a_working_dir = '%s'\n" % a_working_dir, the_printing_depth ) a_file_dirname = os.path.dirname( the_file_path ) a_file_basename = os.path.basename( the_file_path ) import tempfile a_tmp_file = tempfile.mkstemp( dir = a_working_dir )[ 1 ] # a_tmp_file = tempfile.mkstemp()[ 1 ] # use this work arround for FAT file systems sh_command( "cd '%s' && tar -czf %s '%s'" % ( a_file_dirname, a_tmp_file, a_file_basename ), the_printing_depth ) a_statinfo = os.stat( a_tmp_file ) print_d( "a_statinfo.st_size = %d, bytes\n" % a_statinfo.st_size, the_printing_depth ) import math a_suffix_length = math.log10( float( a_statinfo.st_size ) / the_upload_seed_size ) if a_suffix_length > 0 : a_suffix_length = int( a_suffix_length + 1.0 ) else: a_suffix_length = 0 pass print_d( "a_suffix_length = %d, digits\n" % a_suffix_length, the_printing_depth ) a_file_seed_target = os.path.join( a_working_dir, a_file_basename ) sh_command( "cat '%s' | split --bytes=%d --numeric-suffixes --suffix-length=%d - %s.tgz-" % ( a_tmp_file, the_upload_seed_size, a_suffix_length, a_file_seed_target ), the_printing_depth ) a_file_pointer = open( a_tmp_file, 'rb' ) a_md5 = compute_md5( a_file_pointer ) a_hex_md5, a_base64md5 = a_md5 a_file_pointer.close() os.remove( a_tmp_file ) a_file_object = TFileObject.create( the_study_object, the_file_path, the_file_location, a_hex_md5 ) print_d( "a_file_object = %s\n" % a_file_object, the_printing_depth ) pass