fixed usage of "when" sqlite keyword; made dbfile a required argument

This commit is contained in:
Josh Holtrop 2010-12-06 22:37:57 -05:00
parent 9a70a7e9f8
commit 920897cf2f

16
dwtt
View File

@ -10,32 +10,32 @@ from datetime import datetime
PROGRAM_NAME = 'dwtt' PROGRAM_NAME = 'dwtt'
def usage(): def usage():
print '''Usage: dwtt [options] print '''Usage: dwtt [options] <dbfile>
Options: Options:
-c Open a window to take a command as input -c Open a window to take a command as input
-d|--dbfile <dbfile> Use dbfile as the database file
--help Show this help --help Show this help
''' '''
def main(argv): def main(argv):
try: try:
opts, args = getopt.getopt(argv[1:], "d:c", ["help", "dbfile="]) opts, args = getopt.getopt(argv[1:], "c", ["help"])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
sys.exit(1) sys.exit(1)
timedbfile = os.path.expanduser('~/.' + PROGRAM_NAME + '.db')
timenow = datetime.now() timenow = datetime.now()
for opt, arg in opts: for opt, arg in opts:
if opt in ("-d", "--dbfile"): if opt == '-c':
timedbfile = arg
elif opt == '-c':
cmd = doCmdWindow() cmd = doCmdWindow()
print "cmd was:", cmd print "cmd was:", cmd
elif opt == "--help": elif opt == "--help":
usage() usage()
sys.exit() sys.exit()
if len(args) < 1:
usage()
sys.exit(2)
timedbfile = args[0]
if not os.path.exists(timedbfile): if not os.path.exists(timedbfile):
createdb(timedbfile) createdb(timedbfile)
@ -52,7 +52,7 @@ CREATE TABLE tasks (
)''') )''')
c.execute(''' c.execute('''
CREATE TABLE entries ( CREATE TABLE entries (
when INTEGER PRIMARY KEY, date INTEGER PRIMARY KEY,
taskid INTEGER, taskid INTEGER,
hours REAL, hours REAL,
FOREIGN KEY (taskid) REFERENCES tasks(id) FOREIGN KEY (taskid) REFERENCES tasks(id)