moved sqlite code to DataStore.py
This commit is contained in:
parent
7765a7cb0b
commit
1d9f305cf9
40
DataStore.py
Normal file
40
DataStore.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
class DataStore:
|
||||||
|
def __init__(self, timedbfile):
|
||||||
|
if not os.path.exists(timedbfile):
|
||||||
|
self.createdb(timedbfile)
|
||||||
|
self.conn = sqlite3.connect(dbfile)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
def createdb(self, dbfile):
|
||||||
|
conn = sqlite3.connect(dbfile)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute('''
|
||||||
|
CREATE TABLE tasks (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT,
|
||||||
|
longname TEXT,
|
||||||
|
parent TEXT
|
||||||
|
)''')
|
||||||
|
c.execute('''
|
||||||
|
CREATE TABLE entries (
|
||||||
|
date INTEGER PRIMARY KEY,
|
||||||
|
taskid INTEGER,
|
||||||
|
hours REAL,
|
||||||
|
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
||||||
|
)''')
|
||||||
|
c.execute('''
|
||||||
|
CREATE TABLE history (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
taskid INTEGER,
|
||||||
|
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
||||||
|
)''')
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
conn.close()
|
||||||
|
|
32
dwtt
32
dwtt
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from CmdWindow import CmdWindow
|
from CmdWindow import CmdWindow
|
||||||
from Command import Command
|
from Command import Command
|
||||||
import sqlite3
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -39,35 +37,7 @@ def main(argv):
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
timedbfile = args[0]
|
timedbfile = args[0]
|
||||||
|
|
||||||
if not os.path.exists(timedbfile):
|
ds = DataStore(timedbfile)
|
||||||
createdb(timedbfile)
|
|
||||||
|
|
||||||
def createdb(dbfile):
|
|
||||||
conn = sqlite3.connect(dbfile)
|
|
||||||
c = conn.cursor()
|
|
||||||
c.execute('''
|
|
||||||
CREATE TABLE tasks (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
name TEXT,
|
|
||||||
longname TEXT,
|
|
||||||
parent TEXT
|
|
||||||
)''')
|
|
||||||
c.execute('''
|
|
||||||
CREATE TABLE entries (
|
|
||||||
date INTEGER PRIMARY KEY,
|
|
||||||
taskid INTEGER,
|
|
||||||
hours REAL,
|
|
||||||
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
|
||||||
)''')
|
|
||||||
c.execute('''
|
|
||||||
CREATE TABLE history (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
taskid INTEGER,
|
|
||||||
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
|
||||||
)''')
|
|
||||||
conn.commit()
|
|
||||||
c.close()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
def doCmdWindow():
|
def doCmdWindow():
|
||||||
c = CmdWindow()
|
c = CmdWindow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user