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