~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/timeline/nestingtimedaction.py

  • Committer: Robert Collins
  • Date: 2011-08-10 01:00:53 UTC
  • mto: This revision was merged to the branch mainline in revision 13644.
  • Revision ID: robertc@robertcollins.net-20110810010053-w2tcm21i87fwqr3s
Use the new extracted timeline module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Time an action which calls other timed actions."""
5
 
 
6
 
 
7
 
__all__ = ['NestingTimedAction']
8
 
 
9
 
__metaclass__ = type
10
 
 
11
 
 
12
 
import datetime
13
 
 
14
 
from timedaction import TimedAction
15
 
 
16
 
 
17
 
class NestingTimedAction(TimedAction):
18
 
    """A variation of TimedAction which creates a nested environment.
19
 
    
20
 
    This is done by recording two 0 length timed actions in the timeline:
21
 
    one at the start of the action and one at the end, with -start and
22
 
    -stop appended to their categories.
23
 
 
24
 
    See `TimedAction` for more information.
25
 
    """
26
 
 
27
 
    def _init(self):
28
 
        self.duration = datetime.timedelta()
29
 
        self._category = self.category
30
 
        self.category = self._category + '-start'
31
 
 
32
 
    def finish(self):
33
 
        """Mark the TimedAction as finished."""
34
 
        end = self.timeline.start(self._category + '-stop', self.detail)
35
 
        end.duration = datetime.timedelta()