Changeset 57 for trunk/factory/src/backends/__init__.py
- Timestamp:
- 02/03/09 15:51:59 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/factory/src/backends/__init__.py
r56 r57 20 20 """ 21 21 22 class BackendException: 23 """ 24 A base Backend exception class. Backends should derive their own 25 exceptions from this. 26 27 When the Factory catches this exception and recoverable is False, then 28 the backend will be unloaded. 29 """ 30 def __init__(self, message, recoverable = False): 31 self.message = message 32 self.recoverable = recoverable 33 34 def __str__(self): 35 if self.recoverable: 36 return self.message + ' (Recoverable)' 37 return self.message + ' (Not recoverable)' 38 22 39 class Backend: 40 """ 41 The base backend class. Backends shoudl derive from this 42 """ 23 43 def __init__(self, options, config, section): 24 44 self.options = options 25 45 self.config = config 26 46 self.section = section 47 48 self.application = config.get(section, 'application') 49 self.major = config.get(section, 'major') 50 self.minor = config.get(section, 'minor') 51 self.doctype = config.get(section, 'doctype') 52 self.formats = [s.strip() for s in config.get(section, 'formats').split(',')] 53 54 def initialize(self): 55 """ 56 This is called right after instanciating the backend. 57 Returning False will cause the backend not to be loaded 58 """ 59 return True 60 61 def can_process(self, job): 62 """ 63 Return True if this backend is eligable to process this Job, False otherwise 64 """ 65 eligable = ( 66 job['application'] == self.application and 67 job['major'] == self.major and 68 job['minor'] == self.minor and 69 job['doctype'] == self.doctype and 70 job['format'] in self.formats 71 ) 72 return eligable 73 74 def process(self, job): 75 """ 76 Process a job. Backends must override this method. 77 """ 78 raise NotImplementedError
Note: See TracChangeset
for help on using the changeset viewer.