From eb1ca1fae7c2747ffb40fce2acdd7054a98cd78d Mon Sep 17 00:00:00 2001 From: shoulinwei Date: Wed, 1 Jan 2025 14:37:53 +0800 Subject: [PATCH] local_file check --- csst_dfs_client/level1.py | 6 ++++-- csst_dfs_client/level2.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/csst_dfs_client/level1.py b/csst_dfs_client/level1.py index b92b01d..cc60670 100644 --- a/csst_dfs_client/level1.py +++ b/csst_dfs_client/level1.py @@ -152,7 +152,7 @@ def update_prc_status(level1_id: str, file_type: str, prc_status: int, batch_id: """ return request.put(f"/api/level1/prc_status/{level1_id}", {'file_type': file_type, 'prc_status': prc_status, 'batch_id': batch_id}) -def write(local_file: Union[IO | str], +def write(local_file: Union[IO, str], module_id: Literal['MSC', 'IFS', 'MCI', 'HSTDM', 'CPIC'], level0_id: Optional[str | None], level1_id: Optional[str | None], @@ -168,7 +168,7 @@ def write(local_file: Union[IO | str], 将本地的1级数据文件写入到DFS中其他参数如rss_id, cube_id等,可通过extra_kwargs传入 Args: - local_file (Union[IO | str]): 文件路径或文件对象 + local_file (Union[IO, str]): 文件路径或文件对象 module_id ['MSC', 'IFS', 'MCI', 'HSTDM', 'CPIC']其中一个,代表: 模块ID level0_id (Optional[str | None]): 0级数据的ID默认为 None level1_id (Optional[str | None]): 1级数据的ID默认为 None @@ -199,6 +199,8 @@ def write(local_file: Union[IO | str], if not dataset or not batch_id: raise ValueError("dataset and batch_id is required") params.update(extra_kwargs) + if local_file is None: + raise ValueError("local_file is required") if isinstance(local_file, str): if not os.path.exists(local_file): raise FileNotFoundError(local_file) diff --git a/csst_dfs_client/level2.py b/csst_dfs_client/level2.py index b506ae1..af21f82 100644 --- a/csst_dfs_client/level2.py +++ b/csst_dfs_client/level2.py @@ -145,7 +145,7 @@ def update_prc_status_by_file_name(file_name: str, prc_status: int, batch_id: st """ return request.put(f"/api/level2/prc_status/file/{file_name}", {'prc_status': prc_status, 'batch_id': batch_id}) -def write(local_file: Union[IO | str], +def write(local_file: Union[IO, str], module_id: Literal['MSC', 'IFS', 'MCI', 'HSTDM', 'CPIC'], level0_id: Optional[str | None], level1_id: Optional[str | None], @@ -194,7 +194,9 @@ def write(local_file: Union[IO | str], 'dataset': dataset, 'batch_id': batch_id } - params.update(extra_kwargs) + params.update(extra_kwargs) + if local_file is None: + raise ValueError("local_file is required") if isinstance(local_file, str): if not os.path.exists(local_file): raise FileNotFoundError(local_file) -- GitLab