1
# Copyright (c) 2010, 2011, Canonical Ltd
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
# GNU Affero General Public License version 3 (see the file LICENSE).
17
"""Time an action which calls other timed actions."""
20
__all__ = ['NestingTimedAction']
27
from timedaction import TimedAction
30
class NestingTimedAction(TimedAction):
31
"""A variation of TimedAction which creates a nested environment.
33
This is done by recording two 0 length timed actions in the timeline:
34
one at the start of the action and one at the end, with -start and
35
-stop appended to their categories.
37
See `TimedAction` for more information.
41
self.duration = datetime.timedelta()
42
self._category = self.category
43
self.category = self._category + '-start'
46
"""Mark the TimedAction as finished."""
47
end = self.timeline.start(self._category + '-stop', self.detail)
48
end.duration = datetime.timedelta()