fixbot/module.py
changeset 64 8574aeff9b36
parent 62 e4db89a5f6bc
equal deleted inserted replaced
63:a849c00b63f8 64:8574aeff9b36
    11 
    11 
    12     # module's name
    12     # module's name
    13     name = None
    13     name = None
    14 
    14 
    15     def __str__ (self) :
    15     def __str__ (self) :
    16         return "Module %s:" % (self.name)
    16         return "%s" % (self.name)
    17     
    17     
    18     def __repr__ (self) :
    18     def __repr__ (self) :
    19         return "<module %s>" % (self.name, )
    19         return "<module %s>" % (self.name, )
    20 
    20 
    21 
    21 
    68 
    68 
    69         self.connection = None
    69         self.connection = None
    70 
    70 
    71         # XXX: legacy: self.secret = config['api-secret']
    71         # XXX: legacy: self.secret = config['api-secret']
    72 
    72 
       
    73 
    73     def _onRegistered (self, connection) :
    74     def _onRegistered (self, connection) :
    74         """
    75         """
    75             Connected to nexus and registered
    76             Connected to nexus and registered
    76         """
    77         """
    77 
    78 
    78         log.msg("Connected and registered")
    79         log.msg("Connected and registered")
    79 
    80 
    80         self.connection = connection
    81         self.connection = connection
    81 
    82         
       
    83         # XXX: abort on errors?
    82         self.handleConnect()
    84         self.handleConnect()
    83 
    85 
       
    86     
       
    87     # XXX: unused, bad interface
    84     def disconnect (self) :
    88     def disconnect (self) :
    85         """
    89         """
    86             Disconnect from Nexus
    90             Disconnect from Nexus
    87         """
    91         """
    88 
    92 
    89         self.connection.transport.loseConnection()
    93         self.connection.transport.loseConnection()
    90     
    94 
       
    95 
    91     def sendEvent (self, type, msg) :
    96     def sendEvent (self, type, msg) :
    92         """
    97         """
    93             Send event to nexus
    98             Send event to nexus
    94         """
    99         """
    95 
   100 
    96         self.connection.sendEvent(Event(self, type, msg))
   101         self.connection.sendEvent(Event(self, type, msg))
    97 
   102 
       
   103 
    98     def handleConnect (self) :
   104     def handleConnect (self) :
    99         """
   105         """
   100             Do something once we are connected to nexus and registered
   106             Do something once we are connected to nexus and registered
   101         """
   107         """
   102 
   108 
   103         pass
   109         pass
       
   110 
       
   111     def abort (self, err) :
       
   112         """
       
   113             Abort this module, disconnecting with the given error
       
   114         """
       
   115 
       
   116         self.connection.abort(str(err))
   104 
   117 
   105 def makeService (module_class, config, protocol) :
   118 def makeService (module_class, config, protocol) :
   106     s = service.MultiService()
   119     s = service.MultiService()
   107 
   120 
   108     # build factory
   121     # build factory