You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.9 KiB

1 month ago
# 引入模块
import os
import traceback
import sys
import tos
# https://panduola-cdn-xcx-dev.yingxiong.com/2h/StreamingAssets/main/pm_main.version
ak = "AKLTOTY0N2JmMDczZTdhNDNlZWE5Y2QyMTVkZmM5ZjU1ZDA"
sk = "TjJFNE5qZ3hNR0ZqWlRJME5EUXpZMkk0T1dRelpHSmlaREptWXpJeU56UQ=="
endpoint = "tos-cn-beijing.volces.com"
region = "cn-beijing"
bucket_name = "huoliqiang"
current_directory = os.getcwd().replace("\\", "/")
client = tos.TosClientV2(ak, sk, endpoint, region)
def upload_file(bucketName, objectKey, file_path):
try:
print(f"To Cdn path is {objectKey}")
tosClient.put_object_from_file(bucketName, objectKey, file_path)
print(f"文件上传成功: {file_path}")
return True
except tos.exceptions.TosClientError as e:
# Operation failed, catch client error, usually caused by invalid request parameters or network issues
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
return False
except tos.exceptions.TosServerError as e:
# Operation failed, catch server error, detailed error information can be obtained from the response
print('fail with server error, code: {}'.format(e.code))
# request id can be used to locate specific issues, it is strongly recommended to save it in the log.
print('error with request id: {}'.format(e.request_id))
print('error with message: {}'.format(e.message))
print('error with http code: {}'.format(e.status_code))
print('error with ec: {}'.format(e.ec))
print('error with request url: {}'.format(e.request_url))
return False
except Exception as e:
print('fail with unknown error: {}'.format(e))
return False
CdnMainPath = "ffdTestPiplineCdn/{}"
def list_files(startpath, mdict):
success_count = 0
with os.scandir(startpath) as entries:
for entry in entries:
if entry.is_file():
log(os.path.join(startpath, entry))
if upload_file(bucket_name, CdnMainPath.format(entry.name), entry.path):
success_count += 1
else:
if upload_file(bucket_name, CdnMainPath.format(entry.name), entry.path):
success_count += 1
else:
log(f"upload {entry.name} failed")
sys.exit(1)
print(f"上传成功: {success_count}")
def log(*str):
print(*str, flush=True)
# 构建版本如jp
Version = ""
WasmPath = ""
if __name__ == '__main__':
Version = sys.argv[1] # 版本
WasmPath = sys.argv[2] # 版本
CdnPath = sys.argv[3] # 版本
CdnMainPath = f"{CdnPath}/{{}}"
# 输出版本
log(f"upload wasm of version {Version} to {CdnPath}")
my_dict = {}
folder = f'{WasmPath}/webgl/'
tosClient = tos.TosClientV2(ak, sk, endpoint, region)
log(f"folder is {folder}")
list_files(folder, my_dict)
log(f"upload wasm done")
tosClient.close()