ctt/scripts/ctt
2016-05-24 07:16:25 +02:00

119 lines
4.5 KiB
Python
Executable file

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2012-2015 Nico Schottelius (nico-ctt at schottelius.org)
# 2016 Darko Poljak (darko.poljak at gmail.com)
#
# 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 logging
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 parse_argv(argv, version):
parser = {}
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
parser['loglevel'].add_argument('-d', '--debug',
help='set log level to debug', action='store_true',
default=False)
parser['loglevel'].add_argument('-v', '--verbose',
help='set log level to info, be more verbose',
action='store_true', default=False)
parser['main'] = argparse.ArgumentParser(description='ctt ' + version,
parents=[parser['loglevel']])
parser['sub'] = parser['main'].add_subparsers(title="Commands")
parser['listprojects'] = parser['sub'].add_parser('listprojects',
parents=[parser['loglevel']])
parser['listprojects'].set_defaults(func=ListProjects.commandline)
parser['track'] = parser['sub'].add_parser('track',
parents=[parser['loglevel']])
parser['track'].set_defaults(func=Tracker.commandline)
parser['track'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
nargs=1, dest="start")
parser['track'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
nargs=1, default=None, dest="end")
parser['track'].add_argument("-n", "--no-comment", help="disable comment prompting after tracking",
action='store_false', dest="comment")
parser['track'].add_argument("project", help="project to track time for", nargs=1)
parser['report'] = parser['sub'].add_parser('report',
parents=[parser['loglevel']])
parser['report'].set_defaults(func=Report.commandline)
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,
nargs=1, dest="start")
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")
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",
default=None)
parser['report'].add_argument("-i", "--ignore-case", help="ignore case distinctions", action="store_true")
parser['report'].add_argument("-f", "--format", help="output format (default: %s)" % ctt.REPORTFORMAT,
default=ctt.REPORTFORMAT, dest="output_format")
parser['report'].add_argument("-s", "--summary", help="hide project names and list time entries in chronological order", action="store_true")
#parser['track'].add_argument("-t", "--tag", help="Add tags",
# action="store_true")
args = parser['main'].parse_args()
if args.verbose:
logging.root.setLevel(logging.INFO)
if args.debug:
logging.root.setLevel(logging.DEBUG)
log.debug(args)
try:
if hasattr(args, "func"):
args.func(args)
else:
parser['main'].print_help()
except ctt.Error as e:
log.error(e)
sys.exit(1)
except AttributeError as e:
print(e)
parser['main'].print_help()
if __name__ == "__main__":
logging.basicConfig(format='%(message)s')
import ctt
from ctt.tracker import Tracker
from ctt.report import Report
from ctt.listprojects import ListProjects
parse_argv(sys.argv[1:], ctt.VERSION)
sys.exit(0)