Changeset 287
- Timestamp:
- 03/07/06 02:29:52 (3 years ago)
- Files:
-
- pycrash/trunk/crash/attrtree.py (added)
- pycrash/trunk/crash/component.py (modified) (3 diffs)
- pycrash/trunk/crash/loader.py (modified) (3 diffs)
- pycrash/trunk/crash/util.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pycrash/trunk/crash/component.py
r284 r287 22 22 # Christopher Lenz <cmlenz@gmx.de> 23 23 24 __all__ = ['Component', 'ComponentManager', 'ExtensionPoint', 'implements', 25 'SelectedExtensionPoint', 'Interface', 'ComponentError'] 26 24 27 class ComponentError(Exception): pass 25 26 __all__ = ['Component', 'ComponentManager', 'ExtensionPoint', 'implements',27 'SelectedExtensionPoint', 'Interface']28 28 29 29 class Interface(object): … … 81 81 raise ComponentError("can't find selected interface '%s' named '%s'" % (xtnpt.interface.__name__, seek)) 82 82 else: 83 raise ComponentError("no component active for '%s' interface" % xtnpt.interface.__name__)83 raise ComponentError("no component active for interface '%s'" % xtnpt.interface.__name__) 84 84 85 85 class ComponentMeta(type): … … 220 220 221 221 def get_implementors(self, interface): 222 """ Get all component classes that implement a particular interface as 223 a dictionary, with the class name as the key and the class itself as 224 the value. Does not instantiate the component. """ 225 return dict((c.__name__, c) for c in ComponentMeta._components \ 226 if hasattr(c, '_implements') and interface in c._implements) 222 """ Get all component classes that implement a particular interface. 223 Does not instantiate the component. """ 224 return [c for c in ComponentMeta._components 225 if hasattr(c, '_implements') and interface in c._implements] 226 227 def get_components(self): 228 """ Get all components. """ 229 return ComponentMeta._components[:] 230 231 def get_interfaces(self): 232 """ Get all available interfaces. """ 233 interfaces = [] 234 for c in self.get_components(): 235 if hasattr(c, '_implements'): 236 for i in c._implements: 237 if i not in interfaces: 238 interfaces.append(i) 239 return interfaces 240 241 def get_provided_interfaces(self, component): 242 """ Get interfaces that a component provides. """ 243 if hasattr(component, '_implements'): 244 return component._implements[:] 245 return [] 227 246 228 247 def get_component_definition(self, name, interface = None): 229 248 """ Get a component class by name. Does not instantiate the component. """ 230 249 if interface is not None: 231 try: 232 return get_implementors(interface)[name] 233 except KeyError: 234 raise ComponentError, 'No component named %s implementing %s.' % (name, interface.__name__) 250 implementors = self.get_implementors(interface) 251 for i in implementors: 252 if i.__name__ == name: 253 return i 254 raise ComponentError, 'No component named %s implementing %s.' % (name, interface.__name__) 235 255 for c in ComponentMeta._components: 236 256 if c.__name__ == name: pycrash/trunk/crash/loader.py
r286 r287 8 8 raise KeyError 9 9 except KeyError: 10 # The last [''] is very important! 11 a_mod = __import__(module_path, globals(), locals(), ['']) 10 a_mod = __import__(module_path) 12 11 sys.modules[module_path] = a_mod 13 12 return a_mod … … 51 50 def load_all(module): 52 51 """ Load all python modules in a module directory. Returns a tuple of 53 (success, failed) modules. """ 52 (success, failed) modules. Failed is a list of (module, exception, 53 traceback) tuples. """ 54 from crash.util import traceback_string 54 55 from dircache import listdir 55 56 import os … … 69 70 succeeded.append(m) 70 71 except Exception, e: 71 failed.append((plugin, e ))72 failed.append((plugin, e, traceback_string(e))) 72 73 return (succeeded, failed) pycrash/trunk/crash/util.py
r283 r287 532 532 """ Replace all instances of old in seq with new """ 533 533 return [x == old and new or old for x in seq] 534 535 def dict_diff(old, new): 536 """ Return tuple of (added, modified, deleted) keys between two 537 dictionaries. """ 538 try: 539 set = set 540 except: 541 from sets import Set as set 542 all_keys = set(old.keys()).union(new.keys()) 543 added = [] 544 modified = [] 545 deleted = [] 546 for key in all_keys: 547 if key in new: 548 if key in old: 549 if new[key] != old[key]: 550 modified.append(key) 551 else: 552 added.append(key) 553 else: 554 deleted.append(key) 555 return added, modified, deleted 556
