minimal working db

This commit is contained in:
Dominik Demuth
2023-12-31 15:46:14 +01:00
parent 5ad6456b16
commit 3b19f421ef
4 changed files with 84 additions and 9 deletions

63
src/gui_qt/lib/backup.py Normal file
View File

@@ -0,0 +1,63 @@
import os
import sqlite3
from ..Qt import QtCore
DB_FILE = '/autohome/dominik/nmreval/nmreval.db'
class Backup(QtCore.QObject):
def __init__(self):
super().__init__()
self.create_table()
self._pid = None
def create_table(self):
con = sqlite3.connect(DB_FILE)
con.execute(
"CREATE TABLE IF NOT EXISTS sessions (pid INTEGER NOT NULL, backup_file TEXT NOT NULL );"
)
def create_entry(self, pid: int):
con = sqlite3.connect(DB_FILE)
con.execute('INSERT INTO sessions VALUES(?, ?);',
(pid, f'/autohome/dominik/nmreval/tmp_{pid}.nmr'))
con.commit()
con.close()
self._pid = pid
return
def remove_entry(self, pid: int = None):
if pid is None:
pid = self._pid
con = sqlite3.connect(DB_FILE)
cursor = con.execute('DELETE FROM sessions WHERE pid = ?;', (pid,))
res = cursor.execute('SELECT COUNT(sessions.pid) FROM sessions GROUP BY sessions.pid;')
con.commit()
print(res.fetchall())
con.close()
def close(self):
self.remove_entry()
def search_unsaved(self):
con = sqlite3.connect(DB_FILE)
cursor = con.cursor()
res = cursor.execute('SELECT sessions.pid, sessions.backup_file FROM sessions;')
con.commit()
data = res.fetchall()
con.close()
missing_processes = []
for pid, fname in data:
try:
os.kill(pid, 0)
except ProcessLookupError:
missing_processes.append((pid, fname))
return missing_processes