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
press ctrl-c to stop time tracking
@ -15,31 +13,33 @@ Dateformat:
Report:
cdist(1)
========
Nico Schottelius <nico-cdist--@--schottelius.org>
ctt(1)
======
Nico Schottelius <nico-ctt--@--schottelius.org>
NAME
----
cdist - Configuration management
ctt - time tracking for geeks
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
-----------
cdist is the frontend executable to the cdist configuration management.
cdist supports different as explained below. The options to the main
program are:
--------------------------------------------------------------------------------
ctt track myreport
--------------------------------------------------------------------------------
-h, --help::
Show the help screen
@ -50,7 +50,7 @@ program are:
BANNER
-------
Displays the cdist banner.
Displays the ctt banner.
CONFIG
@ -60,15 +60,15 @@ Configure a system
-h, --help::
Show the help screen
-c CDIST_HOME, --cdist-home CDIST_HOME::
Instead of using the parent of the bin directory as cdist home,
-c CDIST_HOME, --ctt-home CDIST_HOME::
Instead of using the parent of the bin directory as ctt home,
use the specified directory
-d, --debug::
Enable debug output
-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::
Operate on multiple hosts in parallel
@ -88,25 +88,25 @@ EXAMPLES
--------------------------------------------------------------------------------
# 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
cdist config -c ~/p/cdist-nutzung \
ctt config -c ~/p/ctt-nutzung \
-p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch
# 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 \
-p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch
# Display banner
cdist banner
ctt banner
# Show help
cdist --help
ctt --help
# Show Version
cdist --version
ctt --version
--------------------------------------------------------------------------------
@ -131,8 +131,8 @@ The following exit values shall be returned:
SEE ALSO
--------
- cdist(7)
- cdist-reference(7)
- ctt(7)
- ctt-reference(7)
COPYING

View file

@ -34,9 +34,22 @@ class Error(Exception):
pass
# Our output format
def user_datetime(when):
"""Print time for the user"""
return when.ctime()
def user_timedelta(seconds):
"""Format timedelta for the user"""
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):
home = os.environ['HOME']

View file

@ -42,19 +42,19 @@ class Report(object):
# Setup default values
try:
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:
start_date = self.default_dates()[0]
self.start_date = self.default_dates()[0]
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:
end_date = self.default_dates()[1]
self.end_date = self.default_dates()[1]
except ValueError as e:
raise ctt.Error(e)
self.start_seconds = start_date.strftime("%s")
self.end_seconds = end_date.strftime("%s")
self.start_seconds = self.start_date.strftime("%s")
self.end_seconds = self.end_date.strftime("%s")
self.project = project
self.project_dir = ctt.project_dir(self.project)
@ -64,7 +64,7 @@ class Report(object):
@classmethod
def commandline(cls, args):
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):
"""Read all contents from db"""
@ -84,14 +84,13 @@ class Report(object):
log.debug("%s/%s" % (float(dirname) - float(self.start_seconds),
float(self.end_seconds) - float(dirname)))
def beautify_timedelta(self, timedelta):
"""Make it printable for the user"""
def report(self):
"""Show report to the user"""
for times in self._report_db.values():
log.debug("Adding %s to %s time..." % (times, count))
count = count + float(times)
hours, minutes, seconds = ctt.user_timedelta(self.total_time())
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):
"""Return total time tracked"""

View file

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