22import logging
33import shutil
44import sys
5- import typing
65from abc import ABC , abstractmethod
76from contextlib import closing
87from pathlib import Path
8+ from typing import Any , List , Optional
99
1010from clp_py_utils .clp_config import Database
1111from clp_py_utils .clp_metadata_db_utils import (
3535
3636
3737class DeleteHandler (ABC ):
38- def __init__ (self , query_params : typing . List [str ]):
39- self ._params : typing . List [str ] = query_params
38+ def __init__ (self , query_params : List [str ]):
39+ self ._params : List [str ] = query_params
4040
41- def get_params (self ) -> typing . List [str ]:
41+ def get_params (self ) -> List [str ]:
4242 return self ._params
4343
4444 @abstractmethod
@@ -48,7 +48,7 @@ def get_criteria(self) -> str: ...
4848 def get_not_found_message (self ) -> str : ...
4949
5050 @abstractmethod
51- def validate_results (self , archive_ids : typing . List [str ]) -> None : ...
51+ def validate_results (self , archive_ids : List [str ]) -> None : ...
5252
5353
5454class FilterDeleteHandler (DeleteHandler ):
@@ -58,7 +58,7 @@ def get_criteria(self) -> str:
5858 def get_not_found_message (self ) -> str :
5959 return "No archives found within the specified time range."
6060
61- def validate_results (self , archive_ids : typing . List [str ]) -> None :
61+ def validate_results (self , archive_ids : List [str ]) -> None :
6262 pass
6363
6464
@@ -70,7 +70,7 @@ def get_criteria(self) -> str:
7070 def get_not_found_message (self ) -> str :
7171 return "No archives found with matching IDs."
7272
73- def validate_results (self , archive_ids : typing . List [str ]) -> None :
73+ def validate_results (self , archive_ids : List [str ]) -> None :
7474 not_found_ids : set [str ] = set (self ._params ) - set (archive_ids )
7575 if not_found_ids :
7676 logger .warning (
@@ -81,7 +81,7 @@ def validate_results(self, archive_ids: typing.List[str]) -> None:
8181 )
8282
8383
84- def main (argv : typing . List [str ]) -> int :
84+ def main (argv : List [str ]) -> int :
8585 clp_home : Path = get_clp_home ()
8686 default_config_file_path : Path = clp_home / CLP_DEFAULT_CONFIG_FILE_RELATIVE_PATH
8787
@@ -253,9 +253,9 @@ def main(argv: typing.List[str]) -> int:
253253def _find_archives (
254254 archives_dir : Path ,
255255 database_config : Database ,
256- dataset : typing . Optional [str ],
256+ dataset : Optional [str ],
257257 begin_ts : int ,
258- end_ts : int = typing . Optional [ int ] ,
258+ end_ts : int ,
259259) -> int :
260260 """
261261 Lists all archive IDs, if begin_ts and end_ts are provided, only lists archives where
@@ -267,20 +267,20 @@ def _find_archives(
267267 :param end_ts:
268268 :return: 0 on success, 1 on failure.
269269 """
270- archive_ids : typing . List [str ]
270+ archive_ids : List [str ]
271271 dataset_specific_message = f" of dataset `{ dataset } `" if dataset is not None else ""
272272 logger .info (f"Starting to find archives{ dataset_specific_message } from the database." )
273273 try :
274274 sql_adapter : SQL_Adapter = SQL_Adapter (database_config )
275- clp_db_connection_params : dict [str , any ] = (
275+ clp_db_connection_params : dict [str , Any ] = (
276276 database_config .get_clp_connection_params_and_type (True )
277277 )
278278 table_prefix : str = clp_db_connection_params ["table_prefix" ]
279279
280280 with closing (sql_adapter .create_connection (True )) as db_conn , closing (
281281 db_conn .cursor (dictionary = True )
282282 ) as db_cursor :
283- query_params : typing . List [int ] = [begin_ts ]
283+ query_params : List [int ] = [begin_ts ]
284284 query : str = (
285285 f"""
286286 SELECT id FROM `{ get_archives_table_name (table_prefix , dataset )} `
@@ -294,7 +294,7 @@ def _find_archives(
294294 db_cursor .execute (query , query_params )
295295 results = db_cursor .fetchall ()
296296
297- archive_ids : typing . List [str ] = [result ["id" ] for result in results ]
297+ archive_ids : List [str ] = [result ["id" ] for result in results ]
298298 if 0 == len (archive_ids ):
299299 logger .info ("No archives found within specified time range." )
300300 return 0
@@ -318,7 +318,7 @@ def _find_archives(
318318def _delete_archives (
319319 archives_dir : Path ,
320320 database_config : Database ,
321- dataset : typing . Optional [str ],
321+ dataset : Optional [str ],
322322 delete_handler : DeleteHandler ,
323323 dry_run : bool = False ,
324324) -> int :
@@ -333,11 +333,11 @@ def _delete_archives(
333333 :return: 0 on success, -1 otherwise.
334334 """
335335
336- archive_ids : typing . List [str ]
336+ archive_ids : List [str ]
337337 dataset_specific_message = f" of dataset `{ dataset } `" if dataset is not None else ""
338338 logger .info (f"Starting to delete archives{ dataset_specific_message } from the database." )
339339 sql_adapter : SQL_Adapter = SQL_Adapter (database_config )
340- clp_db_connection_params : dict [str , any ] = database_config .get_clp_connection_params_and_type (
340+ clp_db_connection_params : dict [str , Any ] = database_config .get_clp_connection_params_and_type (
341341 True
342342 )
343343 table_prefix = clp_db_connection_params ["table_prefix" ]
@@ -350,7 +350,7 @@ def _delete_archives(
350350 logger .info ("Running in dry-run mode." )
351351
352352 query_criteria : str = delete_handler .get_criteria ()
353- query_params : typing . List [str ] = delete_handler .get_params ()
353+ query_params : List [str ] = delete_handler .get_params ()
354354
355355 db_cursor .execute (
356356 f"""
@@ -365,7 +365,7 @@ def _delete_archives(
365365 logger .info (delete_handler .get_not_found_message ())
366366 return 0
367367
368- archive_ids : typing . List [str ] = [result ["id" ] for result in results ]
368+ archive_ids : List [str ] = [result ["id" ] for result in results ]
369369 delete_handler .validate_results (archive_ids )
370370
371371 delete_archives_from_metadata_db (db_cursor , archive_ids , table_prefix , dataset )
0 commit comments