diff --git a/publish_scripts/PypiIndexUpdate.py b/publish_scripts/PypiIndexUpdate.py index 054be8e482..46d0d122f0 100644 --- a/publish_scripts/PypiIndexUpdate.py +++ b/publish_scripts/PypiIndexUpdate.py @@ -15,6 +15,12 @@ from baidubce.services.bos.bos_client import BosClient +def _get_put_super_object_from_file(bos_client): + """Return the multipart upload method supported by the installed BCE SDK.""" + if hasattr(bos_client, "put_super_object_from_file"): + return bos_client.put_super_object_from_file + return bos_client.put_super_obejct_from_file + def VersionVerification(): """ @@ -94,7 +100,7 @@ def upload2bos(bucket_name, file_name): linux_path = path.as_posix() object_key = linux_path - result = bos_client.put_super_obejct_from_file( + result = _get_put_super_object_from_file(bos_client)( bucket_name, object_key, file_name, chunk_size=100, thread_num=multiprocessing.cpu_count() ) if result: diff --git a/tools/bos_tools.py b/tools/bos_tools.py index 0a2b0aedde..c345fdd5e2 100644 --- a/tools/bos_tools.py +++ b/tools/bos_tools.py @@ -22,13 +22,22 @@ config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint=bos_host) bos_client = BosClient(config) + +def _get_put_super_object_from_file(bos_client): + """Return the multipart upload method supported by the installed BCE SDK.""" + if hasattr(bos_client, "put_super_object_from_file"): + return bos_client.put_super_object_from_file + return bos_client.put_super_obejct_from_file + + def bos_upload(bucket_name, object_key, file_name): - result = bos_client.put_super_obejct_from_file( + result = _get_put_super_object_from_file(bos_client)( bucket_name, object_key, file_name, chunk_size=100, thread_num=multiprocessing.cpu_count() ) if result: print("Upload success!") + def bos_download_url(bucket_name, object_key): # 建议使用0.9.29版本的bce-python-sdk print("Please ensure you are using bce-python-sdk version 0.9.29 or later.") diff --git a/tools/bos_upload.py b/tools/bos_upload.py index 94673e3926..b3cecac9ca 100644 --- a/tools/bos_upload.py +++ b/tools/bos_upload.py @@ -16,6 +16,13 @@ from baidubce.services.bos.bos_client import BosClient +def _get_put_super_object_from_file(bos_client): + """Return the multipart upload method supported by the installed BCE SDK.""" + if hasattr(bos_client, "put_super_object_from_file"): + return bos_client.put_super_object_from_file + return bos_client.put_super_obejct_from_file + + # 设置BosClient的Host,Access Key ID和Secret Access Key bos_host = "bj.bcebos.com" access_key_id = os.getenv("AK") @@ -37,7 +44,7 @@ else: chunk_size = 100 -result = bos_client.put_super_obejct_from_file( +result = _get_put_super_object_from_file(bos_client)( bucket_name, object_key, file_name, chunk_size=100, thread_num=multiprocessing.cpu_count() ) if result: