Coverage for jsanctions/services.py: 0%

# Coverage for jsanctions/services.py : 0%

## 15 statements

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

1 import logging

2 import os

3 from typing import List

4 from jsanctions.models import SanctionsListFile

5

6 logger = logging.getLogger(__name__)

7

8

9 def 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()