コード例 #1
0
ファイル: __init__.py プロジェクト: felipebusnello/neubot
    def connection(self):
        if not self.dbc:
            if self.path != ":memory:":
                self.path = system.check_database_path(self.path, logging.error)
            logging.debug("* Database: %s", self.path)
            self.dbc = sqlite3.connect(self.path)

            #
            # To avoid the need to map at hand columns in
            # a row with the sql schema, which is as error
            # prone as driving drunk.
            #
            self.dbc.row_factory = sqlite3.Row

            #
            # Migrate MUST be before table creation.  This
            # is safe because table creation always uses
            # the IF NOT EXISTS clause.  And this is needed
            # because otherwise we cannot migrate archived
            # databases (whose version number is old).
            # The exception is the config table which must
            # be present because migrate() looks at it.
            #
            table_config.create(self.dbc)

            migrate.migrate(self.dbc)
            migrate2.migrate(self.dbc)

            table_speedtest.create(self.dbc)
            table_geoloc.create(self.dbc)
            table_bittorrent.create(self.dbc)
            table_log.create(self.dbc)

        return self.dbc
コード例 #2
0
ファイル: __init__.py プロジェクト: EverlastingFire/neubot
    def connection(self):
        ''' Return connection to database '''
        if not self.dbc:
            database_xxx.linux_fixup_databasedir()
            if self.path != ":memory:":
                self.path = system.check_database_path(self.path)

            logging.debug("* Database: %s", self.path)
            self.dbc = sqlite3.connect(self.path)

            #
            # To avoid the need to map at hand columns in
            # a row with the sql schema, which is as error
            # prone as driving drunk.
            #
            self.dbc.row_factory = sqlite3.Row

            #
            # On POSIX systems, neubot (initially) runs as root, to ensure that
            # database location, ownership and permissions are OK (as well as
            # to bind privileged ports).  But neubot can also be started by
            # normal users.  In this case, mark the database as readonly since
            # write operation are going to raise exceptions.
            #
            if not system.has_enough_privs():
                logging.warning('database: opening database in readonly mode')
                self.readonly = True
                return self.dbc

            #
            # Migrate MUST be before table creation.  This
            # is safe because table creation always uses
            # the IF NOT EXISTS clause.  And this is needed
            # because otherwise we cannot migrate archived
            # databases (whose version number is old).
            # The exception is the config table which must
            # be present because migrate() looks at it.
            #
            table_config.create(self.dbc)

            migrate.migrate(self.dbc)
            migrate2.migrate(self.dbc)

            table_speedtest.create(self.dbc)
            table_geoloc.create(self.dbc)
            table_bittorrent.create(self.dbc)
            table_log.create(self.dbc)
            table_raw.create(self.dbc)

        return self.dbc
コード例 #3
0
ファイル: __init__.py プロジェクト: ClaudioArtusio/neubot
    def connection(self):
        if not self.dbc:
            if self.path != ":memory:":
                self.path = system.check_database_path(self.path, logging.error)
            logging.debug("* Database: %s" % self.path)
            self.dbc = sqlite3.connect(self.path)
            #
            # To avoid the need to map at hand columns in
            # a row with the sql schema, which is as error
            # prone as driving drunk.
            #
            self.dbc.row_factory = sqlite3.Row
            table_config.create(self.dbc)
            table_speedtest.create(self.dbc)
            table_geoloc.create(self.dbc)
            table_bittorrent.create(self.dbc)
            table_log.create(self.dbc)
            migrate.migrate(self.dbc)

        return self.dbc