Example #1
0
        def downloadURL(self, dest_path, url):
            uiname   = 'bittorrent-console'
            defaults = get_defaults(uiname)
            
            # TODO: Bring these in from the plugin's config?
            config_in  = {
                'save_in':                  dest_path,
                'display_interval':         10,
                'max_upload_rate':          8,
                'start_trackerless_client': True,
                'spew':                     False,
                'max_startup_wait':         2 * 60
            }

            try:
                config, args = configfile.parse_configuration_and_args\
                        (defaults, uiname, [], 0, 0)

                config.update(config_in)
                
                metainfo, errors = GetTorrent.get(url)
                if errors:
                    raise BTFailure(_("Error reading .torrent file: ") +\
                        '\n'.join(errors))

            except BTFailure, e:
                self.log.exception("Problem initializing torrent")
                return []
Example #2
0
    def _get_torrent_then_callback(self, name, save_as=None):
        data, errors = GetTorrent.get_quietly(name)

        if data:
            self.start_new_torrent(data, save_as)
        for error in errors:
            self.run_ui_task(self.ui.global_error, ERROR, error)
    def add_task(self, taskid, torrentfile, singledl_config = {}, sha1=None, is_persistent_tasks = True, expire = 0):
	'''
	    would raise Exception if something is wrong
	'''
        if sha1 and self.dls.has_key(sha1):
            self._logger.error('sha1: %s is already downloading', sha1)
            return self.dls[sha1][0]

        for (hash_info, (dl, f)) in self.dls.items():
            if f == torrentfile:
                status = dl.get_activity()
                self._logger.error('file: %s already downloading, status: %s', f, status)
                return dl

        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))

	self.check_whether_can_add_task()

        dl = DL(taskid, metainfo, self.config, singledl_config, self.multitorrent, self.doneflag)
        dl.start()

        expire = self.expire_time if expire <= 0 else expire
        self.tasks[dl.hash_info] = {'taskid': taskid, 'torrentfile': torrentfile, 'status':{},'config':singledl_config,
                                    'begintime': int(time.time()), 'expire': expire}
        self.dls[dl.hash_info] = (dl, torrentfile)
        if is_persistent_tasks:
            self.persistent_tasks(self.tasks)
        return dl
Example #4
0
    def _get_torrent_then_callback(self, name, save_as=None):
        data, errors = GetTorrent.get_quietly(name)

        if data:
            self.start_new_torrent(data, save_as)
        for error in errors:
            self.run_ui_task(self.ui.global_error, ERROR, error)
Example #5
0
    def main(self):
        print "TorrentClient.run"
        """Main loop"""
        uiname = 'bittorrent-console'
        defaults = get_defaults(uiname)
        defaults.append((
            'twisted', 0,
            _("Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted"
              )))

        metainfo = None
        config, args = configfile.parse_configuration_and_args(
            defaults, uiname)

        try:
            metainfo, errors = GetTorrent.get(self.torrentfilename)
            if errors:
                raise BTFailure(
                    _("Error reading .torrent file: ") + '\n'.join(errors))
            else:
                self.dl = DLKamaelia(metainfo, config, self)
                self.dl.run()
        except BTFailure, e:
            print str(e)
            sys.exit(1)
    def main(self):
        print "TorrentClient.run"
        """Main loop"""
        uiname = "bittorrent-console"
        defaults = get_defaults(uiname)
        defaults.append(
            (
                "twisted",
                0,
                _(
                    "Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted"
                ),
            )
        )

        metainfo = None
        config, args = configfile.parse_configuration_and_args(defaults, uiname)

        try:
            metainfo, errors = GetTorrent.get(self.torrentfilename)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + "\n".join(errors))
            else:
                self.dl = DLKamaelia(metainfo, config, self)
                self.dl.run()
        except BTFailure, e:
            print str(e)
            sys.exit(1)
Example #7
0
 def _get_torrent(self, installer_url):
     """Get the .torrent file from the version site."""
     torrentfile = None
     try:
         torrentfile = GetTorrent.get_url(installer_url)
     except GetTorrent.GetTorrentException, e:
         self.debug('_get_torrent() run#%d: failed to download torrent file %s: %s' %
                    (self.runs, installer_url, str_exc(e)))
         pass
Example #8
0
 def _get_torrent(self, installer_url):
     """Get the .torrent file from the version site."""
     torrentfile = None
     try:
         torrentfile = GetTorrent.get_url(installer_url)
     except GetTorrent.GetTorrentException, e:
         self.debug(
             '_get_torrent() run#%d: failed to download torrent file %s: %s'
             % (self.runs, installer_url, str_exc(e)))
         pass
Example #9
0
 def main(self):
     print "TorrentClient.run"
     """Main loop"""
     uiname = 'bittorrent-console'
     defaults = get_defaults(uiname)
     defaults["twisted"] = 0
     metainfo = None
     config, args = configfile.parse_configuration_and_args(defaults, uiname)
     try:
         metainfo, errors = GetTorrent.get( self.torrentfilename )
         if errors:
             raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
         else:
             self.dl = DLKamaelia(metainfo, config, self)
             self.dl.run()
     except BTFailure, e:
         print str(e)
         sys.exit(1)
Example #10
0
 def main(self):
     print "TorrentClient.run"
     """Main loop"""
     uiname = 'bittorrent-console'
     defaults = get_defaults(uiname)
     defaults["twisted"] = 0
     metainfo = None
     config, args = configfile.parse_configuration_and_args(
         defaults, uiname)
     try:
         metainfo, errors = GetTorrent.get(self.torrentfilename)
         if errors:
             raise BTFailure(
                 _("Error reading .torrent file: ") + '\n'.join(errors))
         else:
             self.dl = DLKamaelia(metainfo, config, self)
             self.dl.run()
     except BTFailure, e:
         print str(e)
         sys.exit(1)
    if len(sys.argv) <= 1:
        printHelp(uiname, defaults)
        sys.exit(1)
    try:
        config, args = configfile.parse_configuration_and_args(defaults,
                                       uiname, sys.argv[1:], 0, 1)

        torrentfile = None
        if len(args):
            torrentfile = args[0]
        for opt in ('responsefile', 'url'):
            if config[opt]:
                print '"--%s"' % opt, _("deprecated, do not use")
                torrentfile = config[opt]
        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))
    except BTFailure, e:
        print str(e)
        sys.exit(1)

    errlist = []
    dl = DL(metainfo, config, errlist)
    curses_wrapper(dl.run)

    if errlist:
       print _("These errors occurred during execution:")
       for error in errlist:
Example #12
0
class Updater(object):
    def __init__(self,
                 threadwrap,
                 newversionfunc,
                 startfunc,
                 installfunc,
                 errorfunc,
                 test_new_version='',
                 test_current_version=''):
        self.threadwrap = threadwrap  # for calling back to UI from thread
        self.newversionfunc = newversionfunc  # alert to new version UI function
        self.startfunc = startfunc  # start torrent UI function
        self.installfunc = installfunc  # install torrent UI function
        self.errorfunc = errorfunc  # report error UI function
        self.infohash = None
        self.version = currentversion
        self.currentversion = currentversion
        self.asked_for_install = False
        self.version_site = version_host
        if os.name == 'nt':
            self.version_site += 'win32/'
            if os_version not in ('XP', '2000', '2003'):
                self.version_site += 'legacy/'
        elif osx:
            self.version_site += 'osx/'
        self.debug_mode = DEBUG
        if test_new_version:
            test_new_version = Version.from_str(test_new_version)
            self.debug_mode = True

            def _hack_get_available(url):
                return test_new_version

            self._get_available = _hack_get_available
        if test_current_version:
            self.debug_mode = True
            self.currentversion = Version.from_str(test_current_version)

    def debug(self, message):
        if self.debug_mode:
            self.threadwrap(self.errorfunc, WARNING, message)

    def _get_available(self, url):
        self.debug('Updater.get_available() hitting url %s' % url)
        try:
            u = zurllib.urlopen(url)
            s = u.read()
            s = s.strip()
        except:
            raise BTFailure(_("Could not get latest version from %s") % url)
        try:
            assert len(s) == 5
            availableversion = Version.from_str(s)
        except:
            raise BTFailure(
                _("Could not parse new version string from %s") % url)
        return availableversion

    def get_available(self):
        url = self.version_site + self.currentversion.name()
        availableversion = self._get_available(url)
        if availableversion.is_beta():
            if availableversion[1] != self.currentversion[1]:
                availableversion = self.currentversion
        if self.currentversion.is_beta():
            stable_url = self.version_site + 'stable'
            available_stable_version = self._get_available(stable_url)
            if available_stable_version > availableversion:
                availableversion = available_stable_version
        self.version = availableversion
        self.debug('Updater.get_available() got %s' % str(self.version))
        return self.version

    def get(self):
        try:
            self.get_available()
        except BTFailure, e:
            self.threadwrap(self.errorfunc, WARNING, e)
            return

        if self.version <= self.currentversion:
            self.debug('Updater.get() not updating old version %s' %
                       str(self.version))
            return

        if not self.can_install():
            self.debug('Updater.get() cannot install on this os')
            return

        self.installer_name = self.calc_installer_name()
        self.installer_url = self.version_site + self.installer_name + '.torrent'
        self.installer_dir = self.calc_installer_dir()

        self.torrentfile = None
        torrentfile, terrors = GetTorrent.get_url(self.installer_url)
        signature = None
        try:
            signfile = zurllib.urlopen(self.installer_url + '.sign')
        except:
            self.debug('Updater.get() failed to get signfile %s.sign' %
                       self.installer_url)
        else:
            try:
                signature = pickle.load(signfile)
            except:
                self.debug('Updater.get() failed to load signfile %s' %
                           signfile)

        if terrors:
            self.threadwrap(self.errorfunc, WARNING, '\n'.join(terrors))

        if torrentfile and signature:
            public_key_file = open(os.path.join(doc_root, 'public.key'), 'rb')
            public_key = pickle.load(public_key_file)
            h = sha(torrentfile).digest()
            if public_key.verify(h, signature):
                self.torrentfile = torrentfile
                b = bdecode(torrentfile)
                self.infohash = sha(bencode(b['info'])).digest()
                self.total_size = b['info']['length']
                self.debug('Updater.get() got torrent file and signature')
            else:
                self.debug(
                    'Updater.get() torrent file signature failed to verify.')
                pass
        else:
            self.debug(
                'Updater.get() doesn\'t have torrentfile %s and signature %s' %
                (str(type(torrentfile)), str(type(signature))))
Example #13
0
    if len(sys.argv) <= 1:
        printHelp(uiname, defaults)
        sys.exit(1)
    try:
        config, args = configfile.parse_configuration_and_args(
            defaults, uiname, sys.argv[1:], 0, 1)

        torrentfile = None
        if len(args):
            torrentfile = args[0]
        for opt in ('responsefile', 'url'):
            if config[opt]:
                print '"--%s"' % opt, _("deprecated, do not use")
                torrentfile = config[opt]
        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(
                    _("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))
    except BTFailure, e:
        print str(e)
        sys.exit(1)

    errlist = []
    dl = DL(metainfo, config, errlist)
    curses_wrapper(dl.run)

    if errlist:
        print _("These errors occurred during execution:")
Example #14
0
    for p in to_add:                # then, parse new and changed torrents
        new_file = new_files[p]
        v = new_file[0]             # new_file[0] is the file's (mod time,sz).
        infohash = new_file[1]
        if infohash in new_parsed:  # duplicate, i.e., have same infohash.
            if p not in blocked or files[p][0] != v:
                errfunc(_("**warning** %s is a duplicate torrent for %s") %
                        (p, new_parsed[infohash]['path']))
            new_blocked.add(p)
            continue

        if NOISY:
            errfunc('adding '+p)

        try:
            metainfo = GetTorrent.get(p)
            new_file[1] = metainfo.infohash

            #ff = open(p, 'rb')
            #d = bdecode(ff.read())
            #check_message(d)
            #h = sha(bencode(d['info'])).digest()
            #new_file[1] = h
            if new_parsed.has_key(metainfo.infohash):
                errfunc(_("**warning** %s is a duplicate torrent for %s") %
                        (p, new_parsed[metainfo.infohash][0]))
                new_blocked.add(p)
                continue
            
            #a = {}
            #a['path'] = p