当前位置: 首页>>代码示例>>Python>>正文


Python SqliteCacheDBHandler.TorrentDBHandler类代码示例

本文整理汇总了Python中Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler的典型用法代码示例。如果您正苦于以下问题:Python TorrentDBHandler类的具体用法?Python TorrentDBHandler怎么用?Python TorrentDBHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TorrentDBHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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'])
开发者ID:synctext,项目名称:tribler,代码行数:59,代码来源:test_repository.py

示例2: 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()
开发者ID:Anbcorp,项目名称:tribler,代码行数:13,代码来源:test_tracker_checking.py

示例3: test_reimport_torrents

    def test_reimport_torrents(self):
        self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
        self.torrent_store = LevelDbStore(self.session.config.get_torrent_store_dir())
        db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=self.torrent_store)
        db_migrator.start_migrate()

        # Import a torrent
        self.torrent_store[TORRENT_UBUNTU_FILE_INFOHASH] = fix_torrent(TORRENT_UBUNTU_FILE)
        self.torrent_store.flush()

        db_migrator.reimport_torrents()

        torrent_db_handler = TorrentDBHandler(self.session)
        self.assertEqual(torrent_db_handler.getTorrentID(TORRENT_UBUNTU_FILE_INFOHASH), 3)
开发者ID:synctext,项目名称:tribler,代码行数:14,代码来源:test_db_upgrader.py

示例4: setUp

    def setUp(self):
        AbstractDB.setUp(self)

        self.tdb = TorrentDBHandler.getInstance()
        self.tdb.torrent_dir = FILES_DIR
        self.tdb.mypref_db = MyPreferenceDBHandler.getInstance()
        self.tdb._nb = NetworkBuzzDBHandler.getInstance()
开发者ID:Anbcorp,项目名称:tribler,代码行数:7,代码来源:test_sqlitecachedbhandler.py

示例5: __init__

    def __init__(self, parent):
        HomePanel.__init__(self, parent, 'Newest Torrents' , LIST_BLUE)
        self.Layout()

        self.torrentdb = TorrentDBHandler.getInstance()
        session = Session.get_instance()
        session.add_observer(self.OnNotify, NTFY_TORRENTS, [NTFY_INSERT])
开发者ID:ebcayabyab-personal,项目名称:swiftarm,代码行数:7,代码来源:home.py

示例6: __init__

 def __init__(self, master, integrate_with_tribler = True):
     super(SearchCommunity, self).__init__(master)
     
     self.integrate_with_tribler = integrate_with_tribler
     self.taste_buddies = []
     
     if self.integrate_with_tribler:
         from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler
         from Tribler.Core.CacheDB.Notifier import Notifier 
     
         # tribler channelcast database
         self._channelcast_db = ChannelCastDBHandler.getInstance()
         self._torrent_db = TorrentDBHandler.getInstance()
         self._mypref_db = MyPreferenceDBHandler.getInstance()
         self._notifier = Notifier.getInstance()
         
         # torrent collecting
         self._rtorrent_handler = RemoteTorrentHandler.getInstance()
     else:
         self._channelcast_db = ChannelCastDBStub(self._dispersy)
         self._torrent_db = None
         self._mypref_db = None
         self._notifier = None
         
     self.taste_bloom_filter = None
     self.taste_bloom_filter_key = None
     
     self.dispersy.callback.register(self.create_torrent_collect_requests, delay = CANDIDATE_WALK_LIFETIME)
开发者ID:ebcayabyab-personal,项目名称:swiftarm,代码行数:28,代码来源:community.py

示例7: __init__

 def __init__(self, master, integrate_with_tribler = True):
     super(SearchCommunity, self).__init__(master)
     
     self.integrate_with_tribler = integrate_with_tribler
     self.taste_buddies = []
     #To always connect to a peer uncomment/modify the following line
     #self.taste_buddies.append([1, time(), Candidate(("127.0.0.1", 1234), False))
     
     if self.integrate_with_tribler:
         from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler
         from Tribler.Core.CacheDB.Notifier import Notifier 
     
         # tribler channelcast database
         self._channelcast_db = ChannelCastDBHandler.getInstance()
         self._torrent_db = TorrentDBHandler.getInstance()
         self._mypref_db = MyPreferenceDBHandler.getInstance()
         self._notifier = Notifier.getInstance()
         
         # torrent collecting
         self._rtorrent_handler = RemoteTorrentHandler.getInstance()
     else:
         self._channelcast_db = ChannelCastDBStub(self._dispersy)
         self._torrent_db = None
         self._mypref_db = None
         self._notifier = None
         
     self.taste_bloom_filter = None
     self.taste_bloom_filter_key = None
     
     self.torrent_cache = None
     
     self.dispersy.callback.register(self.create_torrent_collect_requests, delay = CANDIDATE_WALK_LIFETIME)
     self.dispersy.callback.register(self.fast_walker)
开发者ID:duy,项目名称:tribler,代码行数:33,代码来源:community.py

示例8: TestTorrentFullSessionDBHandler

class TestTorrentFullSessionDBHandler(AbstractDB):

    def setUpPreSession(self):
        super(TestTorrentFullSessionDBHandler, self).setUpPreSession()
        self.config.set_megacache_enabled(True)

    @inlineCallbacks
    def setUp(self):
        yield super(TestTorrentFullSessionDBHandler, self).setUp()
        self.tdb = TorrentDBHandler(self.session)

    def test_initialize(self):
        self.tdb.initialize()
        self.assertIsNone(self.tdb.mypref_db)
        self.assertIsNone(self.tdb.votecast_db)
        self.assertIsNone(self.tdb.channelcast_db)
开发者ID:synctext,项目名称:tribler,代码行数:16,代码来源:test_sqlitecachedbhandler_torrents.py

示例9: setUp

    def setUp(self):
        yield super(TestTorrentDBHandler, self).setUp()

        from Tribler.Core.APIImplementation.LaunchManyCore import TriblerLaunchMany
        from Tribler.Core.Modules.tracker_manager import TrackerManager
        self.session.lm = TriblerLaunchMany()
        self.session.lm.tracker_manager = TrackerManager(self.session)
        self.tdb = TorrentDBHandler(self.session)
        self.tdb.torrent_dir = TESTS_DATA_DIR
        self.tdb.category = Category()
        self.tdb.mypref_db = MyPreferenceDBHandler(self.session)
开发者ID:synctext,项目名称:tribler,代码行数:11,代码来源:test_sqlitecachedbhandler_torrents.py

示例10: __init__

    def __init__(self, parent):
        HomePanel.__init__(self, parent, 'Network info' , SEPARATOR_GREY, (0, 1))

        self.torrentdb = TorrentDBHandler.getInstance()
        self.channelcastdb = ChannelCastDBHandler.getInstance()
        self.remotetorrenthandler = RemoteTorrentHandler.getInstance()

        self.timer = None

        session = Session.get_instance()
        session.add_observer(self.OnNotify, NTFY_TORRENTS, [NTFY_INSERT])
        self.UpdateStats()
开发者ID:duy,项目名称:tribler,代码行数:12,代码来源:home.py

示例11: setUp

    def setUp(self):
        self.setUpCleanup()

        config = {}
        config['state_dir'] = self.getStateDir()
        config['install_dir'] = '.'
        init_db(config)

        self.tdb = TorrentDBHandler.getInstance()
        self.tdb.torrent_dir = FILES_DIR
        self.tdb.mypref_db = MyPreferenceDBHandler.getInstance()
        self.tdb._nb = NetworkBuzzDBHandler.getInstance()

        self.torrentChecking = TorrentChecking()
        sleep(5)
开发者ID:Anbcorp,项目名称:tribler,代码行数:15,代码来源:test_tracker_checking.py

示例12: setUp

    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)
开发者ID:synctext,项目名称:tribler,代码行数:16,代码来源:test_repository.py

示例13: reimport_torrents

    def reimport_torrents(self):
        """Import all torrent files in the collected torrent dir, all the files already in the database will be ignored.
        """
        self.status_update_func("Opening TorrentDBHandler...")
        # TODO(emilon): That's a freakishly ugly hack.
        torrent_db_handler = TorrentDBHandler(self.session)
        torrent_db_handler.category = Category()

        # TODO(emilon): It would be nice to drop the corrupted torrent data from the store as a bonus.
        self.status_update_func("Registering recovered torrents...")
        try:
            for infoshash_str, torrent_data in self.torrent_store.iteritems():
                self.status_update_func("> %s" % infoshash_str)
                torrentdef = TorrentDef.load_from_memory(torrent_data)
                if torrentdef.is_finalized():
                    infohash = torrentdef.get_infohash()
                    if not torrent_db_handler.hasTorrent(infohash):
                        self.status_update_func(u"Registering recovered torrent: %s" % hexlify(infohash))
                        torrent_db_handler._addTorrentToDB(torrentdef, extra_info={"filename": infoshash_str})
        finally:
            torrent_db_handler.close()
            self.db.commit_now()
            return self.torrent_store.flush()
开发者ID:synctext,项目名称:tribler,代码行数:23,代码来源:db_upgrader.py

示例14: _printDBStats

 def _printDBStats(self):
     torrentdb = TorrentDBHandler.getInstance()
     tables = torrentdb._db.fetchall("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name");
     for table, in tables:
         print >> sys.stderr, table, torrentdb._db.fetchone("SELECT COUNT(*) FROM %s"%table)
开发者ID:ebcayabyab-personal,项目名称:swiftarm,代码行数:5,代码来源:home.py

示例15: register


#.........这里部分代码省略.........
            if config['dispersy']:
                from Tribler.dispersy.callback import Callback
                from Tribler.dispersy.dispersy import Dispersy
                from Tribler.dispersy.endpoint import RawserverEndpoint, TunnelEndpoint
                from Tribler.dispersy.community import HardKilledCommunity

                # set communication endpoint
                if config['dispersy-tunnel-over-swift'] and self.swift_process:
                    endpoint = TunnelEndpoint(self.swift_process)
                else:
                    endpoint = RawserverEndpoint(self.rawserver, config['dispersy_port'])

                callback = Callback("Dispersy")  # WARNING NAME SIGNIFICANT
                working_directory = unicode(config['state_dir'])

                self.dispersy = Dispersy(callback, endpoint, working_directory)

                # TODO: see if we can postpone dispersy.start to improve GUI responsiveness.
                # However, for now we must start self.dispersy.callback before running
                # try_register(nocachedb, self.database_thread)!

                self.dispersy.start()

                print >> sys.stderr, "lmc: Dispersy is listening on port", self.dispersy.wan_address[1], "using", endpoint
                self.upnp_ports.append((self.dispersy.wan_address[1], 'UDP'))

                self.dispersy.callback.call(self.dispersy.define_auto_load, args=(HardKilledCommunity,), kargs={'load': True})

                # notify dispersy finished loading
                self.session.uch.notify(NTFY_DISPERSY, NTFY_STARTED, None)

                from Tribler.Core.permid import read_keypair
                from Tribler.dispersy.crypto import ec_to_public_bin, ec_to_private_bin
                keypair = read_keypair(self.session.get_permid_keypair_filename())
                self.session.dispersy_member = callback.call(self.dispersy.get_member, (ec_to_public_bin(keypair), ec_to_private_bin(keypair)))

                self.database_thread = callback
            else:
                class FakeCallback():
                    def __init__(self):
                        from Tribler.Utilities.TimedTaskQueue import TimedTaskQueue
                        self.queue = TimedTaskQueue("FakeCallback")

                    def register(self, call, args=(), kargs=None, delay=0.0, priority=0, id_=u"", callback=None, callback_args=(), callback_kargs=None, include_id=False):
                        def do_task():
                            if kargs:
                                call(*args, **kargs)
                            else:
                                call(*args)

                            if callback:
                                if callback_kargs:
                                    callback(*callback_args, **callback_kargs)
                                else:
                                    callback(*callback_args)
                        self.queue.add_task(do_task, t=delay)

                    def shutdown(self, immediately=False):
                        self.queue.shutdown(immediately)

                self.database_thread = FakeCallback()

            if config['megacache']:
                import Tribler.Core.CacheDB.cachedb as cachedb
                from Tribler.Core.CacheDB.SqliteCacheDBHandler import PeerDBHandler, TorrentDBHandler, MyPreferenceDBHandler, VoteCastDBHandler, ChannelCastDBHandler, NetworkBuzzDBHandler, UserEventLogDBHandler
                from Tribler.Category.Category import Category
                from Tribler.Core.Tag.Extraction import TermExtraction
                from Tribler.Core.CacheDB.sqlitecachedb import try_register

                if DEBUG:
                    print >> sys.stderr, 'tlm: Reading Session state from', config['state_dir']

                nocachedb = cachedb.init(config, self.rawserver_fatalerrorfunc)
                try_register(nocachedb, self.database_thread)

                self.cat = Category.getInstance(config['install_dir'])
                self.term = TermExtraction.getInstance(config['install_dir'])

                self.peer_db = PeerDBHandler.getInstance()
                self.peer_db.registerConnectionUpdater(self.session)

                self.torrent_db = TorrentDBHandler.getInstance()
                self.torrent_db.register(os.path.abspath(config['torrent_collecting_dir']))
                self.mypref_db = MyPreferenceDBHandler.getInstance()
                self.votecast_db = VoteCastDBHandler.getInstance()
                self.votecast_db.registerSession(self.session)
                self.channelcast_db = ChannelCastDBHandler.getInstance()
                self.channelcast_db.registerSession(self.session)
                self.nb_db = NetworkBuzzDBHandler.getInstance()
                self.ue_db = UserEventLogDBHandler.getInstance()

                if self.dispersy:
                    self.dispersy.database.attach_commit_callback(self.channelcast_db._db.commitNow)
            else:
                config['torrent_checking'] = 0

            self.rtorrent_handler = None
            if config['torrent_collecting']:
                from Tribler.Core.RemoteTorrentHandler import RemoteTorrentHandler
                self.rtorrent_handler = RemoteTorrentHandler()
开发者ID:Anbcorp,项目名称:tribler,代码行数:101,代码来源:LaunchManyCore.py


注:本文中的Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。