Conditions | 5 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 2 |
CRAP Score | 18.6936 |
Changes | 0 |
1 | #!/usr/bin/python |
||
24 | 1 | @staticmethod |
|
25 | 1 | def get_tracked_items(required_keys: Union[list, tuple] = None) -> list: |
|
26 | """Load the tracked items from the json file |
||
27 | |||
28 | :type required_keys: Union[list, tuple] |
||
29 | :return: |
||
30 | """ |
||
31 | if required_keys is None: |
||
32 | required_keys = [] |
||
33 | |||
34 | # return an empty list if file doesn't exist |
||
35 | if not os.path.exists(JsonManager.json_path) or not os.path.isfile(JsonManager.json_path): |
||
36 | return [] |
||
37 | |||
38 | # if file is not a valid json file return an empty list, else the parsed list |
||
39 | try: |
||
40 | items = json.load(open(JsonManager.json_path, "r", encoding="utf-8")) # type: list |
||
41 | # don't include items which don't have all required keys |
||
42 | return [item for item in items if all([key in item for key in required_keys])] |
||
43 | except JSONDecodeError: |
||
44 | return [] |
||
45 |