From 6186e3fce71cbbe22cfef47148fbfea65f8a0d6a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 19 Apr 2007 01:26:23 +0000 Subject: [PATCH] attempt to fix #12 --- bindings/python/client.py | 22 +++++++++++++-- bindings/python/src/torrent_handle.cpp | 37 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/bindings/python/client.py b/bindings/python/client.py index e83ca17fb..590423218 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -146,6 +146,24 @@ def print_peer_info(console, peers): write_line(console, out) + +def print_download_queue(console, download_queue): + + out = "" + + for e in download_queue: + out += '%4d: [' % e['piece_index']; + finished_blocks = e['finished_blocks'] + requested_blocks = e['requested_blocks'] + for index in xrange(len(e['peers'])) + if (finished_blocks[index]) + out += '#' + elif requested_blocks[index] + out += '+' + else + out += '-' + out += ']\n' + def main(): from optparse import OptionParser @@ -279,8 +297,8 @@ def main(): write_line(console, out) - peers = h.get_peer_info() - print_peer_info(console, peers) + print_peer_info(console, h.get_peer_info()) + print_download_queue(console, h.get_download_queue()) if True and s.state != lt.torrent_status.seeding: out = '\n' diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 9f071abab..ad854097f 100755 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -84,6 +84,42 @@ void replace_trackers(torrent_handle& info, object trackers) info.replace_trackers(result); } +list get_download_queue(torrent_handle& handle) +{ + list ret; + + std::vector downloading; + + { + allow_threading_guard guard; + handle.get_download_queue(downloading); + } + + for (std::vector::iterator i = downloading.begin() + , end(downloading.end()); i != end; ++i) + { + dict partial_piece; + partial_piece["piece_index"] = i->piece_index; + partial_piece["blocks_in_piece"] = i->blocks_in_piece; + list requested; + list finished; + list peer; + for (int k = 0; k < i->blocks_in_piece; ++k) + { + requested.extend(i->requested_blocks[k]); + finished.extend(i->finished_blocks[k]); + peer.extend(i->peer[k]); + } + partial_piece["requested_blocks"] = requested; + partial_piece["finished_blocks"] = finished; + partial_piece["peer"] = peer; + + ret.extend(partial_piece); + } + + return ret; +} + void bind_torrent_handle() { void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce; @@ -123,6 +159,7 @@ void bind_torrent_handle() .def("trackers", range(begin_trackers, end_trackers)) .def("replace_trackers", replace_trackers) .def("get_peer_info", get_peer_info) + .def("get_download_queue", get_download_queue) ; }