add vcs-* fields to debian/control
[debian/mudpuppy.git] / modules / base.py
1 class CannotAutomateException(Exception):
2         '''signal from an Automatia that we can't automate this item
3         This is NOT an error. It's just saying that the item cannot
4         be processed by this module.
5
6         This should ONLY be raised if the system state was not changed
7         by the module.
8         '''
9
10 class Automatia(object):
11         '''Base class for anything that can automate an item'''
12         can_handle = []
13
14         def __init__(self, item_state, task_metadata):
15                 self.item_state = item_state
16                 self.task_metadata = task_metadata
17
18         module_name = property(lambda self: self.__class__.__name__)
19
20         @classmethod
21         def can_automate_item(cls, item_state, task_metadata):
22                 '''return if this module can automate an item given item state and task metadata
23
24                 default implementation to return True iff item name is in
25                 cls.can_handle
26
27                 This must be a class method as modules can count on
28                 only being instantiated if they are going to be used
29                 to attempt to automate something
30                 '''
31                 return item_state['name'] in cls.can_handle
32
33         def do_magic(self):
34                 '''automate a build step'''
35                 raise NotImplementedError(self.module_name+'.do_magic()')