initial support for listing tracked time for all projects

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-07-24 16:35:47 +02:00
parent 138e1075f9
commit 29fbda012f
3 changed files with 38 additions and 13 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# 2012 Nico Schottelius (nico-ctt at schottelius.org) # 2012-2013 Nico Schottelius (nico-ctt at schottelius.org)
# #
# This file is part of ctt. # This file is part of ctt.
# #
@ -66,12 +66,13 @@ def parse_argv(argv, version):
parser['report'] = parser['sub'].add_parser('report', parser['report'] = parser['sub'].add_parser('report',
parents=[parser['loglevel']]) parents=[parser['loglevel']])
parser['report'].set_defaults(func=Report.commandline) parser['report'].set_defaults(func=Report.commandline)
parser['report'].add_argument("project", help="project to report time for", nargs=1) parser['report'].add_argument("project", help="project to report time for", nargs='*')
parser['report'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN, parser['report'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
nargs=1, dest="start") nargs=1, dest="start")
parser['report'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN, parser['report'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
nargs=1, default=None, dest="end") nargs=1, default=None, dest="end")
parser['report'].add_argument("-a", "--all", help="List entries for all projects", action='store_true')
parser['report'].add_argument("-e", "--regexp", help="regular expression to match", parser['report'].add_argument("-e", "--regexp", help="regular expression to match",
default=None) default=None)
parser['report'].add_argument("-i", "--ignore-case", help="ignore case distinctions", action="store_true") parser['report'].add_argument("-i", "--ignore-case", help="ignore case distinctions", action="store_true")
@ -96,7 +97,8 @@ def parse_argv(argv, version):
except ctt.Error as e: except ctt.Error as e:
log.error(e) log.error(e)
sys.exit(1) sys.exit(1)
except AttributeError: except AttributeError as e:
print(e)
parser['main'].print_help() parser['main'].print_help()

View file

@ -33,6 +33,12 @@ class ListProjects(object):
cls.print_projects() cls.print_projects()
@classmethod
def print_projects(): def print_projects():
for project in ctt.list_projects(ctt.ctt_dir()): for project in cls.list_projects():
print(project) print(project)
@staticmethod
def list_projects():
for project in ctt.list_projects(ctt.ctt_dir()):
yield project

View file

@ -32,6 +32,7 @@ import re
import sys import sys
import ctt import ctt
import ctt.listprojects
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -57,8 +58,20 @@ class Report(object):
@classmethod @classmethod
def commandline(cls, args): def commandline(cls, args):
report = cls(args.project[0], args.start, args.end, args.output_format, args.regexp, args.ignore_case) # Report time for all projects
report.report() if args.all:
projects=ctt.listprojects.ListProjects.list_projects()
else:
projects=[args.projects[0]]
total_time = 0
for project in projects:
report = cls(project, args.start, args.end, args.output_format, args.regexp, args.ignore_case)
report.report()
total_time = total_time + report.total_time
cls.summary(total_time)
def _init_date(self, start_date, end_date): def _init_date(self, start_date, end_date):
@ -133,17 +146,22 @@ class Report(object):
log.debug("Skipping: %s" % dirname) log.debug("Skipping: %s" % dirname)
def report(self): def report(self):
self.header()
self.list_entries() self.list_entries()
self.summary() self.summary(self.total_time)
def summary(self): def header(self):
"""Show report to the user""" print("Report for %s between %s and %s" %
(self.project, self.start_date, self.end_date))
hours, minutes, seconds = ctt.user_timedelta(self.total_time()) @staticmethod
def summary(total_time):
hours, minutes, seconds = ctt.user_timedelta(total_time)
print("Tracked time between %s and %s: %sh %sm %ss." % print("Total time tracked: %sh %sm %ss." %
(self.start_date, self.end_date, hours, minutes, seconds)) (hours, minutes, seconds))
@property
def total_time(self): def total_time(self):
"""Return all entries""" """Return all entries"""
@ -160,7 +178,6 @@ class Report(object):
"""Return total time tracked""" """Return total time tracked"""
sorted_times = sorted(self._report_db.keys()) sorted_times = sorted(self._report_db.keys())
#for time, entry in self._report_db.items():
for time in sorted_times: for time in sorted_times:
entry = self._report_db[time] entry = self._report_db[time]