Update server.py
Browse files
server.py
CHANGED
|
@@ -154,56 +154,60 @@ def update_last_uploaded_size(size):
|
|
| 154 |
last_uploaded_size = size
|
| 155 |
|
| 156 |
def compress_folder():
|
| 157 |
-
global last_uploaded_size
|
| 158 |
-
|
| 159 |
-
# 清理并创建目录
|
| 160 |
if os.path.exists('/a'):
|
| 161 |
-
|
| 162 |
-
|
| 163 |
os.makedirs('/a', exist_ok=True)
|
| 164 |
|
| 165 |
-
with lock: #
|
|
|
|
| 166 |
if os.path.exists(zip_file_path):
|
| 167 |
print(f"压缩文件 {zip_file_path} 已存在,跳过本次压缩。")
|
| 168 |
return
|
|
|
|
| 169 |
print('开始压缩数据')
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
| 174 |
print(f"Data compressed into {zip_file_path}")
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
| 178 |
if file_size < (1024 ** 3):
|
| 179 |
print("文件小于1GB,不进行上传。")
|
| 180 |
return
|
|
|
|
| 181 |
if last_uploaded_size == -1 or file_size > last_uploaded_size:
|
| 182 |
-
|
| 183 |
-
# 判断是否为首次运行或上次上传大小为0
|
| 184 |
if last_uploaded_size == -1:
|
| 185 |
print("首次运行,正在执行上传...")
|
| 186 |
-
update_last_uploaded_size(file_size)
|
| 187 |
|
| 188 |
with open(metadata_file_path, 'w') as json_fid:
|
| 189 |
json.dump(kaggle_metadata, json_fid)
|
| 190 |
|
| 191 |
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
| 192 |
last_uploaded_size = file_size
|
| 193 |
-
|
| 194 |
elif file_size > last_uploaded_size:
|
| 195 |
-
print(f"新文件 {
|
| 196 |
-
update_last_uploaded_size(file_size)
|
| 197 |
|
| 198 |
with open(metadata_file_path, 'w') as json_fid:
|
| 199 |
json.dump(kaggle_metadata, json_fid)
|
| 200 |
|
| 201 |
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
| 202 |
last_uploaded_size = file_size
|
| 203 |
-
|
| 204 |
else:
|
| 205 |
-
print(f"新文件 {
|
| 206 |
-
|
| 207 |
|
| 208 |
def repeat_task():
|
| 209 |
print('------打包线程启动-------------')
|
|
@@ -403,13 +407,12 @@ def SillyTavern():
|
|
| 403 |
# ]
|
| 404 |
# run_commands(commands)
|
| 405 |
# SillyTavern()
|
| 406 |
-
threading.Thread(target=SillyTavern, daemon=True).start()
|
| 407 |
-
check_api1()
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
frp(config_data2,'/content/frp/frpc2.ini',True)
|
| 414 |
-
frp(config_data,'/content/frp/frpc.ini',False)
|
| 415 |
# sync()
|
|
|
|
|
|
| 154 |
last_uploaded_size = size
|
| 155 |
|
| 156 |
def compress_folder():
|
| 157 |
+
global last_uploaded_size
|
| 158 |
+
|
| 159 |
+
# 清理并创建目录 /a
|
| 160 |
if os.path.exists('/a'):
|
| 161 |
+
shutil.rmtree('/a') # 更安全地删除目录
|
| 162 |
+
|
| 163 |
os.makedirs('/a', exist_ok=True)
|
| 164 |
|
| 165 |
+
with lock: # 使用锁以防止多线程冲突
|
| 166 |
+
|
| 167 |
if os.path.exists(zip_file_path):
|
| 168 |
print(f"压缩文件 {zip_file_path} 已存在,跳过本次压缩。")
|
| 169 |
return
|
| 170 |
+
|
| 171 |
print('开始压缩数据')
|
| 172 |
+
|
| 173 |
+
result = subprocess.run(['7z', 'a','-mcp=GBK', '-tzip', '-mx=1','-mmt=2', zip_file_path, data_folder])
|
| 174 |
+
|
| 175 |
+
if result.returncode != 0:
|
| 176 |
+
print("压缩失败,请检查7z命令是否正确")
|
| 177 |
+
return
|
| 178 |
+
|
| 179 |
print(f"Data compressed into {zip_file_path}")
|
| 180 |
+
|
| 181 |
+
file_size = os.path.getsize(zip_file_path) # 获取压缩包的大小
|
| 182 |
+
print('文件大小:', file_size, '上次文件大小:', last_uploaded_size)
|
| 183 |
+
|
| 184 |
if file_size < (1024 ** 3):
|
| 185 |
print("文件小于1GB,不进行上传。")
|
| 186 |
return
|
| 187 |
+
|
| 188 |
if last_uploaded_size == -1 or file_size > last_uploaded_size:
|
|
|
|
|
|
|
| 189 |
if last_uploaded_size == -1:
|
| 190 |
print("首次运行,正在执行上传...")
|
| 191 |
+
update_last_uploaded_size(file_size)
|
| 192 |
|
| 193 |
with open(metadata_file_path, 'w') as json_fid:
|
| 194 |
json.dump(kaggle_metadata, json_fid)
|
| 195 |
|
| 196 |
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
| 197 |
last_uploaded_size = file_size
|
| 198 |
+
|
| 199 |
elif file_size > last_uploaded_size:
|
| 200 |
+
print(f"新文件 {zip_file_path} 大于上次上传的大小,正在执行上传...")
|
| 201 |
+
update_last_uploaded_size(file_size)
|
| 202 |
|
| 203 |
with open(metadata_file_path, 'w') as json_fid:
|
| 204 |
json.dump(kaggle_metadata, json_fid)
|
| 205 |
|
| 206 |
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
| 207 |
last_uploaded_size = file_size
|
| 208 |
+
|
| 209 |
else:
|
| 210 |
+
print(f"新文件 {zip_file_path} 不大于上次上传的大小,跳过")
|
|
|
|
| 211 |
|
| 212 |
def repeat_task():
|
| 213 |
print('------打包线程启动-------------')
|
|
|
|
| 407 |
# ]
|
| 408 |
# run_commands(commands)
|
| 409 |
# SillyTavern()
|
| 410 |
+
# threading.Thread(target=SillyTavern, daemon=True).start()
|
| 411 |
+
# check_api1()
|
| 412 |
+
# threading.Thread(target=repeat_task, daemon=True).start() #压缩备份
|
| 413 |
+
# print("开始衔接")
|
| 414 |
+
# Service_status = True
|
| 415 |
+
# frp(config_data2,'/content/frp/frpc2.ini',True)
|
| 416 |
+
# frp(config_data,'/content/frp/frpc.ini',False)
|
|
|
|
|
|
|
| 417 |
# sync()
|
| 418 |
+
compress_folder()
|