diff --git a/components/sud.py b/components/sud.py index 1136499..d06bcc0 100644 --- a/components/sud.py +++ b/components/sud.py @@ -52,6 +52,7 @@ class Sud(AttributeChange): self.path = path with open(path) as f: data = json.load(f) + self._data = data (self.name, self.description, self.schedule, self.pot_mass, self.pot_material) = self._parse_data(data) @@ -87,16 +88,21 @@ class Sud(AttributeChange): self._paused_from = None def save(self): - """Returns the sud.json document currently on disk, for a client to - edit and hand back to load().""" - with open(self.path) as f: - return json.load(f) + """Returns the currently running sud.json document, for a client to + edit and hand back to load(). Purely in-memory - load() no longer + touches disk, so this is just whatever was last loaded (the file + given to __init__, or a later load()), not necessarily what's on + disk at self.path anymore.""" + return self._data def load(self, data): - """Replaces the schedule with a new sud.json document and persists - it to disk, resetting to IDLE as if freshly loaded from that file. - Refused while a brew is in progress, or if data is malformed - in - either case the current schedule is left untouched.""" + """Replaces the running schedule with a new sud.json document (kept + in memory only - never written to disk, so the file originally + configured via self.path is never touched by this), resetting to + IDLE as if freshly loaded. A client wanting to persist a schedule + does so explicitly itself, e.g. by writing save()'s result wherever + it chooses. Refused while a brew is in progress, or if data is + malformed - in either case the current schedule is left untouched.""" if self.state not in (SudState.IDLE, SudState.DONE): return False try: @@ -105,8 +111,7 @@ class Sud(AttributeChange): return False self.name, self.description, self.schedule, self.pot_mass, self.pot_material = parsed - with open(self.path, 'w') as f: - json.dump(data, f, indent='\t') + self._data = data self._reset_run_state() return True