Esempio n. 1
0
def commit_main(args):
    # commits are NOT handled by argparse. `args` are passed to this function
    # as they are from sys.argv.
    u = User()
    invid = u.active_invoice_rowid
    if invid == 0:
        fprintf(
            "GITIME ERROR: You do not have an active invoice set. "
            "You won't be able to record your hours without one. "
            "Create an invoice with the command: `gitime invoice -n <invoice "
            "name>` first. Your commit has NOT been made.", file=sys.stderr)
        sys.exit()
    inv = Invoice(invid)
    raw_hours = parse_hours_flag(args)
    if raw_hours is not False:
        hours = round(raw_hours / inv.rounding) * inv.rounding
    else:
        hours = u.time_tracked(inv)
        if hours <= 0:
            fprintf(
                "GITIME ERROR: You didn't specify a number of hours, and the "
                "timer hasn't recorded anything. Run this command with the "
                "`--hours <hour count>` flag, or use the timer to track your "
                "time. Your commit has NOT been made."), file=sys.stderr)
            sys.exit()
        u.reset_timer()
    message = parse_commit_message(args)
    if not message:
        fprintf("GITIME ERROR: Could not find a message in your commit.", 
            file=sys.stderr)
        sys.exit()
Esempio n. 2
0
def timer_main(args):
    u = User()
    if not args.force:
        if u.active_invoice_rowid == 0:
            fprintf(
                "WARNING: You do not have an active invoice set. "
                "You won't be able to record your hours without one. "
                "Create an invoice with the command: `gitime invoice -n "
                "<invoice name>` first, or suppress this warning by running "
                "the timer with the --force flag.", 
            file=sys.stderr)
            sys.exit()
    if args.action == 'start':
        u.start_timer()
        fprintf('Timer started at %s' %str(datetime.now()))
    elif args.action == 'pause':
        u.pause_timer()
        fprintf('Timer paused at %s' %str(datetime.now()))
    elif args.action == 'reset':
        u.reset_timer()
    elif args.action == 'status':
        inv = Invoice(u.active_invoice_rowid)
        if u.timer_running:
            status = 'has been running since %s.' %str(
                datetime.fromtimestamp(u.timer_start))
        else:
            status = 'is not running.'
        fprintf('The timer %s' %status)
        fprintf('Total hours tracked: %.2f' %(u.time_tracked(inv)))