added cheap status handler, printing to console

This commit is contained in:
Josh Holtrop 2011-01-03 13:45:56 -05:00
parent 8dac698ca2
commit b8d96c8b5a
2 changed files with 40 additions and 2 deletions

View File

@ -17,6 +17,12 @@ class TaskRef:
self.taskid = taskid self.taskid = taskid
self.time = time self.time = time
class Entry:
def __init__(self, date, seconds, taskid):
self.date = date
self.seconds = seconds
self.taskid = taskid
class DataStore: class DataStore:
def __init__(self, dbfile): def __init__(self, dbfile):
if not os.path.exists(dbfile): if not os.path.exists(dbfile):
@ -186,7 +192,7 @@ WHERE name = ?
parenttask = self.getTaskByID(task.parentid) parenttask = self.getTaskByID(task.parentid)
if parenttask is not None: if parenttask is not None:
parentpath = self.getTaskPath(parenttask) parentpath = self.getTaskPath(parenttask)
path = parentpath + ' : ' + path path = parentpath + ':' + path
return path return path
def createTask(self, name, longname, parentid): def createTask(self, name, longname, parentid):
@ -244,3 +250,18 @@ VALUES(?, ?, ?)
''', (date, taskid, seconds)) ''', (date, taskid, seconds))
c.close() c.close()
self.conn.commit() self.conn.commit()
def getEntriesInDateRange(self, date1, date2):
entries = []
c = self.conn.cursor()
c.execute('''
SELECT date, seconds, taskid
FROM entries
WHERE date >= ? AND date <= ?
ORDER BY taskid, date
''', (date1.strftime('%Y-%m-%d'), date2.strftime('%Y-%m-%d')))
for row in c:
entries.append(Entry(*row))
c.close()
self.conn.commit()
return entries

19
dwtt
View File

@ -3,6 +3,7 @@
import os import os
import sys import sys
import getopt import getopt
from datetime import datetime, timedelta
from CmdWindow import CmdWindow from CmdWindow import CmdWindow
from Command import Command from Command import Command
@ -105,10 +106,26 @@ def processTask(cmd, store):
store.createTask(nameparts[-1].strip(), longname, None) store.createTask(nameparts[-1].strip(), longname, None)
return False return False
def processStatus(cmd, store):
now = datetime.now()
monday = now - timedelta(now.weekday())
sunday = monday + timedelta(6)
entries = store.getEntriesInDateRange(monday, sunday)
prevtask = 0
for ent in entries:
if ent.taskid != prevtask:
prevtask = ent.taskid
task = store.getTaskByID(ent.taskid)
print store.getTaskPath(task) + ':'
hours = round(float(ent.seconds) / (60 * 60), 1)
print ' %s: %0.1f' % (ent.date, hours)
return False
COMMAND_HANDLERS = { COMMAND_HANDLERS = {
'start' : processStart, 'start' : processStart,
'out' : processOut, 'out' : processOut,
'task' : processTask 'task' : processTask,
'status' : processStatus
} }
# Returns boolean for whether the command prompt should be displayed again # Returns boolean for whether the command prompt should be displayed again