dwtt/dwtt
2010-12-02 17:59:11 -05:00

56 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
from CmdWindow import CmdWindow
import sqlite3
import os
import sys
import getopt
from datetime import datetime
PROGRAM_NAME = 'dwtt'
def usage():
print '''Usage: dwtt [options]
Options:
-c Open a window to take a command as input
-d|--dbfile <dbfile> Use dbfile as the database file
--help Show this help
'''
def main(argv):
try:
opts, args = getopt.getopt(argv[1:], "d:c", ["help", "dbfile="])
except getopt.GetoptError:
usage()
sys.exit(1)
timedbfile = os.path.expanduser('~/.' + PROGRAM_NAME + '.db')
for opt, arg in opts:
if opt in ("-d", "--dbfile"):
timedbfile = arg
elif opt == '-c':
cmd = doCmdWindow()
elif opt == "--help":
usage()
sys.exit()
if not os.path.exists(timedbfile):
createdb(timedbfile)
def createdb(dbfile):
conn = sqlite3.connect(dbfile)
c = conn.cursor()
c.execute('''CREATE TABLE projects (name TEXT UNIQUE)''')
c.execute('''CREATE TABLE aliases (name TEXT UNIQUE, project TEXT)''')
conn.commit()
c.close()
conn.close()
def doCmdWindow():
c = CmdWindow()
c.main()
if __name__ == "__main__":
main(sys.argv)