Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • bin/stamps

    r3 r10  
    11#!/usr/bin/env python
    22
    3 import sys
     3import argparse
    44from stamper import Stamper
    5 
    6 
    7 def usage(name):
    8     msg = """
    9     Usage:
    10 
    11     To gather information of recorded times: %(name)s
    12 
    13     Recorded times for a given customer: %(name)s customer
    14 
    15     Detailed times for a given customer: %(name)s customer details
    16     """ % {'name': name}
    17     print(msg)
    185
    196
    207if __name__ == '__main__':
    218
     9    parser = argparse.ArgumentParser(
     10        description='stamps: show recorded times information')
     11    parser.add_argument('customer', action="store", nargs='?',
     12                        help='Show times only for this customer')
     13    parser.add_argument('filter', action="store", nargs='?',
     14                        help='Filter the times by date range')
     15    parser.add_argument('-v', '--verbose', action="store_true",
     16                        help='Include detailed times information')
     17
     18    args = parser.parse_args()
     19
    2220    s = Stamper()
    2321    s.load_stamps()
    24 
    25     if len(sys.argv) == 1:
    26         totals = s.totals()
    27         print('Total times for all customers:')
    28         for t in totals:
    29             print(' -> %(customer)s: %(total)s' % {'customer': t,
    30                                                    'total': totals[t]})
    31     elif len(sys.argv) == 2:
    32         if sys.argv[1] in s.customers():
    33             print('Total time for %(customer)s: %(total)s' % {
    34                 'customer': sys.argv[1],
    35                 'total': s.total_by_customer(sys.argv[1])
    36                 })
    37 
    38     elif len(sys.argv) == 3:
    39         if sys.argv[1] in s.customers():
    40             print('Detailed time for %(customer)s' % {
    41                 'customer': sys.argv[1],
    42                 })
    43             details, totals = s.details_by_customer(sys.argv[1])
    44             for day in details:
    45                 print('------ %(day)s ------' % {'day': day})
    46                 for line in details[day]:
    47                     print(line)
    48                 print(' Total: %(total)s' % {'total': totals[day]})
    49 
    50     else:
    51         usage(sys.argv[0])
    52         sys.exit(1)
     22    s.show_stamps(args.customer, args.filter, args.verbose)
Note: See TracChangeset for help on using the changeset viewer.