def add_service(self, svc_class): name = svc_class.service_name log("Starting %s" % name) service = svc_class(self) self._register_listeners(service) log("%s started." % name) service.setServiceParent(self.application) self._services[name] = service
def add_service(self, svc_cls): name = svc_cls.service_name log('Starting ' + name) service = svc_cls(self) self._register_listeners(service) log(name + ' started.') service.setName(name) service.setServiceParent(self.application)
def _unregister_listeners(self, service): ''' Unregisters all event handlers for a service. ''' signalmatrix = service.get_signal_matrix() for signal, handler in signalmatrix.items(): try: self.signals[signal].unregister(handler) except KeyError: log("couln't find a '%s' signal to unregister" % signal)
def _register_listeners(self, service): ''' Registers all event handlers for a service. ''' signalmatrix = service.get_signal_matrix() for signal, handler in signalmatrix.items(): try: #Register the service's handler to the event system's signal self.signals[signal].register(handler) except KeyError: log("couldnt find a '%s' signal for registration" % signal)
def setupDB(self): # we hide the db so that methods always access it only through # this method since db objects can be silently reaped when not # in use. db objects consume 5 file descriptors. if self.db is None: self._setupDB() # self.qp = xapian.QueryParser() # this is vital: these options specify no language for # stemming (""), disable stemming (False), and specify an # empty stop word object (None). we need this because by # default, xapian's query parser does english stemming # s = xapian.Stem(self.STEMMING_LANGUAGE) # self.qp.set_stemmer(s) # we want query terms to be ANDed together by default # self.qp.set_default_op(self.DEFAULT_QUERY_COMBINER_OP) self._configure() log("Index %s contains %s documents" % (self.names, self.get_doccount()))
def _setupDB(self): """ really get a xapian database object """ # xapian expects directories! self.name should refer to a # directory. if it doesn't exist, we'll make one. if not os.path.exists(self.name): os.mkdir(self.name) # try to acquire a lock file if not self.lockFile.lock(): owningPid = os.readlink(self.lockFile.name) errorMsg = "cannot acquire lock file for xapian index %s" "because it is owned by process %s" % ( self.name, owningPid, ) log(errorMsg) raise DatabaseLockError(errorMsg) xapLockFilePath = os.path.join(self.name, XAPIAN_LOCK_FILENAME) if os.path.exists(xapLockFilePath): log("Stale database lock found in %s. Deleting it now." % xapLockFilePath) os.remove(xapLockFilePath) # actually try to open a xapian DB try: try: self.db = ExceptionTranslater.openIndex(False, self.name, self.flags) except DatabaseCorruptionError, e: # the index is trashed, so there's no harm in blowing it # away and starting from scratch log("Xapian index at %s is corrupted and will be destroyed" % self.name) if self.lockFile.locked: self.lockFile.unlock() for idxFname in glob.glob(os.path.join(self.name, "*")): os.remove(idxFname) self.db = ExceptionTranslater.openIndex(False, self.name, self.flags) finally: if self.db is None and self.lockFile.locked: self.lockFile.unlock()
def close(self): log("closing xapian index %s" % self.names) for query in self._searchSessions.keys(): del self._searchSessions[query] self.qp = None self.db = None
def left(self, channel): log('Parted %s' % channel)
def joined(self, channel): log('Joined %s' % channel) self.engine.set_channel(channel)
def dccDoChat(self, user, channel, address, port, data): log('Dcc Chat Request: %s, %s, %s' % (user, address, port)) log('Dcc Chat Request Data: %s' % data)
def dlog(message): if __debug__: trace = traceback.extract_stack()[-2] file, line, name = trace[0], trace[1], trace[2] log('[%s:%s "%s"] %s' % (file.split("/")[-1], line, name, message))