Пример #1
0
    def _configLogs(self, botConfig):
        """
        This method configure the logs for this object. 

        Two handlers are used, one to print to stdout and one to log in a file. For file, TimedRotatingFileHandler is used to rotate the log file every day. 
        @param botConfig: Bot config to use to customize logging
        @type botConfig: ConfigParser
        """
        config = CNBConfig.getInstance()

        # Print output if not in daemon mode
        if not config.get('global', 'daemon'):
            ch = logging.StreamHandler()
            ch.setFormatter(logging.Formatter(config.get('global', 'log-format')))
            self.log.addHandler(ch)

        # Write also to file
        fh = TimedRotatingFileHandler(os.path.join(config.get('global', 'log-dir'), \
                botConfig.get('bot', 'log-file')), \
                backupCount=0, \
                when='d', \
                interval=1)
        fh.setFormatter(logging.Formatter(config.get('global', 'log-format')))
        self.log.addHandler(fh)
       
        # Set log level
        if botConfig.get('bot', 'verbose') == '1':
            self.log.setLevel(logging.DEBUG)
        else:
            self.log.setLevel(logging.INFO)
Пример #2
0
    def _configLogs(self, sFile):
        """
        This method configure the logs for this object. 

        Two handlers are used, one to print to stdout and one to log in a file. For file, TimedRotatingFileHandler is used to rotate the log file every day. 

        @param sFile: Log file name
        @type sFile: string
        @todo: Set log level from config or user input
        """
        config = CNBConfig.getInstance()

        # Print output if not in daemon mode
        if not config.get('global', 'daemon'):
            ch = logging.StreamHandler()
            ch.setFormatter(logging.Formatter(config.get('global', 'log-format')))
            self.log.addHandler(ch)

        # Write also to file
        fh = TimedRotatingFileHandler(\
            os.path.join(config.get('global', 'log-dir'), sFile), \
            backupCount=0, \
            when='d', \
            interval=1)
        fh.setFormatter(logging.Formatter(config.get('global', 'log-format')))
        self.log.addHandler(fh)
       
        # Must stay at DEBUG to log errors
        self.log.setLevel(logging.DEBUG)
Пример #3
0
    def _configLogs(self, sFile):
        """
        This method configure the logs for this object. 

        Two handlers are used, one to print to stdout and one to log in a file. For file, TimedRotatingFileHandler is used to rotate the log file every day. 

        @param sFile: Log file name
        @type sFile: string
        @todo: Set log level from config or user input
        """
        config = CNBConfig.getInstance()

        # Print output if not in daemon mode
        if not config.get('global', 'daemon'):
            ch = logging.StreamHandler()
            ch.setFormatter(
                logging.Formatter(config.get('global', 'log-format')))
            self.log.addHandler(ch)

        # Write also to file
        fh = TimedRotatingFileHandler(\
            os.path.join(config.get('global', 'log-dir'), sFile), \
            backupCount=0, \
            when='d', \
            interval=1)
        fh.setFormatter(logging.Formatter(config.get('global', 'log-format')))
        self.log.addHandler(fh)

        # Must stay at DEBUG to log errors
        self.log.setLevel(logging.DEBUG)
Пример #4
0
    def _configLogs(self, botConfig):
        """
        This method configure the logs for this object. 

        Two handlers are used, one to print to stdout and one to log in a file. For file, TimedRotatingFileHandler is used to rotate the log file every day. 
        @param botConfig: Bot config to use to customize logging
        @type botConfig: ConfigParser
        """
        config = CNBConfig.getInstance()

        # Print output if not in daemon mode
        if not config.get('global', 'daemon'):
            ch = logging.StreamHandler()
            ch.setFormatter(
                logging.Formatter(config.get('global', 'log-format')))
            self.log.addHandler(ch)

        # Write also to file
        fh = TimedRotatingFileHandler(os.path.join(config.get('global', 'log-dir'), \
                botConfig.get('bot', 'log-file')), \
                backupCount=0, \
                when='d', \
                interval=1)
        fh.setFormatter(logging.Formatter(config.get('global', 'log-format')))
        self.log.addHandler(fh)

        # Set log level
        if botConfig.get('bot', 'verbose') == '1':
            self.log.setLevel(logging.DEBUG)
        else:
            self.log.setLevel(logging.INFO)
Пример #5
0
    def __init__(self, botConfig):
        CNBCon.__init__(self, botConfig)
        config = CNBConfig.getInstance()

        self._username = botConfig.get('bot', 'username')
        self._password = botConfig.get('bot', 'password')
        server = botConfig.get('bot', 'server')
        self._rooms = botConfig.get('bot', 'rooms')
        self._autostart = botConfig.get('bot', 'auto-start')
        self.autoReconnect = botConfig.get('bot', 'auto-reconnect')
        self._res = self.__class__.__name__
        if server == '':
            #self.jid = xmpp.JID(self._username)
            self.log.info('Not server specified')
        else:
            #self.jid = xmpp.JID(self._username, server)
            self.log.info('Server specified: ' + server)

        if self._autostart == '1':
            self.log.info('Auto-start = 1')
            self.startBot()

        if self.autoReconnect == '1':
            self.log.info('Auto-reconnect = 1')

        # GTalk specificity
        if botConfig.get('bot','type') == 'xmpp-gtalk':
            self._initMondaySuckRoom()
Пример #6
0
 def loadDefault(self):
     """
     This method load the default connectors from the "cnb.conf" file.
     """
     config = CNBConfig.getInstance()
     aList = config.get('connectors', 'auto')
     sConfigFolder = config.get('global', 'config-dir')
     if sConfigFolder[len(sConfigFolder)-1] != '/':
         sConfigFolder = sConfigFolder + '/'
     for s in aList:
         oCon = self.loadFromFile(sConfigFolder + s)
         if oCon:
             self.log.info('Appending oCon.id = ' + str(oCon.getConfig().get('bot', 'id')))
             self._aConList.append(oCon)
Пример #7
0
 def loadFromFile(self,sFile):
     """
     This method load a Connector object from a file
     @param sFile: File containing the connector configuration (Ex: conf/name.type.conf)
     @type sFile: String
     """
     config = CNBConfig.getInstance()
     self.log.info('Loading instance: "' + sFile + '"')
     botConfig = RawConfigParser()
     try:
         botConfig.readfp(open(sFile))
         botConfig = self._normalize(botConfig)
     except Exception, e:
         self.log.error('Could not open config file: ' + sFile)
         self.log.exception(e)
         botConfig = None
         return None
Пример #8
0
    def __init__(self):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        if oConfig.get('global', 'daemon'):
            self._bEnableShellConsole = False
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)

        oMgr = CNBManager.getInstance()
        oMgr.setCNB(self)

        self.oConMgr = CNBConnectorManager()
        self.oConMgr.loadDefault()

        if self._bEnableShellConsole:
            self.oConsole = CNBConsole()
            self.oConsole.start()

        oMatrix = CNBMatrix.getInstance()
Пример #9
0
    def __init__(self):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        if oConfig.get('global', 'daemon'):
            self._bEnableShellConsole = False
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)

        oMgr = CNBManager.getInstance()
        oMgr.setCNB(self)

        self.oConMgr = CNBConnectorManager()
        self.oConMgr.loadDefault()

        if self._bEnableShellConsole:
            self.oConsole = CNBConsole()
            self.oConsole.start()

        oMatrix = CNBMatrix.getInstance()
Пример #10
0
    def __init__(self):
        Thread.__init__(self)
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs('cnb-console.log')
    
        config = CNBConfig.getInstance()
        for name, value in inspect.getmembers(self):
            if inspect.ismethod(value) and getattr(value, '_console_cmd', False) and getattr(value, '_console_type') == None:
                name = getattr(value, '_console_cmd_name')
                self.log.info('Registered console command: %s' % name)
                self._cmds[name] = value

            if inspect.ismethod(value) and getattr(value, '_console_cmd', False) and getattr(value, '_console_type') == 'xmpp':
                name = getattr(value, '_console_cmd_name')
                self.log.info('Registered xmpp console command: %s' % name)
                self._cmdsXmpp[name] = value

            if inspect.ismethod(value) and getattr(value, '_console_cmd', False) and getattr(value, '_console_type') == 'irc':
                name = getattr(value, '_console_cmd_name')
                self.log.info('Registered irc console command: %s' % name)
                self._cmdsIrc[name] = value
Пример #11
0
    def __init__(self, botConfig):
        CNBCon.__init__(self, botConfig)
        config = CNBConfig.getInstance()

        username = botConfig.get('bot', 'username')
        nickname = username
        realname = username
        channels = botConfig.get('bot', 'channels')
        password = botConfig.get('bot', 'password')
        server = botConfig.get('bot', 'server')
        autostart = botConfig.get('bot', 'auto-start')
        autoreconnect = botConfig.get('bot', 'auto-reconnect')
        reconInterval = 60

        self.ircobj = IRC()
        self.connection = self.ircobj.server()
        self.dcc_connections = []
        self.ircobj.add_global_handler("all_events", self._dispatcher, -10)
        #self.ircobj.add_global_handler("dcc_disconnect", self._dcc_disconnect, -10)

        self.autoReconnect = autoreconnect
        self.server_list.append([server, self.IRC_PORT])
        self.channelsToJoin = channels

        self.channels = IRCDict()
        if not reconInterval or reconInterval < 0:
            reconInterval = 2**31
        self.reconInterval = reconInterval

        self._nickname = nickname
        self._realname = realname
        self._password = password

        if autostart == '1':
            self.log.info('Auto-start = 1')
            self.startBot()

        if autoreconnect == '1':
            self.log.info('Auto-reconnect = 1')
Пример #12
0
    def __init__(self, botConfig):
        CNBCon.__init__(self, botConfig)
        config = CNBConfig.getInstance()

        username = botConfig.get('bot', 'username')
        nickname = username
        realname = username
        channels = botConfig.get('bot', 'channels')
        password = botConfig.get('bot', 'password')
        server = botConfig.get('bot', 'server')
        autostart = botConfig.get('bot', 'auto-start')
        autoreconnect = botConfig.get('bot', 'auto-reconnect')
        reconInterval = 60

        self.ircobj = IRC()
        self.connection = self.ircobj.server()
        self.dcc_connections = []
        self.ircobj.add_global_handler("all_events", self._dispatcher, -10)
        #self.ircobj.add_global_handler("dcc_disconnect", self._dcc_disconnect, -10)

        self.autoReconnect = autoreconnect
        self.server_list.append([server, self.IRC_PORT])
        self.channelsToJoin = channels

        self.channels = IRCDict()
        if not reconInterval or reconInterval < 0:
            reconInterval = 2**31
        self.reconInterval = reconInterval

        self._nickname = nickname
        self._realname = realname
        self._password = password

        if autostart == '1':
            self.log.info('Auto-start = 1')
            self.startBot()

        if autoreconnect == '1':
            self.log.info('Auto-reconnect = 1')
Пример #13
0
    def _configLogs(self):
        """
        This method configure the logs for this object. 

        Two handlers are used, one to print to stdout and one to log in a file. For file, TimedRotatingFileHandler is used to rotate the log file every day. 
        """
        config = CNBConfig.getInstance()

        # Print output if not in daemon mode
        if not config.get('global', 'daemon'):
            ch = logging.StreamHandler()
            ch.setFormatter(logging.Formatter(config.get('global', 'log-format')))
            self.log.addHandler(ch)

        # Write also to file
        fh = TimedRotatingFileHandler(\
            os.path.join(config.get('global', 'log-dir'), 'cnb-conmanager.log'), \
            backupCount=0, \
            when='d', \
            interval=1)
        fh.setFormatter(logging.Formatter(config.get('global', 'log-format')))
        self.log.addHandler(fh)
        
        self.log.setLevel(logging.INFO)