moved sqlite code to DataStore.py

This commit is contained in:
Josh Holtrop 2010-12-26 22:09:23 -05:00
parent 7765a7cb0b
commit 1d9f305cf9
2 changed files with 41 additions and 31 deletions

40
DataStore.py Normal file
View 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
View File

@ -2,8 +2,6 @@
from CmdWindow import CmdWindow
from Command import Command
import sqlite3
import os
import sys
import getopt
from datetime import datetime
@ -39,35 +37,7 @@ def main(argv):
sys.exit(2)
timedbfile = args[0]
if not os.path.exists(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()
ds = DataStore(timedbfile)
def doCmdWindow():
c = CmdWindow()