本文整理汇总了Python中Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB.initialize方法的典型用法代码示例。如果您正苦于以下问题:Python SQLiteCacheDB.initialize方法的具体用法?Python SQLiteCacheDB.initialize怎么用?Python SQLiteCacheDB.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB
的用法示例。
在下文中一共展示了SQLiteCacheDB.initialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AbstractDB
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import initialize [as 别名]
class AbstractDB(AbstractServer):
def setUp(self):
super(AbstractDB, self).setUp()
# dummy session
self.config = SessionStartupConfig()
self.config.set_state_dir(self.getStateDir())
self.config.set_torrent_checking(False)
self.config.set_multicast_local_peer_discovery(False)
self.config.set_megacache(False)
self.config.set_dispersy(False)
self.config.set_mainline_dht(False)
self.config.set_torrent_collecting(False)
self.config.set_libtorrent(False)
self.config.set_dht_torrent_collecting(False)
self.config.set_videoplayer(False)
self.config.set_torrent_store(False)
self.session = Session(self.config, ignore_singleton=True)
dbpath = init_bak_tribler_sdb('bak_new_tribler.sdb', destination_path=self.getStateDir(), overwrite=True)
self.sqlitedb = SQLiteCacheDB(self.session, busytimeout=BUSYTIMEOUT)
self.sqlitedb.initialize(dbpath)
self.session.sqlite_db = self.sqlitedb
@blocking_call_on_reactor_thread
def tearDown(self):
self.sqlitedb.close()
self.sqlitedb = None
self.session.del_instance()
self.session = None
super(AbstractDB, self).tearDown(self)
示例2: TestSqliteCacheDB
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import initialize [as 别名]
class TestSqliteCacheDB(AbstractServer):
def setUp(self):
super(TestSqliteCacheDB, self).setUp()
self.config = SessionStartupConfig()
self.config.set_state_dir(self.getStateDir())
self.config.set_torrent_checking(False)
self.config.set_multicast_local_peer_discovery(False)
self.config.set_megacache(False)
self.config.set_dispersy(False)
self.config.set_mainline_dht(False)
self.config.set_torrent_collecting(False)
self.config.set_libtorrent(False)
self.config.set_dht_torrent_collecting(False)
self.config.set_videoplayer(False)
self.session = Session(self.config, ignore_singleton=True)
self.sqlitedb = None
def tearDown(self):
super(TestSqliteCacheDB, self).tearDown()
if self.sqlitedb:
self.sqlitedb.close()
self.sqlitedb = None
self.session.del_instance()
self.session = None
def test_upgrade_from_obsolete_version(self):
"""We no longer support DB versions older than 17 (Tribler 6.0)"""
dbpath = init_bak_tribler_sdb(u"bak_old_tribler.sdb", destination_path=self.getStateDir(), overwrite=True)
self.sqlitedb = SQLiteCacheDB(self.session)
self.sqlitedb.initialize(dbpath)
class MockTorrentStore(object):
def flush():
pass
def close():
pass
db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=MockTorrentStore())
self.assertRaises(VersionNoLongerSupportedError, db_migrator.start_migrate)
def test_upgrade_from_17(self):
pass
示例3: Session
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import initialize [as 别名]
#.........这里部分代码省略.........
scfg.set_torrent_checking(0)
self.sessconfig = scfg.sessconfig
self.sessconfig.lock = self.sesslock
self.selected_ports = scfg.selected_ports
# Claim all random ports
self.get_listen_port()
self.get_dispersy_port()
self.get_mainline_dht_listen_port()
self.get_videoplayer_port()
self.get_anon_listen_port()
self.get_tunnel_community_socks5_listen_ports()
# Create handler for calling back the user via separate threads
self.lm = TriblerLaunchMany()
self.notifier = Notifier(use_pool=True)
# Checkpoint startup config
self.save_pstate_sessconfig()
self.sqlite_db = None
self.autoload_discovery = autoload_discovery
def prestart(self):
"""
Pre-starts the session. We check the current version and upgrade if needed
- before we start everything else.
"""
self.sqlite_db = SQLiteCacheDB(self)
self.sqlite_db.initialize()
self.sqlite_db.initial_begin()
self.upgrader = TriblerUpgrader(self, self.sqlite_db)
self.upgrader.run()
return self.upgrader
#
# Class methods
#
@staticmethod
def get_instance(*args, **kw):
""" Returns the Session singleton if it exists or otherwise
creates it first, in which case you need to pass the constructor
params.
@return Session."""
if Session.__single is None:
Session(*args, **kw)
return Session.__single
@staticmethod
def has_instance():
return Session.__single is not None
@staticmethod
def del_instance():
Session.__single = None
#
# Public methods
#
def start_download(self, tdef, dcfg=None, initialdlstatus=None, hidden=False):
"""
Creates a Download object and adds it to the session. The passed
示例4: TestSqliteCacheDB
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import initialize [as 别名]
class TestSqliteCacheDB(AbstractServer):
def setUp(self):
super(TestSqliteCacheDB, self).setUp()
self.config = SessionStartupConfig()
self.config.set_state_dir(self.getStateDir())
self.config.set_torrent_checking(False)
self.config.set_multicast_local_peer_discovery(False)
self.config.set_megacache(False)
self.config.set_dispersy(False)
self.config.set_mainline_dht(False)
self.config.set_torrent_collecting(False)
self.config.set_libtorrent(False)
self.config.set_dht_torrent_collecting(False)
self.config.set_videoplayer(False)
self.session = Session(self.config, ignore_singleton=True)
self.sqlite_test = SQLiteCacheDB(self.session)
self.db_path = u":memory:"
self.sqlite_test.initialize(self.db_path)
def tearDown(self):
super(TestSqliteCacheDB, self).tearDown()
self.sqlite_test.close()
self.sqlite_test = None
self.session.del_instance()
self.session = None
@blocking_call_on_reactor_thread
def test_create_db(self):
sql = u"CREATE TABLE person(lastname, firstname);"
self.sqlite_test.execute(sql)
@blocking_call_on_reactor_thread
def test_insert(self):
self.test_create_db()
self.sqlite_test.insert('person', lastname='a', firstname='b')
assert self.sqlite_test.size('person') == 1
@blocking_call_on_reactor_thread
def test_fetchone(self):
self.test_insert()
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
assert one == ('a', 'b')
one = self.sqlite_test.fetchone(u"SELECT lastname FROM person WHERE firstname == 'b'")
assert one == 'a'
one = self.sqlite_test.fetchone(u"SELECT lastname FROM person WHERE firstname == 'c'")
assert one is None
@blocking_call_on_reactor_thread
def test_insertmany(self):
self.test_create_db()
values = []
for i in range(100):
value = (str(i), str(i ** 2))
values.append(value)
self.sqlite_test.insertMany('person', values)
assert self.sqlite_test.size('person') == 100
@blocking_call_on_reactor_thread
def test_fetchall(self):
self.test_insertmany()
all = self.sqlite_test.fetchall('select * from person')
assert len(all) == 100
all = self.sqlite_test.fetchall("select * from person where lastname=='101'")
assert all == []
@blocking_call_on_reactor_thread
def test_insertorder(self):
self.test_insertmany()
self.sqlite_test.insert('person', lastname='1', firstname='abc')
one = self.sqlite_test.fetchone("select firstname from person where lastname == '1'")
assert one == '1' or one == 'abc'
all = self.sqlite_test.fetchall("select firstname from person where lastname == '1'")
assert len(all) == 2
@blocking_call_on_reactor_thread
def test_update(self):
self.test_insertmany()
self.sqlite_test.update('person', "lastname == '2'", firstname='56')
one = self.sqlite_test.fetchone("select firstname from person where lastname == '2'")
assert one == '56', one
self.sqlite_test.update('person', "lastname == '3'", firstname=65)
one = self.sqlite_test.fetchone("select firstname from person where lastname == '3'")
assert one == 65, one
self.sqlite_test.update('person', "lastname == '4'", firstname=654, lastname=44)
one = self.sqlite_test.fetchone("select firstname from person where lastname == 44")
assert one == 654, one