Exemple #1
0
def status_main(args):
    if hasattr(args, 'invoice'):
        inv = Invoice(args.invoice)
    else:
        u = User()
        invid = u.active_invoice_rowid
        if invid == 0:
            fprintf("You do not have any invoices yet! Create one with `gitime "
                "invoice -n <invoice name>`.")
            sys.exit()
        inv = Invoice(u.active_invoice_rowid)
    total_hours = inv.total_hours()
    hourstr = 'hour' if total_hours == 1 else 'hours'
    print(textwrap.dedent("""\
        On invoice %s
        Total Time Worked: %g %s
        Total Charges:     $%.2f
        Charges:""" 
    %(inv.name, total_hours, hourstr, inv.total_earnings())))
    commits = inv.get_commit_meta()
    if not commits:
        fprintf("No charges yet!")
    else:
        for com in commits:
            date = (datetime.fromtimestamp(com[1])).strftime('%m-%d-%Y')
            wspace1 = (17 - len(date)) * " "
            hourstr = 'hour' if com[2] == 1 else 'hours'
            hours = "%g %s" %(com[2], hourstr)
            wspace2 = (14 - len(hours)) * " "
            message = com[0]
            fprintf(date, wspace1, hours, wspace2, message)
Exemple #2
0
def invoice_main(args):
    u = User()
    if hasattr(args, 'name'):
        if args.new:
            kwargs = {'new': True}
            if hasattr(args, 'rate'):
                kwargs['rate'] = args.rate
            if hasattr(args, 'round'):
                kwargs['rounding'] = args.round
            inv = Invoice(args.name, **kwargs)
            inv.set_active()
            fprintf("Future commits will now be sent to the invoice %s." 
                %inv.name)
        else:
            try:
                inv = Invoice(args.name)
            except InvoiceNotFound:
                if raw_input(
                    "That invoice doesn't exist. Make a new one? [Y/n] "
                ) == 'n':
                    sys.exit()
                inv = Invoice(args.name, new=True)
            if hasattr(args, 'rate'):
                inv.set_rate(args.rate)
            if hasattr(args, 'round'):
                inv.set_rounding(args.round)
            if u.active_invoice_rowid != inv.rowid:
                inv.set_active()
                fprintf("Future commits will now be sent to the invoice %s." 
                    %inv.name)
    else:
        if db.invoice_count() == 0:
            fprintf("You do not have any invoices yet! Create one with `gitime "
                "invoice -n <invoice name>`.")
        else:
            inv = Invoice(u.active_invoice_rowid)
            if hasattr(args, 'rate'):
                inv.set_rate(args.rate)
            if hasattr(args, 'round'):
                inv.set_rounding(args.round)
    if args.list:
        count = db.invoice_count()
        noun = 'invoice' if count == 1 else 'invoices'
        fprintf("You have %d %s:" %(count, noun))
        for invoice in db.query_all_invoices():
            if invoice[3] == u.active_invoice_rowid:
                active = " (active)"
            else:
                active = ""
            fprintf(invoice[0], active)