优化代码
This commit is contained in:
parent
05df024ddc
commit
c27ff27f9e
@ -17,6 +17,7 @@ FILE_DIR = os.path.dirname(__file__)
|
||||
# home = os.path.join(BASE_DIR, "/unstructured_data/remote_sensing_data")
|
||||
home = "/unstructured_data/remote_sensing_data"
|
||||
|
||||
|
||||
# 定义一个函数,计算进度条
|
||||
def bar(num=1, sum=100):
|
||||
rate = float(num) / float(sum)
|
||||
@ -24,6 +25,7 @@ def bar(num=1, sum=100):
|
||||
temp = '\r%d %%' % (rate_num)
|
||||
sys.stdout.write(temp)
|
||||
|
||||
|
||||
def md5_file(name):
|
||||
m = md5()
|
||||
a_file = open(name, 'rb') # 需要使用二进制格式读取文件内容
|
||||
@ -55,16 +57,10 @@ def upload_file_client(file_path, depth, dateTime, collectionCode):
|
||||
result_exist = str(ck.recv(1024), encoding='utf-8')
|
||||
has_sent = 0
|
||||
if result_exist == "2003":
|
||||
# inp = input("文件已存在,是否续传?Y/N:").strip()
|
||||
# if inp.upper() == 'Y':
|
||||
ck.sendall(bytes("2004", encoding='utf-8'))
|
||||
result_continue_pos = str(ck.recv(1024), encoding='utf-8') # 已经传输了多少的文件内容
|
||||
print(result_continue_pos)
|
||||
has_sent = int(result_continue_pos)
|
||||
|
||||
# else:
|
||||
# ck.sendall(bytes("2005", encoding='utf-8')) #发送2005代表不续传
|
||||
|
||||
file_obj = open(file_path, 'rb') # 对文件进行读操作
|
||||
file_obj.seek(has_sent) # 调整指针
|
||||
|
||||
@ -76,5 +72,6 @@ def upload_file_client(file_path, depth, dateTime, collectionCode):
|
||||
|
||||
file_obj.close()
|
||||
print("文件上传成功!")
|
||||
uc = {'file_size': file_byte_size, 'fileName': file_name, 'md5': md5, 'file_path': file_paths+'/'+file_name, 'type': 'ok'}
|
||||
uc = {'file_size': file_byte_size, 'fileName': file_name, 'md5': md5, 'file_path': file_paths + '/' + file_name,
|
||||
'type': 'ok'}
|
||||
return uc
|
||||
|
Loading…
Reference in New Issue
Block a user