Changeset 32:80a51180155e in stamper


Ignore:
Timestamp:
Aug 9, 2014, 10:04:58 AM (7 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Added support to delete up to N stamps from the list:

  • Delete the last recorded stamp:

stamp -d 1

  • Delete the last 10 stamps:

stamp -d 10

We ask for confirmation before proceeding with every stamp, in case
the user asks for the removal of multiple stamps, as soon as he does
not remove one of them, the following stamps could not be deleted.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bin/stamps

    r30 r32  
    2121    parser.add_argument('-t', '--timeline', action="store_true",
    2222                        help='Show a timeline of recorded times')
     23    parser.add_argument('-d', '--delete', action="store", type=int,
     24                        help='Delete up to n recorded stamps')
    2325
    2426    args = parser.parse_args()
     
    3638    if args.timeline:
    3739        s.timeline()
     40    elif args.delete:
     41        s.remove_stamps(args.delete)
    3842    elif args.graph:
    3943        s.graph_stamps(args.customer, args.filter)
  • stamper/stamper.py

    r30 r32  
    4848        })
    4949
    50     def last_stamp(self):
     50    def last_stamp(self, n=1):
     51        """
     52        return the stamp in position -n, that is, starting from the latest one
     53        and going back N positions in the list of stamps
     54        """
    5155        if not self.stamps:
    5256            return None
    53         return self.stamps[-1]
     57        return self.stamps[-n]
    5458
    5559    def worktime(self, start, end):
     
    311315                    totalDays, remainingHr, remainingMin, HOURS_DAY
    312316                ))
     317
     318    def remove_stamps(self, n=1):
     319        """
     320        Remove up to n stamps back, asking for confirmation before delete
     321        """
     322        for i in range(n):
     323            stamp = self.last_stamp()
     324            if not stamp['customer']:
     325                print(stamp['start'] + ' start')
     326            else:
     327                print(' '.join([stamp['end'],
     328                                stamp['customer'],
     329                                stamp['action']]))
     330            confirm = ''
     331            while confirm.lower() not in ['y', 'n']:
     332                confirm = raw_input('delete stamp? (y/n) ')
     333                confirm = confirm.lower()
     334            if confirm == 'y':
     335                self.stamps.pop()
     336            else:
     337                # if the user says no to the removal of an stamp, we cannot
     338                # keep deleting stamps after that one, as that could leave the
     339                # stamps in an inconsistent state.
     340                print('Aborting removal of stamps')
     341                break
     342        self.save_stamps()
Note: See TracChangeset for help on using the changeset viewer.