# HG changeset patch # User Magnus Schieder # Date 1537265631 -7200 # Node ID f5e1a78173cb9629c56b7a8a39d80505acb3ab6a # Parent f751499d3f8d08d458f15a19d1e22b944ebab6bf Old databases can now be read in. Added comments. diff -r f751499d3f8d -r f5e1a78173cb getan/backend.py --- a/getan/backend.py Mon Sep 17 20:41:28 2018 +0200 +++ b/getan/backend.py Tue Sep 18 12:13:51 2018 +0200 @@ -54,6 +54,18 @@ """ ] +CREATE_RECOVER = """ +CREATE TABLE IF NOT EXISTS recover( + id INTEGER PRIMARY KEY, + project_id INTEGER REFERENCES projects(id), + start_time TIMESTAMP NOT NULL, + stop_time TIMESTAMP NOT NULL, + description VARCHAR(256), + + CHECK (strftime('%s', start_time) <= strftime('%s', stop_time)) +) +""" + LOAD_ACTIVE_PROJECTS = ''' SELECT id, key, description, total FROM projects LEFT JOIN @@ -258,9 +270,14 @@ close(cur) def load_recover(self): + """If there is an entry in the recovery table, the entry is moved to + its project.""" cor = None try: cur = self.con.cursor() + # Creates the recover table if it does not exist to make old + # databases compatible. + cur.execute(CREATE_RECOVER) cur.execute(LOAD_RECOVER) recover = cur.fetchone() if not recover: diff -r f751499d3f8d -r f5e1a78173cb getan/states.py --- a/getan/states.py Mon Sep 17 20:41:28 2018 +0200 +++ b/getan/states.py Tue Sep 18 12:13:51 2018 +0200 @@ -281,6 +281,8 @@ 'running') self.controller.loop.draw_screen() self.sec = self.sec + 1 + # The time is stored every minute to be able to restore them in + # case of a crash. if self.sec % 60 == 0: self.controller.save_recovery_data() else: