當前位置: 首頁>>代碼示例>>Python>>正文


Python ChannelManager.modifyChannel方法代碼示例

本文整理匯總了Python中Tribler.Main.vwxGUI.SearchGridManager.ChannelManager.modifyChannel方法的典型用法代碼示例。如果您正苦於以下問題:Python ChannelManager.modifyChannel方法的具體用法?Python ChannelManager.modifyChannel怎麽用?Python ChannelManager.modifyChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tribler.Main.vwxGUI.SearchGridManager.ChannelManager的用法示例。


在下文中一共展示了ChannelManager.modifyChannel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dispersy_started

# 需要導入模塊: from Tribler.Main.vwxGUI.SearchGridManager import ChannelManager [as 別名]
# 或者: from Tribler.Main.vwxGUI.SearchGridManager.ChannelManager import modifyChannel [as 別名]
def dispersy_started(session, opt):
    myPermid = permid_for_user(session.get_permid())
    print >> sys.stderr, "permid: ", myPermid

    from Tribler.Main.vwxGUI.SearchGridManager import TorrentManager, LibraryManager, ChannelManager
    torrentManager = TorrentManager(None)
    libraryManager = LibraryManager(None)
    channelManager = ChannelManager()

    torrentManager.connect(session, libraryManager, channelManager)
    channelManager.connect(session, libraryManager, torrentManager)
    libraryManager.connect(session, torrentManager, channelManager)

    myChannelName = opt.channelname or opt.nickname or 'MetadataInjector-Channel'
    myChannelName = unicode(myChannelName)

    createdNewChannel = False
    myChannelId = channelManager.channelcast_db.getMyChannelId()
    if not myChannelId:
        print >> sys.stderr, "creating a new channel"
        channelManager.createChannel(myChannelName, u'')
        createdNewChannel = True

    else:
        print >> sys.stderr, "reusing previously created channel"
        myChannel = channelManager.getChannel(myChannelId)
        if myChannel.name != myChannelName:
            print >> sys.stderr, "renaming channel to", myChannelName
            channelManager.modifyChannel(myChannelId, {'name': myChannelName})

    # use dispersythread, this way we know our channel has been created
    @forceDispersyThread
    def createTorrentFeed():
        myChannelId = channelManager.channelcast_db.getMyChannelId()

        torrentfeed = RssParser.getInstance()
        torrentfeed.register(session, myChannelId)
        torrentfeed.addCallback(myChannelId, channelManager.createTorrentFromDef)

        for rss in opt.rss.split(";"):
            torrentfeed.addURL(rss, myChannelId)

    if opt.rss:
        createTorrentFeed()

    # same here, using dispersythread to make sure channel has been created
    @forceDispersyThread
    def createDirFeed():
        myChannelId = channelManager.channelcast_db.getMyChannelId()

        def on_torrent_callback(dirpath, infohash, torrent_data):
            torrentdef = TorrentDef.load_from_dict(torrent_data)
            channelsearch_manager.createTorrentFromDef(myChannelId, torrentdef)

            # save torrent to collectedtorrents
            filename = torrentManager.getCollectedFilenameFromDef(torrentdef)
            if not os.path.isfile(filename):
                torrentdef.save(filename)

        dirfeed = DirectoryFeedThread.getInstance()
        for dirpath in opt.dir.split(";"):
            dirfeed.addDir(dirpath, callback=on_torrent_callback)

    if opt.dir:
        createDirFeed()

    # same here, using dispersythread to make sure channel has been created
    @forceDispersyThread
    def createFileFeed():
        myChannelId = channelManager.channelcast_db.getMyChannelId()
        community = channelManager._disp_get_community_from_channel_id(myChannelId)

        print >> sys.stderr, "Using community:", community._cid.encode('HEX')

        items = json.load(open(opt.file, 'rb'))
        for item in items:
            try:
                infohash = sha1(item['name']).digest()
            except:
                infohash = sha1(str(random.randint(0, 1000000))).digest()
            message = community._disp_create_torrent(infohash, long(time.time()), unicode(item['name']), ((u'fake.file', 10),), tuple(), update=False, forward=False)

            print >> sys.stderr, "Created a new torrent"

            latest_review = None
            for modification in item['modifications']:
                reviewmessage = community._disp_create_modification('description', unicode(modification['text']), long(time.time()), message, latest_review, update=False, forward=False)

                print >> sys.stderr, "Created a new modification"

                if modification['revert']:
                    community._disp_create_moderation('reverted', long(time.time()), 0, reviewmessage.packet_id, update=False, forward=False)

                    print >> sys.stderr, "Reverted the last modification"
                else:
                    latest_review = reviewmessage

    if opt.file and createdNewChannel:
        createFileFeed()
開發者ID:Anbcorp,項目名稱:tribler,代碼行數:101,代碼來源:metadata-injector.py

示例2: dispersy_started

# 需要導入模塊: from Tribler.Main.vwxGUI.SearchGridManager import ChannelManager [as 別名]
# 或者: from Tribler.Main.vwxGUI.SearchGridManager.ChannelManager import modifyChannel [as 別名]
def dispersy_started(session, opt):
    myPermid = permid_for_user(session.get_permid())
    print >>sys.stderr, "permid: ", myPermid
    
    from Tribler.Main.vwxGUI.SearchGridManager import TorrentManager, LibraryManager, ChannelManager
    torrentManager = TorrentManager(None)
    libraryManager = LibraryManager(None)
    channelManager = ChannelManager()
    
    torrentManager.connect(session, libraryManager, channelManager)
    channelManager.connect(session, torrentManager)
    libraryManager.connect(session, torrentManager)
    
    myChannelName = opt.channelname or opt.nickname or 'MetadataInjector-Channel'
    myChannelName = unicode(myChannelName)
    
    myChannelId = channelManager.channelcast_db.getMyChannelId()
    if not myChannelId:
        print >> sys.stderr, "creating a new channel"
        channelManager.createChannel(myChannelName, u'')
        
    else:
        print >> sys.stderr, "reusing previously created channel"
        
        myChannel = channelManager.getChannel(myChannelId)
        if myChannel.name != myChannelName:
            print >> sys.stderr, "renaming channel to",myChannelName
            channelManager.modifyChannel(myChannelId, {'name': myChannelName})

    #use dispersythread, this way we know our channel has been created
    @forceDispersyThread
    def createTorrentFeed():
        myChannelId = channelManager.channelcast_db.getMyChannelId()

        torrentfeed = RssParser.getInstance()
        torrentfeed.register(session, myChannelId)
        torrentfeed.addCallback(myChannelId, channelManager.createTorrentFromDef)
        
        for rss in opt.rss.split(";"):
            torrentfeed.addURL(rss, myChannelId)
        
    if opt.rss:
        createTorrentFeed()
    
    #same here, using dispersythread to make sure channel has been created
    @forceDispersyThread
    def createDirFeed():
        myChannelId = channelManager.channelcast_db.getMyChannelId()
        
        def on_torrent_callback(dirpath, infohash, torrent_data):
            torrentdef = TorrentDef.load_from_dict(torrent_data)
            channelsearch_manager.createTorrentFromDef(myChannelId, torrentdef)
            
            #save torrent to collectedtorrents
            filename = torrentManager.getCollectedFilenameFromDef(torrentdef)
            if not os.path.isfile(filename): 
                torrentdef.save(filename)
        
        dirfeed = DirectoryFeedThread.getInstance()
        for dirpath in opt.dir.split(";"):
            dirfeed.addDir(dirpath, callback = on_torrent_callback)
            
    if opt.dir:
        createDirFeed()
開發者ID:ebcayabyab-personal,項目名稱:swiftarm,代碼行數:66,代碼來源:metadata-injector.py


注:本文中的Tribler.Main.vwxGUI.SearchGridManager.ChannelManager.modifyChannel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。