ctt/bin/ctt

100 lines
2.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2012 Nico Schottelius (nico-ctt at schottelius.org)
#
# This file is part of ctt.
#
# ctt is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ctt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ctt. If not, see <http://www.gnu.org/licenses/>.
#
#
import argparse
import calendar
import datetime
#import signal
import locale
import logging
import time
import os
import os.path
import sys
log = logging.getLogger(__name__)
# Setup locale for calendar printing
# Setup locale to get Timezone information?
#print(locale.getlocale())
# Record tags
def cmd_track(args):
"""Command line handler for time tracking"""
tracker = Tracker(args.project[0])
tracker.track_time()
tracker.write_time()
print(tracker.delta())
def cmd_report(args):
"""Command line handler for time reporting"""
print(args)
report = Report(args.project[0], args.start, args.end)
print(Report.default_dates())
def parse_argv(argv):
parser = {}
parser['main'] = argparse.ArgumentParser(description='ctt ' + VERSION)
parser['sub'] = parser['main'].add_subparsers(title="Commands")
parser['track'] = parser['sub'].add_parser('track')
parser['track'].set_defaults(func=cmd_track)
parser['track'].add_argument("project", help="Project to track time for", nargs=1)
parser['report'] = parser['sub'].add_parser('report')
parser['report'].set_defaults(func=cmd_report)
parser['report'].add_argument("project", help="Project to report time for", nargs=1)
parser['report'].add_argument("-s", "--start", help="Start datetime (first of last month)",
nargs=1)
parser['report'].add_argument("-e", "--end", help="End datetime (last of last month)", nargs=1,
default=None)
#parser['track'].add_argument("-t", "--tag", help="Add tags",
# action="store_true")
args = parser['main'].parse_args()
print(args)
args.func(args)
if __name__ == "__main__":
# Ensure our /lib/ is included into PYTHON_PATH
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../lib')))
from ctt.tracker import Tracker
from ctt.report import Report
parse_argv(sys.argv[1:])
sys.exit(0)
# Setup signal handler
# Start tracking
# Save stuff to our home directory
# Create datetime from userinput
# Wed Aug 1 23:35:53 2012