Exemplo n.º 1
0
def do_edit(args):
    log.info("edit timer %s", args.id)

    service = TimerService()

    if args.delete:
        service.delete(id=args.id)
        print("Deleted timer %s" % args.id)

    if args.start_time or args.stop_time or args.task:
        start, stop = None, None
        if args.start_time:
            start = _parse_timestamp(args.start_time)
            print('Updating start time for timer "%s" to "%s"' %
                  (args.id, start))
        if args.stop_time:
            stop = _parse_timestamp(args.stop_time)
            print('Updating stop time for timer "%s" to "%s"' %
                  (args.id, stop))

        if args.task:
            print('Updating task for timer "%s" to "%s"' %
                  (args.id, args.task))

        service.update(id=args.id, task=args.task, start=start, stop=stop)

    if args.make_active:
        service.update(id=args.id, stop="")
        print('Marking timer "%s" as active' % args.id)
Exemplo n.º 2
0
def do_export(args):
    service = TimerService()
    if args.destination == "-":
        tt.io.dump(service, sys.stdout)
        return

    with open(args.destination, "w") as out:
        print("Exporting records to %s" % args.destination)
        tt.io.dump(service, out)
Exemplo n.º 3
0
def do_import(args):
    task_service = TaskService()
    timer_service = TimerService()

    if args.source == "-":
        tt.io.load(task_service, timer_service, sys.stdin)
        return
    with open(args.source, "r") as in_:
        print("Importing records from %s" % args.source)
        tt.io.load(task_service, timer_service, in_)
Exemplo n.º 4
0
def do_summary(args):

    if args.begin or args.end:
        begin = _parse_timestamp(args.begin or DEFAULT_REPORT_START)
        end = _parse_timestamp(args.end or DEFAULT_REPORT_END)
    else:
        begin, end = from_timerange(args)

    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    print(reporting_service.summary_by_task(start=begin, end=end))
Exemplo n.º 5
0
def do_records(args):

    if args.begin or args.end:
        begin = _parse_timestamp(args.begin or DEFAULT_REPORT_START)
        end = _parse_timestamp(args.end or DEFAULT_REPORT_END)
    else:
        begin, end = from_timerange(args)

    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    for daily_table in reporting_service.timers_by_day(start=begin, end=end):
        print("%s\n" % daily_table)
Exemplo n.º 6
0
def do_report(args):
    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    target_date = datetime.now(tz_local()).replace(hour=0,
                                                   minute=0,
                                                   second=0,
                                                   microsecond=0)

    if args.month:
        if args.month > target_date.month:
            target_date = target_date.replace(year=target_date.year - 1)
        target_date = target_date.replace(month=args.month)

    last_day_of_month = calendar.monthrange(target_date.year,
                                            target_date.month)[1]

    start = target_date.replace(day=1)
    end = target_date.replace(day=last_day_of_month)
    for weekly_report in reporting_service.summary_by_day_and_task(start=start,
                                                                   end=end):
        print("%s\n" % weekly_report)
Exemplo n.º 7
0
def do_status(args):
    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    now = datetime.now(tz_local()).replace(hour=0,
                                           minute=0,
                                           second=0,
                                           microsecond=0)

    week_begin, week_end = tt.datetime.week_boundaries(now)

    day_begin = now
    day_end = now + timedelta(days=1)
    try:
        print(
            next(
                reporting_service.summary_by_day_and_task(start=week_begin,
                                                          end=week_end)))
        print("\n")
        print(
            next(reporting_service.timers_by_day(start=day_begin,
                                                 end=day_end)))
    except StopIteration:
        print("No records")
Exemplo n.º 8
0
def timer_service():
    return TimerService()
Exemplo n.º 9
0
def do_stop(args):
    time = _parse_timestamp(args.time)
    log.info("stopping current timer %s", time)
    service = TimerService()
    service.stop(timestamp=time)
    print('Stopped at "%s"' % time)
Exemplo n.º 10
0
def do_start(args):
    time = _parse_timestamp(args.time)
    log.info("starting timer on task %s %s", args.task, time)
    service = TimerService()
    service.start(task=args.task, timestamp=time)
    print('Started at "%s"' % time)