예제 #1
0
def main():
    command_line_parser = optparse.OptionParser()
    command_line_parser.add_option("--statedir", action="store", type="string", help="Use an alternate statedir")
    command_line_parser.add_option("--port", action="store", type="int", help="Listen at this port")
    command_line_parser.add_option("--rss", action="store", type="string", help="Url where to fetch rss feed, or several seperated with ';'")
    command_line_parser.add_option("--dir", action="store", type="string", help="Directory to watch for .torrent files, or several seperated with ';'")
    command_line_parser.add_option("--file", action="store", type="string", help="JSON file which has a community")
    command_line_parser.add_option("--nickname", action="store", type="string", help="The moderator name")
    command_line_parser.add_option("--channelname", action="store", type="string", help="The channel name")

    # parse command-line arguments
    opt, args = command_line_parser.parse_args()

    if not (opt.rss or opt.dir or opt.file):
        command_line_parser.print_help()
        print "\nExample: python Tribler/Main/metadata-injector.py --rss http://frayja.com/rss.php --nickname frayja --channelname goldenoldies"
        sys.exit()

    print "Type 'Q' to stop the metadata-injector"

    sscfg = SessionStartupConfig()
    if opt.statedir:
        sscfg.set_state_dir(unicode(os.path.realpath(opt.statedir)))
    if opt.port:
        sscfg.set_dispersy_port(opt.port)
    if opt.nickname:
        sscfg.set_nickname(opt.nickname)

    sscfg.set_megacache(True)
    sscfg.set_overlay(True)
    # turn torrent collecting on. this will cause torrents to be distributed
    sscfg.set_torrent_collecting(True)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    session = Session(sscfg)
    session.start()

    # condition variable would be prettier, but that don't listen to
    # KeyboardInterrupt
    try:
        while True:
            x = sys.stdin.readline()
            print >> sys.stderr, x
            if x.strip() == 'Q':
                break
    except:
        print_exc()

    torrentfeed = RssParser.getInstance()
    torrentfeed.shutdown()

    dirfeed = DirectoryFeedThread.getInstance()
    dirfeed.shutdown()

    session.shutdown()
    print "Shutting down..."
    time.sleep(5)
예제 #2
0
    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)
    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)
def main():
    command_line_parser = optparse.OptionParser()
    command_line_parser.add_option("--statedir",
                                   action="store",
                                   type="string",
                                   help="Use an alternate statedir")
    command_line_parser.add_option("--port",
                                   action="store",
                                   type="int",
                                   help="Listen at this port")
    command_line_parser.add_option(
        "--rss",
        action="store",
        type="string",
        help="Url where to fetch rss feed, or several seperated with ';'")
    command_line_parser.add_option(
        "--dir",
        action="store",
        type="string",
        help=
        "Directory to watch for .torrent files, or several seperated with ';'")
    command_line_parser.add_option("--file",
                                   action="store",
                                   type="string",
                                   help="JSON file which has a community")
    command_line_parser.add_option("--nickname",
                                   action="store",
                                   type="string",
                                   help="The moderator name")
    command_line_parser.add_option("--channelname",
                                   action="store",
                                   type="string",
                                   help="The channel name")

    # parse command-line arguments
    opt, args = command_line_parser.parse_args()

    if not (opt.rss or opt.dir or opt.file):
        command_line_parser.print_help()
        print "\nExample: python Tribler/Main/metadata-injector.py --rss http://frayja.com/rss.php --nickname frayja --channelname goldenoldies"
        sys.exit()

    print "Type 'Q' to stop the metadata-injector"

    sscfg = SessionStartupConfig()
    if opt.statedir:
        sscfg.set_state_dir(unicode(os.path.realpath(opt.statedir)))
    if opt.port: sscfg.set_dispersy_port(opt.port)
    if opt.nickname: sscfg.set_nickname(opt.nickname)

    sscfg.set_megacache(True)
    sscfg.set_overlay(True)
    # turn torrent collecting on. this will cause torrents to be distributed
    sscfg.set_torrent_collecting(True)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    session = Session(sscfg)

    #Wait for Dispersy
    if Dispersy.has_instance():
        dispersy_started(session, opt)
    else:

        def notify(*args):
            dispersy_started(session, opt)

        session.add_observer(notify, NTFY_DISPERSY, [NTFY_STARTED])

    # condition variable would be prettier, but that don't listen to
    # KeyboardInterrupt
    try:
        while True:
            x = sys.stdin.readline()
            print >> sys.stderr, x
            if x.strip() == 'Q':
                break
    except:
        print_exc()

    torrentfeed = RssParser.getInstance()
    torrentfeed.shutdown()

    dirfeed = DirectoryFeedThread.getInstance()
    dirfeed.shutdown()

    session.shutdown()
    print "Shutting down..."
    time.sleep(5)