Añadidas tres funciones más: master
authorDaniel Garcia Moreno <dgarcia@emergya.es>
Mon, 29 Sep 2008 07:16:21 +0000 (09:16 +0200)
committerDaniel Garcia Moreno <dgarcia@emergya.es>
Mon, 29 Sep 2008 07:16:21 +0000 (09:16 +0200)
 -d <delta>
 -gd <delta>
 -ga

show.py
ttt.py

diff --git a/show.py b/show.py
index b060c82..8d4449e 100755 (executable)
--- a/show.py
+++ b/show.py
@@ -14,7 +14,10 @@ if __name__ == '__main__':
      -g muestra agrupados por proyecto
      -w muestra la ultima semana
      -gw muestra la ultima semana agrupado por proyecto
+     -d <delta> muestra hace delta dias
+     -gd <delta> muestra hace delta dias agrupados
      -a muestra todo
+     -ga muestra todo agrupado
 
      si no se especifica opcion muestra las tareas de hoy
     '''
@@ -32,5 +35,19 @@ if __name__ == '__main__':
         ttt.show_week_grouped()
     elif '-a' in args:
         ttt.show_all()
+    elif '-ga' in args:
+        ttt.show_all_grouped()
+    elif '-d' in args:
+        try:
+            delta = int(args[1])
+            ttt.show_today(delta, day=True)
+        except:
+            print help % sys.argv[0]
+    elif '-gd' in args:
+        try:
+            delta = int(args[1])
+            ttt.show_today_grouped(delta, day=True)
+        except:
+            print help % sys.argv[0]
     else:
         ttt.show_today()
diff --git a/ttt.py b/ttt.py
index ff09f1a..00cce20 100755 (executable)
--- a/ttt.py
+++ b/ttt.py
@@ -8,6 +8,7 @@ import time
 import sys
 import tttdb as db
 from tttdb import Tracker
+from sqlobject import AND
 
 sqlhub = db.get_hub()
 
@@ -80,35 +81,47 @@ def show(trackers):
 
     print '\nTotal: %s' % parse_time(total)
 
-def show_today(delta=0):
+def show_today(delta=0, day=False, func=show):
     today = datetime.datetime.now() - datetime.timedelta(delta)
     yesterday = datetime.datetime(today.year, today.month, today.day)
-    today_trackers = Tracker.select(Tracker.q.start > yesterday)
-    show(today_trackers)
+    tomorrow = datetime.datetime(today.year, today.month, today.day, 23, 59, 59)
+    if day:
+        today_trackers = Tracker.select(AND(Tracker.q.start > yesterday,
+                                            Tracker.q.start < tomorrow),
+                                            orderBy="start")
+    else:
+        today_trackers = Tracker.select(Tracker.q.start > yesterday,
+                                        orderBy="start")
+
+    print 'DAY %s' % yesterday.ctime()
+    func(today_trackers)
 
 def show_project(project):
-    project_trackers = Tracker.select(Tracker.q.project == project)
+    project_trackers = Tracker.select(Tracker.q.project == project,
+                                    orderBy="start")
     sum = 0
     for i in project_trackers:
         sum += (i.end - i.start).seconds
 
     print 'Tiempo para "%s": %s' % (project, parse_time(sum))
 
-def show_all():
-    all = Tracker.select()
-    show(all)
+def show_all(func=show):
+    all = Tracker.select(orderBy="start")
+    func(all)
+
+def show_all_grouped():
+    all = show_all(func=show_grouped)
 
 def show_week():
-    show_today(6)
+    d = datetime.datetime.now().weekday()
+    show_today(d)
 
 def show_week_grouped():
-    show_today_grouped(6)
+    d = datetime.datetime.now().weekday()
+    show_today_grouped(d)
 
-def show_today_grouped(delta=0):
-    today = datetime.datetime.now() - datetime.timedelta(delta)
-    yesterday = datetime.datetime(today.year, today.month, today.day)
-    today_trackers = Tracker.select(Tracker.q.start > yesterday)
-    show_grouped(today_trackers)
+def show_today_grouped(delta=0, day=False):
+    show_today(delta, day, func=show_grouped)
 
 def show_grouped(trackers):
     projects = {}