Example #1
0
                elif version >= 4:
                    up, down = line[41:-1].split(' ', 1)
                    t.uptotal = t.uptotal_old = int(up)
                    t.downtotal = t.downtotal_old = int(down)
            except ValueError:  # unpack, int(), decode()
                raise BTFailure(_("Invalid state file (bad entry)"))

            torrent_config = self.config
            try:
                if version < 5:
                    torrent_config = configfile.read_torrent_config(
                        self.config, self.data_dir, infohash,
                        lambda s: self.global_error(logging.ERROR, s))
                else:
                    torrent_config = self._read_torrent_config(infohash)
                t.update_config(torrent_config)
            except BTFailure, e:
                self.logger.error("Read torrent config failed",
                                  exc_info=sys.exc_info())
                # if read_torrent_config fails then ignore the torrent...
                return None

            return infohash, t

        # BEGIN _restore_state
        assert self.resume_from_torrent_config
        filename = os.path.join(self.data_dir, 'ui_state')
        if not os.path.exists(filename):
            return
        f = None
        try:
                    t.uptotal = t.uptotal_old = int(up)
                    t.downtotal = t.downtotal_old = int(down)
            except ValueError:  # unpack, int(), decode()
                raise BTFailure(_("Invalid state file (bad entry)"))

            torrent_config = self.config
            try:
                if version < 5:
                    torrent_config = configfile.read_torrent_config(
                                                           self.config,
                                                           self.data_dir,
                                                           infohash,
                                                           lambda s : self.global_error(logging.ERROR, s))
                else:
                    torrent_config = self._read_torrent_config(infohash)
                t.update_config(torrent_config)
            except BTFailure, e:
                self.logger.error("Read torrent config failed",
                                  exc_info=sys.exc_info())
                # if read_torrent_config fails then ignore the torrent...
                return None

            return infohash, t
        # BEGIN _restore_state
        assert self.resume_from_torrent_config
        filename = os.path.join(self.data_dir, 'ui_state')
        if not os.path.exists(filename):
            return
        f = None
        try:
            f = file(filename, 'rb')