reporting tracked time works

[17:37] brief:ctt% ./bin/ctt report -s 2012-01-01 -e 2012-12-31  test
Tracked time between 2012-01-01 00:00:00 and 2012-12-31 00:00:00: 0h 0m
10.654657s.
[17:37] brief:ctt% ./bin/ctt report -s 2012-01-01 -e 2012-12-31  localch
Tracked time between 2012-01-01 00:00:00 and 2012-12-31 00:00:00: 16h
32m 38.84267699999327s.

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-08-27 17:37:56 +02:00
parent 1681870473
commit 1f482cf3f2
4 changed files with 55 additions and 43 deletions

52
README
View file

@ -1,5 +1,3 @@
ctt - time tracking for geeks
ctt - starts time tracking ctt - starts time tracking
press ctrl-c to stop time tracking press ctrl-c to stop time tracking
@ -15,31 +13,33 @@ Dateformat:
Report: Report:
cdist(1) ctt(1)
======== ======
Nico Schottelius <nico-cdist--@--schottelius.org> Nico Schottelius <nico-ctt--@--schottelius.org>
NAME NAME
---- ----
cdist - Configuration management ctt - time tracking for geeks
SYNOPSIS SYNOPSIS
-------- --------
cdist [-h] [-V] ctt [-h] [-V]
cdist banner ctt track [-h] [-d] [-v] [-s START] [-e END] project
cdist config [-h] [-d] [-V] [-c CDIST_HOME] [-i MANIFEST] [-p] [-s] host [host ...] ctt report [-h] [-d] [-v] [-s START] [-e END] project
TIME TRACKING
-------------
If you start ctt with a project name, ctt will begin right away to
track the time, until you stop it using Ctrl-C:
DESCRIPTION --------------------------------------------------------------------------------
----------- ctt track myreport
cdist is the frontend executable to the cdist configuration management. --------------------------------------------------------------------------------
cdist supports different as explained below. The options to the main
program are:
-h, --help:: -h, --help::
Show the help screen Show the help screen
@ -50,7 +50,7 @@ program are:
BANNER BANNER
------- -------
Displays the cdist banner. Displays the ctt banner.
CONFIG CONFIG
@ -60,15 +60,15 @@ Configure a system
-h, --help:: -h, --help::
Show the help screen Show the help screen
-c CDIST_HOME, --cdist-home CDIST_HOME:: -c CDIST_HOME, --ctt-home CDIST_HOME::
Instead of using the parent of the bin directory as cdist home, Instead of using the parent of the bin directory as ctt home,
use the specified directory use the specified directory
-d, --debug:: -d, --debug::
Enable debug output Enable debug output
-i MANIFEST, --initial-manifest MANIFEST:: -i MANIFEST, --initial-manifest MANIFEST::
Path to a cdist manifest or - to read from stdin Path to a ctt manifest or - to read from stdin
-p, --parallel:: -p, --parallel::
Operate on multiple hosts in parallel Operate on multiple hosts in parallel
@ -88,25 +88,25 @@ EXAMPLES
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# Configure ikq05.ethz.ch with debug enabled # Configure ikq05.ethz.ch with debug enabled
cdist config -d ikq05.ethz.ch ctt config -d ikq05.ethz.ch
# Configure hosts in parallel and use a different home directory # Configure hosts in parallel and use a different home directory
cdist config -c ~/p/cdist-nutzung \ ctt config -c ~/p/ctt-nutzung \
-p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch
# Use custom remote exec / copy commands # Use custom remote exec / copy commands
cdist config --remote-exec /path/to/my/remote/exec \ ctt config --remote-exec /path/to/my/remote/exec \
--remote-copy /path/to/my/remote/copy \ --remote-copy /path/to/my/remote/copy \
-p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch
# Display banner # Display banner
cdist banner ctt banner
# Show help # Show help
cdist --help ctt --help
# Show Version # Show Version
cdist --version ctt --version
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -131,8 +131,8 @@ The following exit values shall be returned:
SEE ALSO SEE ALSO
-------- --------
- cdist(7) - ctt(7)
- cdist-reference(7) - ctt-reference(7)
COPYING COPYING

View file

@ -34,9 +34,22 @@ class Error(Exception):
pass pass
# Our output format # Our output format
def user_datetime(when): def user_timedelta(seconds):
"""Print time for the user""" """Format timedelta for the user"""
return when.ctime()
if seconds >= 3600:
hours = int(seconds / 3600)
seconds = seconds - (hours * 3600)
else:
hours = 0
if seconds >= 60:
minutes = int(seconds / 60)
seconds = seconds - (minutes * 60)
else:
minutes = 0
return (hours, minutes, seconds)
def project_dir(project): def project_dir(project):
home = os.environ['HOME'] home = os.environ['HOME']

View file

@ -42,19 +42,19 @@ class Report(object):
# Setup default values # Setup default values
try: try:
if start_date: if start_date:
start_date = datetime.datetime.strptime(start_date[0], ctt.DATEFORMAT) self.start_date = datetime.datetime.strptime(start_date[0], ctt.DATEFORMAT)
else: else:
start_date = self.default_dates()[0] self.start_date = self.default_dates()[0]
if end_date: if end_date:
end_date = datetime.datetime.strptime(end_date[0], ctt.DATEFORMAT) self.end_date = datetime.datetime.strptime(end_date[0], ctt.DATEFORMAT)
else: else:
end_date = self.default_dates()[1] self.end_date = self.default_dates()[1]
except ValueError as e: except ValueError as e:
raise ctt.Error(e) raise ctt.Error(e)
self.start_seconds = start_date.strftime("%s") self.start_seconds = self.start_date.strftime("%s")
self.end_seconds = end_date.strftime("%s") self.end_seconds = self.end_date.strftime("%s")
self.project = project self.project = project
self.project_dir = ctt.project_dir(self.project) self.project_dir = ctt.project_dir(self.project)
@ -64,7 +64,7 @@ class Report(object):
@classmethod @classmethod
def commandline(cls, args): def commandline(cls, args):
report = cls(args.project[0], args.start, args.end) report = cls(args.project[0], args.start, args.end)
print("Total time in seconds: %s" % report.total_time()) report.report()
def _init_report_db(self): def _init_report_db(self):
"""Read all contents from db""" """Read all contents from db"""
@ -84,14 +84,13 @@ class Report(object):
log.debug("%s/%s" % (float(dirname) - float(self.start_seconds), log.debug("%s/%s" % (float(dirname) - float(self.start_seconds),
float(self.end_seconds) - float(dirname))) float(self.end_seconds) - float(dirname)))
def beautify_timedelta(self, timedelta): def report(self):
"""Make it printable for the user""" """Show report to the user"""
for times in self._report_db.values(): hours, minutes, seconds = ctt.user_timedelta(self.total_time())
log.debug("Adding %s to %s time..." % (times, count))
count = count + float(times)
return count print("Tracked time between %s and %s: %sh %sm %ss." %
(self.start_date, self.end_date, hours, minutes, seconds))
def total_time(self): def total_time(self):
"""Return total time tracked""" """Return total time tracked"""

View file

@ -43,7 +43,7 @@ class Tracker:
tracker = cls(args.project[0]) tracker = cls(args.project[0])
tracker.track_time() tracker.track_time()
tracker.write_time() tracker.write_time()
print(tracker.delta()) log.info(tracker.delta())
# Track time and return information from tracking # Track time and return information from tracking
def track_time(self): def track_time(self):