Skip to content
Snippets Groups Projects
Commit 8d42cb92 authored by David Trattnig's avatar David Trattnig
Browse files

style: improve json file layout

parent a5050850
Branches
Tags
1 merge request!35ORM-less scheduling
Pipeline #7763 passed
...@@ -56,6 +56,7 @@ class TimetableService: ...@@ -56,6 +56,7 @@ class TimetableService:
last_successful_fetch: datetime = None last_successful_fetch: datetime = None
cache_location: str = None cache_location: str = None
timetable_file: str = None timetable_file: str = None
restorable: bool
def __init__(self, cache_location: str): def __init__(self, cache_location: str):
""" """
...@@ -66,7 +67,7 @@ class TimetableService: ...@@ -66,7 +67,7 @@ class TimetableService:
""" """
self.config = AuraConfig.instance.config self.config = AuraConfig.instance.config
self.logger = logging.getLogger("engine") self.logger = logging.getLogger("engine")
jsonpickle.set_encoder_options("json", sort_keys=True, indent=4) jsonpickle.set_encoder_options("json", sort_keys=False, indent=2)
if cache_location[-1] != "/": if cache_location[-1] != "/":
cache_location += "/" cache_location += "/"
...@@ -74,6 +75,7 @@ class TimetableService: ...@@ -74,6 +75,7 @@ class TimetableService:
os.makedirs(cache_location, exist_ok=True) os.makedirs(cache_location, exist_ok=True)
self.cache_location = cache_location self.cache_location = cache_location
self.timetable_file = self.cache_location + "/timetable.json" self.timetable_file = self.cache_location + "/timetable.json"
self.restorable = False
@synchronized @synchronized
def refresh(self): def refresh(self):
...@@ -125,7 +127,7 @@ class TimetableService: ...@@ -125,7 +127,7 @@ class TimetableService:
""" """
try: try:
with open(self.timetable_file, "w") as file: with open(self.timetable_file, "w") as file:
file.write(jsonpickle.encode(self.timetable)) file.write(jsonpickle.encode(self.timetable, unpicklable=self.restorable))
self.logger.info(SU.green("timetable.json stored")) self.logger.info(SU.green("timetable.json stored"))
except Exception as e: except Exception as e:
self.logger.error(SU.red(f"Error while storing {self.timetable_file}"), e) self.logger.error(SU.red(f"Error while storing {self.timetable_file}"), e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment