本文整理汇总了Python中Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB类的典型用法代码示例。如果您正苦于以下问题:Python SQLiteCacheDB类的具体用法?Python SQLiteCacheDB怎么用?Python SQLiteCacheDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLiteCacheDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AbstractDB
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: TestContentRepositoryWithRealDatabase
class TestContentRepositoryWithRealDatabase(TestBase):
"""
Tests content repository with real database.
"""
def setUp(self):
super(TestContentRepositoryWithRealDatabase, self).setUp()
session_base_dir = self.temporary_directory()
tar = tarfile.open(os.path.join(TESTS_DATA_DIR, 'bak_new_tribler.sdb.tar.gz'), 'r|gz')
tar.extractall(session_base_dir)
db_path = os.path.join(session_base_dir, 'bak_new_tribler.sdb')
self.sqlitedb = SQLiteCacheDB(db_path, busytimeout=BUSYTIMEOUT)
session = MockObject()
session.sqlite_db = self.sqlitedb
session.notifier = MockObject()
self.torrent_db = TorrentDBHandler(session)
channel_db = MockObject()
self.content_repository = ContentRepository(self.torrent_db, channel_db)
def tearDown(self):
self.torrent_db.close()
self.sqlitedb.close()
super(TestContentRepositoryWithRealDatabase, self).tearDown()
def test_update_db_from_search_results(self):
"""
Test if database is properly updated with the search results.
Should not raise any UnicodeDecodeError.
"""
# Add a torrent infohash before updating from search results
infohash = unhexlify('ed81da94d21ad1b305133f2726cdaec5a57fed98')
self.content_repository.torrent_db.addOrGetTorrentID(infohash)
# Sample search results
name = 'Puppy.Linux.manual.301.espa\xc3\xb1ol.pdf'
length = random.randint(1000, 9999)
num_files = random.randint(1, 10)
category_list = ['other']
creation_date = random.randint(1000000, 111111111)
seeders = random.randint(10, 200)
leechers = random.randint(5, 1000)
cid = None
search_results = [[infohash, name, length, num_files, category_list, creation_date, seeders, leechers, cid]]
# Update from search results
self.content_repository.update_from_torrent_search_results(search_results)
# Check if database has correct results
torrent_info = self.content_repository.get_torrent(infohash)
expected_name = u'Puppy.Linux.manual.301.espa\xc3\xb1ol.pdf'
self.assertEqual(expected_name, torrent_info['name'])
self.assertEqual(seeders, torrent_info['num_seeders'])
self.assertEqual(leechers, torrent_info['num_leechers'])
self.assertEqual(creation_date, torrent_info['creation_date'])
self.assertEqual(num_files, torrent_info['num_files'])
self.assertEqual(length, torrent_info['length'])
示例3: tearDown
def tearDown(self):
if SQLiteCacheDB.hasInstance():
SQLiteCacheDB.getInstance().close_all()
SQLiteCacheDB.delInstance()
if Session.has_instance(): # Upgrading will create a session instance
Session.del_instance()
sqlitecachedb.INITIAL_UPGRADE_PAUSE, sqlitecachedb.SUCCESIVE_UPGRADE_PAUSE, sqlitecachedb.UPGRADE_BATCH_SIZE, sqlitecachedb.TEST_OVERRIDE = self.original_values
self.tearDownCleanup()
示例4: test_integrity_check_failed
def test_integrity_check_failed(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"),
os.path.join(self.SQLITE_SCRIPTS_DIR, "script1.sql"))
def execute(sql):
if sql == u"PRAGMA quick_check":
db_response = MockObject()
db_response.next = lambda: ("Error: database disk image is malformed", )
return db_response
sqlite_test_2.execute = execute
示例5: tearDown
def tearDown(self):
self.torrentChecking.shutdown()
TorrentChecking.delInstance()
if SQLiteCacheDB.hasInstance():
SQLiteCacheDB.getInstance().close_all()
SQLiteCacheDB.delInstance()
TorrentDBHandler.delInstance()
MyPreferenceDBHandler.delInstance()
NetworkBuzzDBHandler.delInstance()
self.tearDownCleanup()
示例6: setUp
def setUp(self):
db_path = TRIBLER_DB_PATH
db = SQLiteCacheDB.getInstance()
db.initDB(db_path, busytimeout=BUSYTIMEOUT)
launchmany = FakeLaunchmany(db)
overlay_bridge = FakeOverlayBridge()
self.datahandler = DataHandler(launchmany,overlay_bridge)
示例7: setUp
def setUp(self):
self.setUpCleanup()
dbpath = init_bak_tribler_sdb('bak_new_tribler.sdb', destination_path=self.getStateDir(), overwrite=True)
self.sqlitedb = SQLiteCacheDB.getInstance()
self.sqlitedb.initDB(dbpath, busytimeout=BUSYTIMEOUT)
self.sqlitedb.waitForUpdateComplete()
示例8: setUp
def setUp(self):
db_path = TRIBLER_DB_PATH
db = SQLiteCacheDB.getInstance()
db.openDB(db_path, lib=LIB, autocommit=AUTOCOMMIT, busytimeout=BUSYTIMEOUT)
self.sp1 = '0R0\x10\x06\x07*\x86H\xce=\x02\x01\x06\x05+\x81\x04\x00\x1a\x03>\x00\x04\x00\\\xdfXv\xffX\xf2\xfe\x96\xe1_]\xf5\x1b\xb4\x91\x91\xa5I\xf0nl\x81\xd2A\xfb\xb7u)\x01T\xa9*)r\x9b\x81s\xb7j\xd2\xecrSg$;\xc8"7s\xecSF\xd3\x0bgK\x1c'
self.sp2 = '0R0\x10\x06\x07*\x86H\xce=\x02\x01\x06\x05+\x81\x04\x00\x1a\x03>\x00\x04\x01\xdb\x80+O\xd9N7`\xfc\xd3\xdd\xf0 \xfdC^\xc9\[email protected]\x97\xaa\x91r\x1c\xdeL\xf2n\x9f\x00U\xc1A\xf9Ae?\xd8t}_c\x08\xb3G\[email protected]! \xa0\x90M\xfb\xca\[email protected]'
self.fr1 = str2bin('MFIwEAYHKoZIzj0CAQYFK4EEABoDPgAEAL/l2IyVa6lc3KAqQyEnR++rIzi+AamnbzXHCxOFAFy67COiBhrC79PLzzUiURbHDx21QA4p8w3UDHLA')
示例9: __init__
def __init__(self):
self._sqlite_cache_db = SQLiteCacheDB.getInstance()
crawler = Crawler.get_instance()
if crawler.am_crawler():
msg = "# Crawler started"
self.__log(msg)
示例10: read_data
def read_data(self):
db = SQLiteCacheDB.getInstance()
one = db.fetchone('select * from person')
assert one == ('a','b'), str(one)
one = db.fetchone("select lastname from person where firstname == 'b'")
assert one == 'a'
one = db.fetchone("select lastname from person where firstname == 'c'")
assert one == None
all = db.fetchall('select * from person')
assert len(all) == 101, len(all)
num = db.size('person')
assert num == 101
db.insert('person', lastname='1', firstname='abc')
one = db.fetchone("select firstname from person where lastname == '1'")
assert one == '1' or one == 'abc'
all = db.fetchall("select firstname from person where lastname == '1'")
assert len(all) == 2
db.update('person', "lastname == '2'", firstname='56')
one = db.fetchone("select firstname from person where lastname == '2'")
assert one == '56', one
db.update('person', "lastname == '3'", firstname=65)
one = db.fetchone("select firstname from person where lastname == '3'")
assert one == 65, one
db.update('person', "lastname == '4'", firstname=654, lastname=44)
one = db.fetchone("select firstname from person where lastname == 44")
assert one == 654, one
db.close()
示例11: test_open_close_db
def test_open_close_db(self):
sqlite_test = SQLiteCacheDB.getInstance()
sqlite_test.openDB(self.db_path, 1250)
sqlite_test.close()
sqlite_test.close()
sqlite_test.openDB(self.db_path, 0)
sqlite_test.close()
示例12: keep_reading_data
def keep_reading_data(self, period):
db = SQLiteCacheDB.getInstance()
st = time()
oldnum = 0
self.all = []
self.read_times = 0
if DEBUG_R:
print "begin read", self.getName(), period, time()
while True:
et = time()
if et-st > period:
break
if DEBUG_R:
print "...start read", self.getName(), time()
sys.stdout.flush()
try:
self.all = db.fetchall("select * from person")
self.last_read = time()-st
self.read_times += 1
except Exception, msg:
print_exc()
print "*-*", Exception, msg
self.read_locks += 1
if DEBUG:
print >> sys.stdout, "Locked while reading!", self.read_locks
sys.stdout.flush()
else:
if DEBUG_R:
print "...end read", self.getName(), time(), len(self.all)
sys.stdout.flush()
示例13: setUp
def setUp(self):
yield super(TestSqliteCacheDB, self).setUp()
db_path = u":memory:"
self.sqlite_test = SQLiteCacheDB(db_path)
self.sqlite_test.set_show_sql(True)
示例14: start_database
def start_database(self):
"""
Start the SQLite database.
"""
db_path = os.path.join(self.config.get_state_dir(), DB_FILE_RELATIVE_PATH)
self.sqlite_db = SQLiteCacheDB(db_path)
self.readable_status = STATE_OPEN_DB
示例15: TestSqliteCacheDB
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