Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import re 

2from datetime import datetime 

3 

4from sdc_etl_libs.sdc_filetransfer.utils.delete_files_mechanism.DeleteCriteria import \ 

5 DeleteCriteria 

6 

7 

8class FilenameMatchDeleteCriteria(DeleteCriteria): 

9 

10 def __init__(self, file_name=None, file_regex=None): 

11 self.file_match_criteria = file_regex \ 

12 if file_name is None and file_regex else file_name 

13 

14 def get_files_to_delete(self, files): 

15 """ 

16 Filter files to be deleted whose filename matches a 

17 predefined file_name or file_regex. 

18 :param files: List of sftp files 

19 :type files: List(SFTPAttributes) 

20 :return: list of filtered SFTPAttributes objects 

21 :rtype: List(SFTPAttributes) 

22 """ 

23 return [file for file in files if re.search(self.file_match_criteria, file.filename)]