Exemple #1
0
    def onStartup(self):
        """
        Initialize plugin.
        """
        if self.console.config.has_option('server', 'delay'):
            self._sftpdelay = self.console.config.getfloat('server', 'delay')
        
        if self.console.config.has_option('server', 'local_game_log'):
            self.lgame_log = self.console.config.getpath('server', 'local_game_log')
        else:
            self.lgame_log = os.path.normpath(os.path.expanduser(self.console.input.name))

        self.lgame_log = b3.getWritableFilePath(self.lgame_log)
        self.debug('local game log is: %s' % self.lgame_log)

        if self.console.config.get('server', 'game_log')[0:7] == 'sftp://':
            self.init_thread(self.console.config.get('server', 'game_log'))

        if self.console.config.has_option('server', 'log_append'):
            self._logAppend = self.console.config.getboolean('server', 'log_append')
        else:
            self._logAppend = False

        # get rid of "no handler found for paramiko.transport" errors
        paramiko_logger = logging.getLogger('paramiko')
        paramiko_logger.handlers = [logging.NullHandler()]
        paramiko_logger.propagate = False
Exemple #2
0
    def onStartup(self):
        """
        Initialize plugin.
        """
        if self.console.config.has_option('server', 'delay'):
            self._sftpdelay = self.console.config.getfloat('server', 'delay')

        if self.console.config.has_option('server', 'local_game_log'):
            self.lgame_log = self.console.config.getpath(
                'server', 'local_game_log')
        else:
            self.lgame_log = os.path.normpath(
                os.path.expanduser(self.console.input.name))

        self.lgame_log = b3.getWritableFilePath(self.lgame_log)
        self.debug('local game log is: %s' % self.lgame_log)

        if self.console.config.get('server', 'game_log')[0:7] == 'sftp://':
            self.init_thread(self.console.config.get('server', 'game_log'))

        if self.console.config.has_option('server', 'log_append'):
            self._logAppend = self.console.config.getboolean(
                'server', 'log_append')
        else:
            self._logAppend = False

        # get rid of "no handler found for paramiko.transport" errors
        paramiko_logger = logging.getLogger('paramiko')
        paramiko_logger.handlers = [logging.NullHandler()]
        paramiko_logger.propagate = False
Exemple #3
0
    def onStartup(self):
        """
        Initialize plugin
        """
        if self.console.config.has_option('server', 'delay'):
            self._gamelog_read_delay = self.console.config.getfloat(
                'server', 'delay')

        if self.console.config.has_option('server', 'local_game_log'):
            self.lgame_log = self.console.config.getpath(
                'server', 'local_game_log')
        else:
            self.lgame_log = os.path.normpath(
                os.path.expanduser(self.console.input.name))

        self.lgame_log = b3.getWritableFilePath(self.lgame_log)
        self.debug('local game log is: %s' % self.lgame_log)

        if self.console.config.get('server', 'game_log')[0:6] == 'ftp://':
            self.init_thread(self.console.config.get('server', 'game_log'))

        if self.console.config.has_option('server', 'log_append'):
            self._logAppend = self.console.config.getboolean(
                'server', 'log_append')
        else:
            self._logAppend = False
Exemple #4
0
    def connect(self):
        """
        Establish and return a connection with the storage layer.
        Will store the connection object also in the 'db' attribute so in the future we can reuse it.
        :return The connection instance if established successfully, otherwise None.
        """
        try:
            import sqlite3
            path = b3.getWritableFilePath(self.dsn[9:])
            self.console.bot("Using database file: %s" % path)
            is_new_database = not os.path.isfile(path)
            self.db = sqlite3.connect(path, check_same_thread=False)
            self.db.isolation_level = None  # set autocommit mode
        except Exception as e:
            self.db = None
            self.console.error('Database connection failed: %s', e)
            if self._consoleNotice:
                self.console.screen.write('Connecting to DB : FAILED\n')
                self._consoleNotice = False
        else:
            # import SQL script if necessary
            if path == ':memory:' or is_new_database:
                self.console.info("Importing SQL file: %s..." %
                                  b3.getAbsolutePath("@b3/sql/sqlite/b3.sql"))
                self.queryFromFile("@b3/sql/sqlite/b3.sql")

            if self._consoleNotice:
                self.console.screen.write('Connecting to DB : OK\n')
                self._consoleNotice = False
        finally:
            return self.db
Exemple #5
0
    def onStartup(self):
        """
        Sets and loads config values from the main config file.
        """
        if self.console.config.has_option('server', 'local_game_log'):
            self.locallog = self.console.config.getpath('server', 'local_game_log')
        else:
            # setup ip addresses
            self._publicIp = self.console.config.get('server', 'public_ip')
            self._port = self.console.config.getint('server', 'port')

            if self._publicIp[0:1] == '~' or self._publicIp[0:1] == '/':
                # load ip from a file
                f = file(self.console.getAbsolutePath(self._publicIp))
                self._publicIp = f.read().strip()
                f.close()

            logext = str(self._publicIp.replace('.', '_'))
            logext = 'games_mp_' + logext + '_' + str(self._port) + '.log'
            self.locallog = os.path.normpath(os.path.expanduser(logext))

        self.locallog = b3.getWritableFilePath(self.locallog)
        self.debug('local game log is :%s' % self.locallog)

        if self.console.config.has_option('server', 'log_append'):
            self._logAppend =self.console.config.getboolean('server', 'log_append')
        else:
            self._logAppend = False

        if self.console.config.has_option('server', 'log_timeout'):
            self.timeout = self.console.config.get('server', 'log_timeout')
        else:
            # get timeout value set by gameservers.com
            try:
                
                req = urllib.request.Request(self._timeout_url)
                req.headers['User-Agent'] = user_agent
                f = urllib.request.urlopen(req)
                self.timeout = int(f.readlines()[0])
                f.close()
                self.debug('using timeout value of %s seconds' % self.timeout)
                
            except (urllib.error.HTTPError, urllib.error.URLError, socket.timeout) as error: 
                self.timeout = self._default_timeout
                self.error('ERROR: %s' % error)
                self.error('ERROR: Couldn\'t get timeout value. Using default %s seconds' % self.timeout)

        if self.console.config.get('server','game_log')[0:7] == 'http://' :
            self._url = self.console.config.get('server','game_log')
            self.initThread()
        else:
            self.error('your game log url doesn\'t seem to be valid: please check your config file')
            self.console.die()
    def onStartup(self):
        """
        Sets and loads config values from the main config file.
        """
        if self.console.config.has_option("server", "local_game_log"):
            self.locallog = self.console.config.getpath("server", "local_game_log")
        else:
            # setup ip addresses
            self._publicIp = self.console.config.get("server", "public_ip")
            self._port = self.console.config.getint("server", "port")

            if self._publicIp[0:1] == "~" or self._publicIp[0:1] == "/":
                # load ip from a file
                f = file(self.console.getAbsolutePath(self._publicIp))
                self._publicIp = f.read().strip()
                f.close()

            logext = str(self._publicIp.replace(".", "_"))
            logext = "games_mp_" + logext + "_" + str(self._port) + ".log"
            self.locallog = os.path.normpath(os.path.expanduser(logext))

        self.locallog = b3.getWritableFilePath(self.locallog)
        self.debug("local game log is :%s" % self.locallog)

        if self.console.config.has_option("server", "log_append"):
            self._logAppend = self.console.config.getboolean("server", "log_append")
        else:
            self._logAppend = False

        if self.console.config.has_option("server", "log_timeout"):
            self.timeout = self.console.config.get("server", "log_timeout")
        else:
            # get timeout value set by gameservers.com
            try:

                req = urllib2.Request(self._timeout_url)
                req.headers["User-Agent"] = user_agent
                f = urllib2.urlopen(req)
                self.timeout = int(f.readlines()[0])
                f.close()
                self.debug("using timeout value of %s seconds" % self.timeout)

            except (urllib2.HTTPError, urllib2.URLError, socket.timeout), error:
                self.timeout = self._default_timeout
                self.error("ERROR: %s" % error)
                self.error("ERROR: Couldn't get timeout value. Using default %s seconds" % self.timeout)
    def onStartup(self):
        """
        Sets and loads config values from the main config file.
        """
        if self.console.config.has_option('server', 'local_game_log'):
            self.locallog = self.console.config.getpath('server', 'local_game_log')
        else:
            # setup ip addresses
            self._publicIp = self.console.config.get('server', 'public_ip')
            self._port = self.console.config.getint('server', 'port')

            if self._publicIp[0:1] == '~' or self._publicIp[0:1] == '/':
                # load ip from a file
                f = file(self.console.getAbsolutePath(self._publicIp))
                self._publicIp = f.read().strip()
                f.close()

            logext = str(self._publicIp.replace('.', '_'))
            logext = 'games_mp_' + logext + '_' + str(self._port) + '.log'
            self.locallog = os.path.normpath(os.path.expanduser(logext))

        self.locallog = b3.getWritableFilePath(self.locallog)
        self.debug('local game log is :%s' % self.locallog)

        if self.console.config.has_option('server', 'log_append'):
            self._logAppend =self.console.config.getboolean('server', 'log_append')
        else:
            self._logAppend = False

        if self.console.config.has_option('server', 'log_timeout'):
            self.timeout = self.console.config.get('server', 'log_timeout')
        else:
            # get timeout value set by gameservers.com
            try:
                
                req = urllib2.Request(self._timeout_url)
                req.headers['User-Agent'] = user_agent
                f = urllib2.urlopen(req)
                self.timeout = int(f.readlines()[0])
                f.close()
                self.debug('using timeout value of %s seconds' % self.timeout)
                
            except (urllib2.HTTPError, urllib2.URLError, socket.timeout), error: 
                self.timeout = self._default_timeout
                self.error('ERROR: %s' % error)
                self.error('ERROR: Couldn\'t get timeout value. Using default %s seconds' % self.timeout)
Exemple #8
0
 def connect(self):
     """
     Establish and return a connection with the storage layer.
     Will store the connection object also in the 'db' attribute so in the future we can reuse it.
     :return The connection instance if established successfully, otherwise None.
     """
     try:
         import sqlite3
         path = b3.getWritableFilePath(self.dsn[9:])
         self.console.bot("Using database file: %s" % path)
         is_new_database = not os.path.isfile(path)
         self.db = sqlite3.connect(path, check_same_thread=False)
         self.db.isolation_level = None  # set autocommit mode
     except Exception, e:
         self.db = None
         self.console.error('Database connection failed: %s', e)
         if self._consoleNotice:
             self.console.screen.write('Connecting to DB : FAILED\n')
             self._consoleNotice = False
 def connect(self):
     """
     Establish and return a connection with the storage layer.
     Will store the connection object also in the 'db' attribute so in the future we can reuse it.
     :return The connection instance if established successfully, otherwise None.
     """
     try:
         import sqlite3
         path = b3.getWritableFilePath(self.dsn[9:])
         self.console.bot("Using database file: %s" % path)
         is_new_database = not os.path.isfile(path)
         self.db = sqlite3.connect(path, check_same_thread=False)
         self.db.isolation_level = None  # set autocommit mode
     except Exception, e:
         self.db = None
         self.console.error('Database connection failed: %s', e)
         if self._consoleNotice:
             self.console.screen.write('Connecting to DB : FAILED\n')
             self._consoleNotice = False
 def _write(self, text):
     if text.strip() == '':
         self._console.warning('AUTODOC: nothing to write')
         
     dsn = splitDSN(self._outputUrl)
     if dsn['protocol'] == 'ftp':
         self._console.debug('AUTODOC: uploading to FTP server %s' % dsn['host'])
         ftp = FTP(dsn['host'], dsn['user'], passwd=dsn['password'])
         ftp.cwd(os.path.dirname(dsn['path']))
         ftpfile = StringIO.StringIO()
         ftpfile.write(text)
         ftpfile.seek(0)
         ftp.storbinary('STOR ' + os.path.basename(dsn['path']), ftpfile)
     elif dsn['protocol'] == 'file':
         path = getWritableFilePath(dsn['path'], True)
         self._console.debug('AUTODOC: writing to %s', path)
         f = file(path, 'w')
         f.write(text)
         f.close()
     else:
         self._console.error('AUTODOC: protocol [%s] is not supported' % dsn['protocol'])
Exemple #11
0
    def onStartup(self):
        """
        Plugin startup.
        """
        if self.console.config.has_option("server", "delay"):
            self._httpdelay = self.console.config.getfloat("server", "delay")

        if self.console.config.has_option("server", "local_game_log"):
            self.lgame_log = self.console.config.getpath("server", "local_game_log")
        else:
            self.lgame_log = os.path.normpath(os.path.expanduser(self.console.input.name))

        self.lgame_log = b3.getWritableFilePath(self.lgame_log)
        self.debug("local game log is: %s" % self.lgame_log)

        if self.console.config.get("server", "game_log")[0:7] == "http://":
            self.initThread(self.console.config.get("server", "game_log"))

        if self.console.config.has_option("server", "log_append"):
            self._logAppend = self.console.config.getboolean("server", "log_append")
        else:
            self._logAppend = False
Exemple #12
0
    def onStartup(self):
        """
        Initialize plugin
        """
        if self.console.config.has_option('server', 'delay'):
            self._gamelog_read_delay = self.console.config.getfloat('server', 'delay')
        
        if self.console.config.has_option('server', 'local_game_log'):
            self.lgame_log = self.console.config.getpath('server', 'local_game_log')
        else:
            self.lgame_log = os.path.normpath(os.path.expanduser(self.console.input.name))

        self.lgame_log = b3.getWritableFilePath(self.lgame_log)
        self.debug('local game log is: %s' % self.lgame_log)

        if self.console.config.get('server', 'game_log')[0:6] == 'ftp://':
            self.init_thread(self.console.config.get('server', 'game_log'))
            
        if self.console.config.has_option('server', 'log_append'):
            self._logAppend = self.console.config.getboolean('server', 'log_append')
        else:
            self._logAppend = False