Package Task :: Module Base
[hide private]
[frames] | no frames]

Source Code for Module Task.Base

  1  ''' 
  2  Defines the base class for all L{Task}s. 
  3   
  4  @author: Peter Parente 
  5  @author: Larry Weiss 
  6  @organization: IBM Corporation 
  7  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  8  @license: The BSD License 
  9   
 10  All rights reserved. This program and the accompanying materials are made  
 11  available under the terms of the BSD license which accompanies 
 12  this distribution, and is available at 
 13  U{http://www.opensource.org/licenses/bsd-license.php} 
 14  ''' 
 15  import Tools, UIElement, UIRegistrar 
 16   
 17  default_types = [] 
 18  all_types = [] 
 19   
20 -def registerTaskType(name, default):
21 ''' 22 Called once by every L{Task} class to register itself for buffering and 23 filtering by an L{AEMonitor}. 24 25 @param name: Name of the L{Task} 26 @type name: string 27 @param default: Should this L{Task} be buffered by default? 28 @type default: boolean 29 ''' 30 global default_types 31 global all_types 32 all_types.append(name) 33 if default: 34 default_types.append(name)
35
36 -def getDefaults():
37 ''' 38 Suggests the default L{Task}s to be monitored. 39 40 @return: Names of defaults to monitor 41 @rtype: list of string 42 ''' 43 return default_types
44
45 -def getNames():
46 ''' 47 Gets the names of all the L{Task} types. 48 49 @return: List of all L{Task} names 50 @rtype: list of string 51 ''' 52 return all_types
53
54 -class Task(Tools.All, UIElement.UIE):
55 ''' 56 Most base class for all L{Task}s that execute in a L{Perk}. Stores a 57 string identifying a particular class instance. Implements L{UIElement} 58 to provide information to the user about its purpose even though it is not 59 managed by the L{UIRegistrar}. 60 61 @ivar ident: Programmatic identifier for this L{Task} 62 @type ident: string 63 '''
64 - def __init__(self, ident):
65 ''' 66 Stores the L{Task} identifier. 67 68 @param ident: Programmatic identifier 69 @type ident: string 70 ''' 71 Tools.All.__init__(self) 72 self.ident = ident
73
74 - def execute(self, **kwargs):
75 ''' 76 Executes this L{Task} in response to an event. Called by 77 L{Tier.Tier._executeTask}. 78 79 @param kwargs: Dictionary containing parameters passed to a task. 80 @type kwargs: dictionary 81 @return: Should processing continue? Always returns True by default. 82 @rtype: boolean 83 ''' 84 return True
85
86 - def update(self, **kwargs):
87 ''' 88 Allows this L{Task} to update itself in response to an event that was 89 consumed by another L{Task} that executed before it. Called by 90 L{Tier.Tier._executeTask}. 91 92 @param kwargs: Dictionary containing parameters passed to a task. 93 @type kwargs: dictionary 94 ''' 95 pass
96
97 - def getIdentity(self):
98 ''' 99 Gets the unique string identity assigned to this L{Task}. 100 101 @return: Identity of this L{Task} 102 @rtype: string 103 @raise ValueError: When L{ident} is None, meaning this L{Task} has no 104 unique identity 105 ''' 106 if self.ident is None: 107 raise ValueError 108 return self.ident
109
110 - def getPerk(self):
111 ''' 112 Gets the L{Perk} in which this L{Task} was registered. 113 114 @return: Reference to the L{Perk} 115 @rtype: L{Perk} 116 ''' 117 return self.perk
118
119 - def getPath(self):
120 ''' 121 @return: Absolute path location of the module containing the implementor 122 of this interface 123 @rtype: string 124 ''' 125 return UIRegistrar.getPath(self.perk.getClassName())
126