added --show-progress expiremental functionality
This commit is contained in:
parent
6981dca878
commit
e350c2e076
2 changed files with 83 additions and 6 deletions
|
@ -24,6 +24,8 @@ import datetime
|
|||
import logging
|
||||
import os
|
||||
import os.path
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import ctt
|
||||
|
||||
|
@ -32,12 +34,13 @@ log = logging.getLogger(__name__)
|
|||
|
||||
class Tracker:
|
||||
def __init__(self, project, start_datetime=None, end_datetime=None,
|
||||
comment=True):
|
||||
comment=True, show_progress=False):
|
||||
self.project = project
|
||||
self.project_dir = ctt.project_dir(project)
|
||||
|
||||
self._tracked_time = False
|
||||
self.comment = None
|
||||
self.show_progress = show_progress
|
||||
|
||||
# Setup default values
|
||||
try:
|
||||
|
@ -60,7 +63,7 @@ class Tracker:
|
|||
|
||||
@classmethod
|
||||
def commandline(cls, args):
|
||||
tracker = cls(args.project[0], args.start, args.end, args.comment)
|
||||
tracker = cls(args.project[0], args.start, args.end, args.comment, args.show_progress)
|
||||
tracker.track_time()
|
||||
|
||||
if args.comment:
|
||||
|
@ -85,6 +88,77 @@ class Tracker:
|
|||
if not self.start_datetime:
|
||||
self.start_datetime = datetime.datetime.now()
|
||||
|
||||
if self.show_progress:
|
||||
while True:
|
||||
print()
|
||||
import ctt
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Tracker:
|
||||
def __init__(self, project, start_datetime=None, end_datetime=None,
|
||||
comment=True, show_progress=False):
|
||||
self.project = project
|
||||
self.project_dir = ctt.project_dir(project)
|
||||
|
||||
self._tracked_time = False
|
||||
self.comment = None
|
||||
self.show_progress = show_progress
|
||||
|
||||
# Setup default values
|
||||
try:
|
||||
if start_datetime:
|
||||
self.start_datetime = datetime.datetime.strptime(
|
||||
start_datetime[0], ctt.DATETIMEFORMAT)
|
||||
else:
|
||||
self.start_datetime = None
|
||||
|
||||
if end_datetime:
|
||||
self.end_datetime = datetime.datetime.strptime(
|
||||
end_datetime[0], ctt.DATETIMEFORMAT)
|
||||
else:
|
||||
self.end_datetime = None
|
||||
except ValueError as e:
|
||||
raise ctt.Error(e)
|
||||
|
||||
if self.start_datetime and self.end_datetime:
|
||||
self._tracked_time = True
|
||||
|
||||
@classmethod
|
||||
def commandline(cls, args):
|
||||
tracker = cls(args.project[0], args.start, args.end, args.comment, args.show_progress)
|
||||
tracker.track_time()
|
||||
|
||||
if args.comment:
|
||||
tracker.record_comment()
|
||||
|
||||
tracker.write_time()
|
||||
log.info(tracker.delta())
|
||||
|
||||
def record_comment(self):
|
||||
"""Record a comment for tracked data"""
|
||||
self.comment = input("Comment: ")
|
||||
|
||||
# Track time and return information from tracking
|
||||
def track_time(self):
|
||||
"""Track time, if necessary"""
|
||||
|
||||
# Do not track again
|
||||
if self._tracked_time:
|
||||
return
|
||||
|
||||
# If not given by the user
|
||||
if not self.start_datetime:
|
||||
self.start_datetime = datetime.datetime.now()
|
||||
|
||||
if self.show_progress:
|
||||
while True:
|
||||
now = datetime.datetime.now()
|
||||
current_time = now.strftime("%H:%M:%S")
|
||||
print("Current Time =", current_time)
|
||||
time.sleep(10)
|
||||
else:
|
||||
try:
|
||||
# Wait for the exception to pop up
|
||||
input()
|
||||
|
|
|
@ -69,6 +69,9 @@ def parse_argv(argv, version):
|
|||
parser['track'].add_argument(
|
||||
"-n", "--no-comment", help="disable comment prompting after tracking",
|
||||
action='store_false', dest="comment")
|
||||
parser['track'].add_argument(
|
||||
"--show-progress", help="show time spent in session",
|
||||
action='store_true')
|
||||
parser['track'].add_argument(
|
||||
"project", help="project to track time for", nargs=1)
|
||||
|
||||
|
|
Loading…
Reference in a new issue