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 logging 

2import os 

3from typing import List 

4from jsanctions.models import SanctionsListFile 

5 

6logger = logging.getLogger(__name__) 

7 

8 

9def delete_old_sanction_list_files(list_type: str, exclude: List[SanctionsListFile]): 

10 exclude_ids = [ex.id for ex in exclude] 

11 qs = SanctionsListFile.objects.all().filter(list_type=list_type).exclude(id__in=exclude_ids) 

12 for e in qs: 

13 assert isinstance(e, SanctionsListFile) 

14 logger.info("Deleting SanctionsListFile id=%s", e.id) 

15 if os.path.isfile(e.full_path) and not any([ex.full_path == e.full_path for ex in exclude]): 

16 os.unlink(e.full_path) 

17 logger.info("%s deleted", e.full_path) 

18 e.delete()