Changeset 288

Show
Ignore:
Timestamp:
03/08/06 01:17:30 (3 years ago)
Author:
athomas
Message:
  • Added interface introspection to the component module.
  • Split cwrite into mono_cwrite and colour_cwrite, which can be used explicitly.
Files:

Legend:

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

    r287 r288  
    2727class ComponentError(Exception): pass 
    2828 
     29class InterfaceMeta(type): 
     30    _interfaces = [] 
     31 
     32    def __new__(cls, name, bases, d): 
     33        new_class = type.__new__(cls, name, bases, d) 
     34        if name != 'Interface': 
     35            InterfaceMeta._interfaces.append(new_class) 
     36        return new_class 
     37 
    2938class Interface(object): 
    3039    """Dummy base class for interfaces. 
     
    3241    (Might use PyProtocols in the future.) 
    3342    """ 
     43    __metaclass__ = InterfaceMeta 
    3444 
    3545class ExtensionPoint(object): 
     
    266276            name of the component to use. """ 
    267277        raise NotImplementedError 
     278 
     279    def get_interfaces(self): 
     280        """ Return all known interfaces. """ 
     281        return InterfaceMeta._interfaces 
  • pycrash/trunk/crash/console.py

    r285 r288  
    1414    pass 
    1515 
    16 if sys.stdout.isatty() and __colour_terminal: 
    17     def cwrite(io, text): 
    18         bold = underline = 0 
    19         out = [] 
    20         for token in __cprint_re.finditer(text): 
    21             if token.group(1): 
    22                 c = token.group(1) 
    23                 if c == 'B': 
    24                     if bold: 
    25                         out.append("") 
    26                     else: 
    27                         out.append("") 
    28                     bold = not bold 
    29                 elif c == 'U': 
    30                     if underline: 
    31                         out.append("") 
    32                     else: 
    33                         out.append("") 
    34                     underline = not underline 
    35                 elif c == 'N': 
    36                     underline = bold = 0 
    37                     out.append("") 
    38                 elif c >= '0' and c <= '7': 
    39                     out.append("[3" + c + "m") 
     16def colour_cwrite(io, text): 
     17    bold = underline = 0 
     18    out = [] 
     19    for token in __cprint_re.finditer(text): 
     20        if token.group(1): 
     21            c = token.group(1) 
     22            if c == 'B': 
     23                if bold: 
     24                    out.append("") 
    4025                else: 
    41                     out.append(token.group(0)) 
     26                    out.append("") 
     27                bold = not bold 
     28            elif c == 'U': 
     29                if underline: 
     30                    out.append("") 
     31                else: 
     32                    out.append("") 
     33                underline = not underline 
     34            elif c == 'N': 
     35                underline = bold = 0 
     36                out.append("") 
     37            elif c >= '0' and c <= '7': 
     38                out.append("[3" + c + "m") 
    4239            else: 
    4340                out.append(token.group(0)) 
    44         for t in out: 
    45             io.write(t) 
    46  
     41        else: 
     42            out.append(token.group(0)) 
     43    for t in out: 
     44        io.write(t) 
     45 
     46def mono_cwrite(io, text): 
     47    io.write(__cprint_strip.sub('', text)) 
     48 
     49if sys.stdout.isatty() and __colour_terminal: 
     50    cwrite = colour_cwrite 
    4751else: 
    48     def cwrite(io, text): 
    49         io.write(__cprint_strip.sub('', text)) 
    50          
    51 cwrite.__doc__ = """ Print using colour escape codes similar to the Quake engine. That is, 
    52         ^0-7 correspond to colours, ^B toggles bold, ^U toggles underline and 
    53         ^N is reset to normal text. Colour is not automatically reset at the 
    54         end of output. """ 
    55  
     52    cwrite = mono_cwrite 
     53 
     54cwrite.__doc__ = """ 
     55Print using colour escape codes similar to the Quake engine. That is, 
     56^0-7 correspond to colours, ^B toggles bold, ^U toggles underline and 
     57^N is reset to normal text. Colour is not automatically reset at the 
     58end of output. 
     59""" 
     60     
    5661def cprint(*args): 
    5762    stream = sys.stdout