Changeset 284

Show
Ignore:
Timestamp:
01/16/06 20:18:36 (3 years ago)
Author:
athomas
Message:
  • Added some useful component introspection methods (get_component_definition() and get_component()).
  • Component Manager? will raise a NotImplementedError if a there is no get_selected_implementation() callback for SelectedExtensionPoint.
  • util.print_table() now takes the header as the first argument, which is more logical.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pycrash/trunk/crash/component.py

    r282 r284  
    225225        return dict((c.__name__, c) for c in ComponentMeta._components \ 
    226226            if hasattr(c, '_implements') and interface in c._implements) 
     227 
     228    def get_component_definition(self, name, interface = None): 
     229        """ Get a component class by name. Does not instantiate the component. """ 
     230        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__) 
     235        for c in ComponentMeta._components: 
     236            if c.__name__ == name: 
     237                return c 
     238        raise ComponentError, 'No component named %s.' % name 
     239 
     240    def get_component(self, name, interface = None): 
     241        """ Get a component instance by name. """ 
     242        return self[self.get_component_definition(name, interface)] 
     243 
     244    def get_selected_implementation(self, interface): 
     245        """ Get the singleton implementation of interface. Should return the 
     246            name of the component to use. """ 
     247        raise NotImplementedError 
  • pycrash/trunk/crash/console.py

    r282 r284  
    179179    return out.rstrip() 
    180180 
    181 def print_table(table, header = None, sep = ' ', auto_format = ['^B^U', '^6', '^B^6'], expand_to_fit = 1): 
     181def print_table(header, table, sep = ' ', auto_format = ['^B^U', '^6', '^B^6'], expand_to_fit = 1): 
    182182    """Print a list of lists as a table, so that columns line up nicely. 
    183183    header, if specified, will be printed as the first row. sep is the 
  • pycrash/trunk/crash/decorators.py

    r282 r284  
    11import inspect, re, types 
     2 
     3__all__ = [ 'validate', 'abstract', 'default_members' ] 
    24 
    35class validate: 
  • pycrash/trunk/crash/__init__.py

    r268 r284  
     1import classmaker, component, console, decorators, loader, network, \ 
     2    singleton, threadpool, util 
  • pycrash/trunk/crash/network.py

    r279 r284  
    1414         
    1515        For the purposes of this class, an "int" representation of a network is 
    16         the 32-bit raw integer form (eg. 4294967168L), "cidr" is the number of bits in a  
    17         netmask (eg. 26) and dq is the full dotted-quad form (eg. 10.2.3.4). 
     16        the 32-bit raw integer form (eg. 4294967168L), "cidr" is the number of 
     17        bits in a netmask (eg. 26) and dq is the full dotted-quad form (eg. 
     18        10.2.3.4). 
    1819    """ 
    1920