예제 #1
0
def run(params):
    #cols = 80
    def disp_exception(text):
        print text

    h = HeadlessDisplayer()
    while 1:
        configdir = ConfigDir('downloadheadless')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(('save_options', 0, "whether to save the current "
                        "options as the new default configuration "
                        "(only for btdownloadheadless.py)"))
        try:
            config = parse_params(params, configdefaults)
        except ValueError, e:
            print 'error: %s \nrun with no args for parameter explanations' % e
            break
        if not config:
            print get_usage(defaults, 80, configdefaults)
            break
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])

        myid = createPeerID()
        seed(myid)

        global doneFlag
        doneFlag = Event()

        rawserver = RawServer(doneFlag, config['timeout_check_interval'],
                              config['timeout'],
                              ipv6_enable=config['ipv6_enabled'],
                              failfunc=h.failed,
                              errorfunc=disp_exception)
        upnp_type = UPnP_test(config['upnp_nat_access'])
        while True:
            try:
                listen_port = rawserver.find_and_bind(
                    config['minport'],
                    config['maxport'],
                    config['bind'],
                    ipv6_socket_style=config['ipv6_binds_v4'],
                    upnp=upnp_type,
                    randomizer=config['random_port'])
                break
            except socketerror, e:
                if upnp_type and e == UPnP_ERROR:
                    print 'WARNING: COULD NOT FORWARD VIA UPnP'
                    upnp_type = 0
                    continue
                print "error: Couldn't listen - " + str(e)
                h.failed()
                return
예제 #2
0
        ('display_path', 1, 'whether to display the full path or the torrent '
         'contents for each torrent'),
    ])
    try:
        configdir = ConfigDir('launchmany')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(
            ('save_options', 0, 'whether to save the current options as the '
             'new default configuration (only for btlaunchmany.py)'))
        if len(sys.argv) < 2:
            print "Usage: btlaunchmany.py <directory> <global options>\n"
            print "<directory> - directory to look for .torrent files " \
                "(semi-recursive)"
            print get_usage(defaults, 80, configdefaults)
            sys.exit(1)
        config, args = parseargs(sys.argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])
        if not os.path.isdir(args[0]):
            raise ValueError("Warning: " + args[0] + " is not a directory")
        config['torrent_dir'] = args[0]
    except ValueError as e:
        print 'error: {}\nrun with no args for parameter explanations' \
            ''.format(e)
        sys.exit(1)

    LaunchMany(config, HeadlessDisplayer())
    if Exceptions:
def run(scrwin, errlist, params):
    doneflag = Event()
    d = CursesDisplayer(scrwin, errlist, doneflag)
    try:
        while 1:
            configdir = ConfigDir('downloadcurses')
            defaultsToIgnore = ['responsefile', 'url', 'priority']
            configdir.setDefaults(defaults,defaultsToIgnore)
            configdefaults = configdir.loadConfig()
            defaults.append(('save_options',0,
             "whether to save the current options as the new default configuration " +
             "(only for btdownloadcurses.py)"))
            try:
                config = parse_params(params, configdefaults)
            except ValueError, e:
                d.error('error: ' + str(e) + '\nrun with no args for parameter explanations')
                break
            if not config:
                d.error(get_usage(defaults, d.fieldw, configdefaults))
                break
            if config['save_options']:
                configdir.saveConfig(config)
            configdir.deleteOldCacheData(config['expire_cache_data'])

            myid = createPeerID()
            seed(myid)

            rawserver = RawServer(doneflag, config['timeout_check_interval'],
                                  config['timeout'], ipv6_enable = config['ipv6_enabled'],
                                  failfunc = d.failed, errorfunc = d.error)

            upnp_type = UPnP_test(config['upnp_nat_access'])
            while True:
                try:
                    listen_port = rawserver.find_and_bind(config['minport'], config['maxport'],
                                    config['bind'], ipv6_socket_style = config['ipv6_binds_v4'],
                                    upnp = upnp_type, randomizer = config['random_port'])
                    break
                except socketerror, e:
                    if upnp_type and e == UPnP_ERROR:
                        d.error('WARNING: COULD NOT FORWARD VIA UPnP')
                        upnp_type = 0
                        continue
                    d.error("Couldn't listen - " + str(e))
                    d.failed()
                    return

            response = get_response(config['responsefile'], config['url'], d.error)
            if not response:
                break

            infohash = sha(bencode(response['info'])).digest()
            
            dow = BT1Download(d.display, d.finished, d.error, d.error, doneflag,
                            config, response, infohash, myid, rawserver, listen_port,
                            configdir)
            
            if not dow.saveAs(d.chooseFile):
                break

            if not dow.initFiles(old_style = True):
                break
            if not dow.startEngine():
                dow.shutdown()
                break
            dow.startRerequester()
            dow.autoStats()

            if not dow.am_I_finished():
                d.display(activity = 'connecting to peers')
            rawserver.listen_forever(dow.getPortHandler())
            d.display(activity = 'shutting down')
            dow.shutdown()
            break
            d.display(activity = 'shutting down')
            dow.shutdown()
            break

    except KeyboardInterrupt:
        # ^C to exit.. 
        pass 
    try:
        rawserver.shutdown()
    except:
        pass
    if not d.done:
        d.failed()


if __name__ == '__main__':
    if argv[1:] == ['--version']:
        print version
        exit(0)
    if len(argv) <= 1:
        print "Usage: btdownloadcurses.py <global options>\n"
        print get_usage(defaults)
        exit(1)

    errlist = []
    curses_wrapper(run, errlist, argv[1:])

    if errlist:
       print "These errors occurred during execution:"
       for error in errlist:
          print error
예제 #5
0
    def download(self, params):
        role = params[0]
        if role == 'download':
            self.isDownloader = True

        self.logger = logging.getLogger(role)

        params.remove(role)

        while True:
            configdir = ConfigDir('downloadheadless')
            defaultsToIgnore = ['responsefile', 'url', 'priority']
            configdir.setDefaults(defaults,defaultsToIgnore)
            configdefaults = configdir.loadConfig()
            defaults.append(('save_options',0,
             "whether to save the current options as the new default configuration " +
             "(only for btdownloadheadless.py)"))
            try:
                config = parse_params(params, configdefaults)
            except ValueError, e:
                print 'error: ' + str(e) + '\nrun with no args for parameter explanations'
                break
            if not config:
                print get_usage(defaults, 80, configdefaults)
                break
            if config['save_options']:
                configdir.saveConfig(config)
            configdir.deleteOldCacheData(config['expire_cache_data'])
            
            if config['url']:
                self.torrent = config['url']
            elif config['responsefile']:
                self.torrent = config['responsefile']

            for k in adjustDownloader:
                config[k] = adjustDownloader[k]

            myid = createPeerID()
            seed(myid)
        
            def disp_exception(text):
                self.logger.info( text)
            rawserver = RawServer(self.doneflag, config['timeout_check_interval'],
                                  config['timeout'], ipv6_enable = config['ipv6_enabled'],
                                  failfunc = self.failed, errorfunc = disp_exception)
            upnp_type = UPnP_test(config['upnp_nat_access'])

            while True:
                try:
                    listen_port = rawserver.find_and_bind(config['minport'], config['maxport'],
                                    config['bind'], ipv6_socket_style = config['ipv6_binds_v4'],
                                    upnp = upnp_type, randomizer = config['random_port'])
                    break
                except socketerror, e:
                    if upnp_type and e == UPnP_ERROR:
                        self.logger.info( 'WARNING: COULD NOT FORWARD VIA UPnP')
                        upnp_type = 0
                        continue
                    self.logger.info( "error: Couldn't listen - " + str(e))
                    self.failed()
                    return "error: Couldn't listen - " + str(e)
예제 #6
0
def run(autoDie, shareKill, userName, params):

    try:

        h = HeadlessDisplayer()
        h.autoShutdown = autoDie
        h.shareKill = shareKill
        h.user = userName

        while 1:
            try:
                config = parse_params(params)
            except ValueError, e:
                print 'error: ' + str(e) + '\nrun with no args for parameter explanations'
                break
            if not config:
                print get_usage()
                break

            # log what we are starting up
            transferLog("tornado starting up :\n", True)
            transferLog(" - torrentfile : " + config['responsefile'] + "\n", True)
            transferLog(" - userName : "******"\n", True)
            transferLog(" - transferStatFile : " + transferStatFile + "\n", True)
            transferLog(" - transferCommandFile : " + transferCommandFile + "\n", True)
            transferLog(" - transferLogFile : " + transferLogFile + "\n", True)
            transferLog(" - transferPidFile : " + transferPidFile + "\n", True)
            transferLog(" - autoDie : " + autoDie + "\n", True)
            transferLog(" - shareKill : " + shareKill + "\n", True)
            transferLog(" - minport : " + str(config['minport']) + "\n", True)
            transferLog(" - maxport : " + str(config['maxport']) + "\n", True)
            transferLog(" - max_upload_rate : " + str(config['max_upload_rate']) + "\n", True)
            transferLog(" - max_download_rate : " + str(config['max_download_rate']) + "\n", True)
            transferLog(" - min_uploads : " + str(config['min_uploads']) + "\n", True)
            transferLog(" - max_uploads : " + str(config['max_uploads']) + "\n", True)
            transferLog(" - min_peers : " + str(config['min_peers']) + "\n", True)
            transferLog(" - max_initiate : " + str(config['max_initiate']) + "\n", True)
            transferLog(" - max_connections : " + str(config['max_connections']) + "\n", True)
            transferLog(" - super_seeder : " + str(config['super_seeder']) + "\n", True)
            transferLog(" - security : " + str(config['security']) + "\n", True)
            transferLog(" - auto_kick : " + str(config['auto_kick']) + "\n", True)
            if 'crypto_allowed' in config:
                transferLog(" - crypto_allowed : " + str(config['crypto_allowed']) + "\n", True)
            if 'crypto_only' in config:
                transferLog(" - crypto_only : " + str(config['crypto_only']) + "\n", True)
            if 'crypto_stealth' in config:
                transferLog(" - crypto_stealth : " + str(config['crypto_stealth']) + "\n", True)
            transferLog(" - priority : " + str(config['priority']) + "\n", True)
            transferLog(" - alloc_type : " + str(config['alloc_type']) + "\n", True)
            transferLog(" - alloc_rate : " + str(config['alloc_rate']) + "\n", True)
            transferLog(" - buffer_reads : " + str(config['buffer_reads']) + "\n", True)
            transferLog(" - write_buffer_size : " + str(config['write_buffer_size']) + "\n", True)
            transferLog(" - check_hashes : " + str(config['check_hashes']) + "\n", True)
            transferLog(" - max_files_open : " + str(config['max_files_open']) + "\n", True)
            transferLog(" - upnp_nat_access : " + str(config['upnp_nat_access']) + "\n", True)

            # remove command-file if exists
            if isfile(transferCommandFile):
                try:
                    transferLog("removing command-file " + transferCommandFile + "...\n", True)
                    remove(transferCommandFile)
                except:
                    pass

            # write pid-file
            currentPid = (str(getpid())).strip()
            transferLog("writing pid-file : " + transferPidFile + " (" + currentPid + ")\n", True)
            try:
                pidFile = open(transferPidFile, 'w')
                pidFile.write(currentPid + "\n")
                pidFile.flush()
                pidFile.close()
            except Exception, e:
                transferLog("Failed to write pid-file, shutting down : " + transferPidFile + " (" + currentPid + ")" + "\n", True)
                break

            myid = createPeerID()
            seed(myid)

            doneflag = Event()
            def disp_exception(text):
                print text
            rawserver = RawServer(doneflag, config['timeout_check_interval'],
                              config['timeout'], ipv6_enable = config['ipv6_enabled'],
                              failfunc = h.failed, errorfunc = disp_exception)
            upnp_type = UPnP_test(config['upnp_nat_access'])
            while True:
                try:
                    listen_port = rawserver.find_and_bind(config['minport'], config['maxport'],
                                config['bind'], ipv6_socket_style = config['ipv6_binds_v4'],
                                upnp = upnp_type, randomizer = config['random_port'])
                    break
                except socketerror, e:
                    if upnp_type and e == UPnP_ERROR:
                        print 'WARNING: COULD NOT FORWARD VIA UPnP'
                        upnp_type = 0
                        continue
                    print "error: Couldn't listen - " + str(e)
                    h.failed()
                    return
예제 #7
0
def run(autoDie,shareKill,statusFile,userName,params):

    if __debug__: traceMsg('run - begin')

    try:
        f=open(statusFile+".pid",'w')
        f.write(str(getpid()).strip() + "\n")
        f.flush()
        f.close()
    except:
        if __debug__: traceMsg('run - Failed to Create PID file')
        pass

    try:

        h = HeadlessDisplayer()
        h.statFile = statusFile
        h.autoShutdown = autoDie
        h.shareKill = shareKill
        h.user = userName
    
        while 1:
            try:
                config = parse_params(params)
            except ValueError, e:
                print 'error: ' + str(e) + '\nrun with no args for parameter explanations'
                break
            if not config:
                print get_usage()
                break

            myid = createPeerID()
            seed(myid)
        
            doneflag = Event()
            def disp_exception(text):
                print text
            rawserver = RawServer(doneflag, config['timeout_check_interval'],
                              config['timeout'], ipv6_enable = config['ipv6_enabled'],
                              failfunc = h.failed, errorfunc = disp_exception)
            upnp_type = UPnP_test(config['upnp_nat_access'])
            while True:
                try:
                    listen_port = rawserver.find_and_bind(config['minport'], config['maxport'],
                                config['bind'], ipv6_socket_style = config['ipv6_binds_v4'],
                                upnp = upnp_type, randomizer = config['random_port'])
                    break
                except socketerror, e:
                    if upnp_type and e == UPnP_ERROR:
                        print 'WARNING: COULD NOT FORWARD VIA UPnP'
                        upnp_type = 0
                        continue
                    print "error: Couldn't listen - " + str(e)
                    h.failed()
                    return

            response = get_response(config['responsefile'], config['url'], h.error)
            if not response:
                break

            infohash = sha(bencode(response['info'])).digest()

            dow = BT1Download(h.display, h.finished, h.error, disp_exception, doneflag,
                        config, response, infohash, myid, rawserver, listen_port)
        
            if not dow.saveAs(h.chooseFile, h.newpath): 
                break

            if not dow.initFiles(old_style = True): 
                break

            if not dow.startEngine():
                dow.shutdown()
                break
            dow.startRerequester()
            dow.autoStats()

            if not dow.am_I_finished():
                h.display(activity = 'connecting to peers')
                
            rawserver.listen_forever(dow.getPortHandler())
            h.display(activity = 'shutting down')
            dow.shutdown()
            break
예제 #8
0
def run(scrwin, errlist, params):
    doneflag = threading.Event()
    d = CursesDisplayer(scrwin, errlist, doneflag)
    try:
        while 1:
            configdir = ConfigDir('downloadcurses')
            defaultsToIgnore = ['responsefile', 'url', 'priority']
            configdir.setDefaults(defaults, defaultsToIgnore)
            configdefaults = configdir.loadConfig()
            defaults.append(
                ('save_options', 0, 'whether to save the current options as '
                 'the new default configuration (only for btdownloadcurses.py)'
                 ))
            try:
                config = parse_params(params, configdefaults)
            except ValueError as e:
                d.error('error: {}\nrun with no args for parameter '
                        'explanations'.format(e))
                break
            if not config:
                d.error(get_usage(defaults, d.fieldw, configdefaults))
                break
            if config['save_options']:
                configdir.saveConfig(config)
            configdir.deleteOldCacheData(config['expire_cache_data'])

            myid = createPeerID()
            random.seed(myid)

            rawserver = RawServer(doneflag,
                                  config['timeout_check_interval'],
                                  config['timeout'],
                                  ipv6_enable=config['ipv6_enabled'],
                                  failfunc=d.failed,
                                  errorfunc=d.error)

            upnp_type = UPnP_test(config['upnp_nat_access'])
            while True:
                try:
                    listen_port = rawserver.find_and_bind(
                        config['minport'],
                        config['maxport'],
                        config['bind'],
                        ipv6_socket_style=config['ipv6_binds_v4'],
                        upnp=upnp_type,
                        randomizer=config['random_port'])
                    break
                except socket.error as e:
                    if upnp_type and e == UPnP_ERROR:
                        d.error('WARNING: COULD NOT FORWARD VIA UPnP')
                        upnp_type = 0
                        continue
                    d.error("Couldn't listen - " + str(e))
                    d.failed()
                    return

            response = get_response(config['responsefile'], config['url'],
                                    d.error)
            if not response:
                break

            infohash = hashlib.sha1(bencode(response['info'])).digest()

            dow = BT1Download(d.display, d.finished, d.error, d.error,
                              doneflag, config, response, infohash, myid,
                              rawserver, listen_port, configdir)

            if not dow.saveAs(d.chooseFile):
                break

            if not dow.initFiles(old_style=True):
                break
            if not dow.startEngine():
                dow.shutdown()
                break
            dow.startRerequester()
            dow.autoStats()

            if not dow.am_I_finished():
                d.display(activity='connecting to peers')
            rawserver.listen_forever(dow.getPortHandler())
            d.display(activity='shutting down')
            dow.shutdown()
            break

    except KeyboardInterrupt:
        # ^C to exit...
        pass
    try:
        rawserver.shutdown()
    except:
        pass
    if not d.done:
        d.failed()
예제 #9
0
            dow.shutdown()
            break

    except KeyboardInterrupt:
        # ^C to exit...
        pass
    try:
        rawserver.shutdown()
    except:
        pass
    if not d.done:
        d.failed()


if __name__ == '__main__':
    if sys.argv[1:] == ['--version']:
        print version
        sys.exit(0)
    if len(sys.argv) <= 1:
        print "Usage: btdownloadcurses.py <global options>\n"
        print get_usage(defaults)
        sys.exit(1)

    errlist = []
    curses_wrapper(run, errlist, sys.argv[1:])

    if errlist:
        print "These errors occurred during execution:"
        for error in errlist:
            print error
예제 #10
0
def run(params):
    h = HeadlessDisplayer()
    while 1:
        configdir = ConfigDir('downloadheadless')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(
            ('save_options', 0, 'whether to save the current options as the '
             'new default configuration (only for btdownloadheadless.py)'))
        try:
            config = parse_params(params, configdefaults)
        except ValueError as e:
            print 'error: {}\nrun with no args for parameter explanations' \
                ''.format(e)
            break
        if not config:
            print get_usage(defaults, 80, configdefaults)
            break
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])

        myid = createPeerID()
        random.seed(myid)

        doneflag = threading.Event()

        def disp_exception(text):
            print text
        rawserver = RawServer(
            doneflag, config['timeout_check_interval'], config['timeout'],
            ipv6_enable=config['ipv6_enabled'], failfunc=h.failed,
            errorfunc=disp_exception)
        upnp_type = UPnP_test(config['upnp_nat_access'])
        while True:
            try:
                listen_port = rawserver.find_and_bind(
                    config['minport'], config['maxport'], config['bind'],
                    ipv6_socket_style=config['ipv6_binds_v4'],
                    upnp=upnp_type, randomizer=config['random_port'])
                break
            except socket.error as e:
                if upnp_type and e == UPnP_ERROR:
                    print 'WARNING: COULD NOT FORWARD VIA UPnP'
                    upnp_type = 0
                    continue
                print "error: Couldn't listen - " + str(e)
                h.failed()
                return

        response = get_response(config['responsefile'], config['url'], h.error)
        if not response:
            break

        infohash = hashlib.sha1(bencode(response['info'])).digest()

        dow = BT1Download(
            h.display, h.finished, h.error, disp_exception, doneflag, config,
            response, infohash, myid, rawserver, listen_port, configdir)

        if not dow.saveAs(h.chooseFile, h.newpath):
            break

        if not dow.initFiles(old_style=True):
            break
        if not dow.startEngine():
            dow.shutdown()
            break
        dow.startRerequester()
        dow.autoStats()

        if not dow.am_I_finished():
            h.display(activity='connecting to peers')
        rawserver.listen_forever(dow.getPortHandler())
        h.display(activity='shutting down')
        dow.shutdown()
        break
    try:
        rawserver.shutdown()
    except:
        pass
    if not h.done:
        h.failed()
예제 #11
0
파일: tftornado.py 프로젝트: safvan010/123
def run(autoDie, shareKill, userName, params):

    try:

        h = HeadlessDisplayer()
        h.autoShutdown = autoDie
        h.shareKill = shareKill
        h.user = userName

        while 1:
            try:
                config = parse_params(params)
            except ValueError, e:
                print 'error: ' + str(
                    e) + '\nrun with no args for parameter explanations'
                break
            if not config:
                print get_usage()
                break

            # log what we are starting up
            transferLog("tornado starting up :\n", True)
            transferLog(" - torrentfile : " + config['responsefile'] + "\n",
                        True)
            transferLog(" - userName : "******"\n", True)
            transferLog(" - transferStatFile : " + transferStatFile + "\n",
                        True)
            transferLog(
                " - transferCommandFile : " + transferCommandFile + "\n", True)
            transferLog(" - transferLogFile : " + transferLogFile + "\n", True)
            transferLog(" - transferPidFile : " + transferPidFile + "\n", True)
            transferLog(" - autoDie : " + autoDie + "\n", True)
            transferLog(" - shareKill : " + shareKill + "\n", True)
            transferLog(" - minport : " + str(config['minport']) + "\n", True)
            transferLog(" - maxport : " + str(config['maxport']) + "\n", True)
            transferLog(
                " - max_upload_rate : " + str(config['max_upload_rate']) +
                "\n", True)
            transferLog(
                " - max_download_rate : " + str(config['max_download_rate']) +
                "\n", True)
            transferLog(
                " - min_uploads : " + str(config['min_uploads']) + "\n", True)
            transferLog(
                " - max_uploads : " + str(config['max_uploads']) + "\n", True)
            transferLog(" - min_peers : " + str(config['min_peers']) + "\n",
                        True)
            transferLog(
                " - max_initiate : " + str(config['max_initiate']) + "\n",
                True)
            transferLog(
                " - max_connections : " + str(config['max_connections']) +
                "\n", True)
            transferLog(
                " - super_seeder : " + str(config['super_seeder']) + "\n",
                True)
            transferLog(" - security : " + str(config['security']) + "\n",
                        True)
            transferLog(" - auto_kick : " + str(config['auto_kick']) + "\n",
                        True)
            if 'crypto_allowed' in config:
                transferLog(
                    " - crypto_allowed : " + str(config['crypto_allowed']) +
                    "\n", True)
            if 'crypto_only' in config:
                transferLog(
                    " - crypto_only : " + str(config['crypto_only']) + "\n",
                    True)
            if 'crypto_stealth' in config:
                transferLog(
                    " - crypto_stealth : " + str(config['crypto_stealth']) +
                    "\n", True)
            transferLog(" - priority : " + str(config['priority']) + "\n",
                        True)
            transferLog(" - alloc_type : " + str(config['alloc_type']) + "\n",
                        True)
            transferLog(" - alloc_rate : " + str(config['alloc_rate']) + "\n",
                        True)
            transferLog(
                " - buffer_reads : " + str(config['buffer_reads']) + "\n",
                True)
            transferLog(
                " - write_buffer_size : " + str(config['write_buffer_size']) +
                "\n", True)
            transferLog(
                " - check_hashes : " + str(config['check_hashes']) + "\n",
                True)
            transferLog(
                " - max_files_open : " + str(config['max_files_open']) + "\n",
                True)
            transferLog(
                " - upnp_nat_access : " + str(config['upnp_nat_access']) +
                "\n", True)

            # remove command-file if exists
            if isfile(transferCommandFile):
                try:
                    transferLog(
                        "removing command-file " + transferCommandFile +
                        "...\n", True)
                    remove(transferCommandFile)
                except:
                    pass

            # write pid-file
            currentPid = (str(getpid())).strip()
            transferLog(
                "writing pid-file : " + transferPidFile + " (" + currentPid +
                ")\n", True)
            try:
                pidFile = open(transferPidFile, 'w')
                pidFile.write(currentPid + "\n")
                pidFile.flush()
                pidFile.close()
            except Exception, e:
                transferLog(
                    "Failed to write pid-file, shutting down : " +
                    transferPidFile + " (" + currentPid + ")" + "\n", True)
                break

            myid = createPeerID()
            seed(myid)

            doneflag = Event()

            def disp_exception(text):
                print text

            rawserver = RawServer(doneflag,
                                  config['timeout_check_interval'],
                                  config['timeout'],
                                  ipv6_enable=config['ipv6_enabled'],
                                  failfunc=h.failed,
                                  errorfunc=disp_exception)
            upnp_type = UPnP_test(config['upnp_nat_access'])
            while True:
                try:
                    listen_port = rawserver.find_and_bind(
                        config['minport'],
                        config['maxport'],
                        config['bind'],
                        ipv6_socket_style=config['ipv6_binds_v4'],
                        upnp=upnp_type,
                        randomizer=config['random_port'])
                    break
                except socketerror, e:
                    if upnp_type and e == UPnP_ERROR:
                        print 'WARNING: COULD NOT FORWARD VIA UPnP'
                        upnp_type = 0
                        continue
                    print "error: Couldn't listen - " + str(e)
                    h.failed()
                    return
예제 #12
0
def run(params):
    cols = 80

    h = HeadlessDisplayer()
    while 1:
        configdir = ConfigDir("downloadheadless")
        defaultsToIgnore = ["responsefile", "url", "priority"]
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(
            (
                "save_options",
                0,
                "whether to save the current options as the new default configuration "
                + "(only for btdownloadheadless.py)",
            )
        )
        try:
            config = parse_params(params, configdefaults)
        except ValueError, e:
            print "error: " + str(e) + "\nrun with no args for parameter explanations"
            break
        if not config:
            print get_usage(defaults, 80, configdefaults)
            break
        if config["save_options"]:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config["expire_cache_data"])

        myid = createPeerID()
        seed(myid)

        global doneFlag
        doneFlag = Event()

        def disp_exception(text):
            print text

        rawserver = RawServer(
            doneFlag,
            config["timeout_check_interval"],
            config["timeout"],
            ipv6_enable=config["ipv6_enabled"],
            failfunc=h.failed,
            errorfunc=disp_exception,
        )
        upnp_type = UPnP_test(config["upnp_nat_access"])
        while True:
            try:
                listen_port = rawserver.find_and_bind(
                    config["minport"],
                    config["maxport"],
                    config["bind"],
                    ipv6_socket_style=config["ipv6_binds_v4"],
                    upnp=upnp_type,
                    randomizer=config["random_port"],
                )
                break
            except socketerror, e:
                if upnp_type and e == UPnP_ERROR:
                    print "WARNING: COULD NOT FORWARD VIA UPnP"
                    upnp_type = 0
                    continue
                print "error: Couldn't listen - " + str(e)
                h.failed()
                return
예제 #13
0
def run(params):

    try:
        import curses
        curses.initscr()
        cols = curses.COLS
        curses.endwin()
    except:
        cols = 80

    h = HeadlessDisplayer()

    while 1:
        configdir = ConfigDir('downloadheadless')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append((
            'save_options', 0,
            "whether to save the current options as the new default configuration "
            + "(only for btdownloadheadless.py)"))
        try:
            config = parse_params(params, configdefaults)
        except ValueError, e:
            print 'error: ' + str(
                e) + '\nrun with no args for parameter explanations'
            break
        if not config:
            print get_usage(defaults, 80, configdefaults)
            break
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])
        if config['verbose']:
            h.verbose = 1

        myid = createPeerID()
        seed(myid)

        doneflag = Event()

        def disp_exception(text):
            print text

        rawserver = RawServer(doneflag,
                              config['timeout_check_interval'],
                              config['timeout'],
                              ipv6_enable=config['ipv6_enabled'],
                              failfunc=h.failed,
                              errorfunc=disp_exception)

        h.raw_server = rawserver

        upnp_type = UPnP_test(config['upnp_nat_access'])
        while True:
            try:
                listen_port = rawserver.find_and_bind(
                    config['minport'],
                    config['maxport'],
                    config['bind'],
                    ipv6_socket_style=config['ipv6_binds_v4'],
                    upnp=upnp_type,
                    randomizer=config['random_port'])
                break
            except socketerror, e:
                if upnp_type and e == UPnP_ERROR:
                    print 'WARNING: COULD NOT FORWARD VIA UPnP'
                    upnp_type = 0
                    continue
                print "error: Couldn't listen - " + str(e)
                h.failed()
                return
예제 #14
0
         "whether to display the full path or the torrent contents for each torrent"
         ),
    ])
    try:
        configdir = ConfigDir('launchmany')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append((
            'save_options', 0,
            "whether to save the current options as the new default configuration "
            + "(only for btlaunchmany.py)"))
        if len(argv) < 2:
            print "Usage: btlaunchmany.py <directory> <global options>\n"
            print "<directory> - directory to look for .torrent files (semi-recursive)"
            print get_usage(defaults, 80, configdefaults)
            exit(1)
        config, args = parseargs(argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])
        if not os.path.isdir(args[0]):
            raise ValueError("Warning: " + args[0] + " is not a directory")
        config['torrent_dir'] = args[0]
    except ValueError, e:
        print 'error: ' + str(
            e) + '\nrun with no args for parameter explanations'
        exit(1)

    LaunchMany(config, HeadlessDisplayer())
    if Exceptions: