Esempio n. 1
0
def run(scrwin, errlist, params):
    doneflag = threading.Event()
    d = CursesDisplayer(scrwin, errlist, doneflag)
    try:
        while 1:
            configdir = ConfigDir('downloadcurses')
            defaultsToIgnore = ['metafile', '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

            metainfo = get_metainfo(config['metafile'], config['url'], d.error)
            if not metainfo:
                break

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

            dow = BT1Download(d.display, d.finished, d.error, d.error,
                              doneflag, config, metainfo, 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 Exception:
        pass
    if not d.done:
        d.failed()
Esempio n. 2
0
 defaults.extend([
     ('parse_dir_interval', 60,
      'how often to rescan the torrent directory, in seconds'),
     ('saveas_style', 2, 'How to name torrent downloads (1 = rename to '
      'torrent name, 2 = save under name in torrent, 3 = save in directory '
      'under torrent name)'),
     ('display_path', 0, 'whether to display the full path or the torrent '
      'contents for each torrent'),
 ])
 try:
     configdir = ConfigDir('launchmanycurses')
     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 '
                      'btlaunchmanycurses.py)'))
     if len(sys.argv) < 2:
         print("Usage: btlaunchmanycurses.py <directory> <global options>\n"
               "<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:
Esempio n. 3
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 Exception:
        pass
    if not d.done:
        d.failed()
Esempio n. 4
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 Exception:
        pass
    if not h.done:
        h.failed()
Esempio n. 5
0
 defaults.extend([
     ('parse_dir_interval', 60,
      "how often to rescan the torrent directory, in seconds"),
     ('saveas_style', 1, 'How to name torrent downloads (1 = rename to '
      'torrent name, 2 = save under name in torrent, 3 = save in directory '
      'under torrent name)'),
     ('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:
Esempio n. 6
0
 defaults.extend([
     ('parse_dir_interval', 60,
      "how often to rescan the torrent directory, in seconds"),
     ('saveas_style', 1, 'How to name torrent downloads (1 = rename to '
      'torrent name, 2 = save under name in torrent, 3 = save in directory '
      'under torrent name)'),
     ('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:
Esempio n. 7
0
 defaults.extend([
     ('parse_dir_interval', 60,
      'how often to rescan the torrent directory, in seconds'),
     ('saveas_style', 2, 'How to name torrent downloads (1 = rename to '
      'torrent name, 2 = save under name in torrent, 3 = save in directory '
      'under torrent name)'),
     ('display_path', 0, 'whether to display the full path or the torrent '
      'contents for each torrent'),
 ])
 try:
     configdir = ConfigDir('launchmanycurses')
     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 '
                      'btlaunchmanycurses.py)'))
     if len(sys.argv) < 2:
         print "Usage: btlaunchmanycurses.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:
Esempio n. 8
0
def run(params):
    h = HeadlessDisplayer()
    while 1:
        configdir = ConfigDir('downloadheadless')
        defaultsToIgnore = ['metafile', '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: {}\n'.format(e),
                  'run 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()
        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 - ", e)
                h.failed()
                return

        metainfo = get_metainfo(config['metafile'], config['url'], h.error)
        if not metainfo:
            break

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

        dow = BT1Download(
            h.display, h.finished, h.error, disp_exception, doneflag, config,
            metainfo, 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 Exception:
        pass
    if not h.done:
        h.failed()
Esempio n. 9
0
def run(scrwin, errlist, params):
    doneflag = threading.Event()
    d = CursesDisplayer(scrwin, errlist, doneflag)
    try:
        while 1:
            configdir = ConfigDir("downloadcurses")
            defaultsToIgnore = ["metafile", "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

            metainfo = get_metainfo(config["metafile"], config["url"], d.error)
            if not metainfo:
                break

            infohash = hashlib.sha1(bencode(metainfo["info"])).digest()

            dow = BT1Download(
                d.display,
                d.finished,
                d.error,
                d.error,
                doneflag,
                config,
                metainfo,
                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 Exception:
        pass
    if not d.done:
        d.failed()