diff --git a/.gitignore b/.gitignore index 810f03485..bf75a8a17 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ *.exe *.out *.app +libtool *.m4 *.in @@ -50,3 +51,8 @@ bindings/python/*flags # Logs libtorrent_logs* *.log + +# Python related files and dirs +*.pyc +dist +*.egg-info diff --git a/bindings/python/compile_flags.in b/bindings/python/compile_flags.in index 701d89862..d51261c10 100644 --- a/bindings/python/compile_flags.in +++ b/bindings/python/compile_flags.in @@ -1 +1 @@ --I@top_srcdir@/include @COMPILETIME_OPTIONS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @OPENSSL_INCLUDES@ +-I@top_srcdir@/include @COMPILETIME_OPTIONS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @PYTHON_CXXFLAGS@ @OPENSSL_INCLUDES@ diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 5a8ff4c44..66b6bd3ae 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -191,12 +191,6 @@ void dict_to_announce_entry(dict d, announce_entry& ae) ae.tier = extract(d["tier"]); if (d.has_key("fail_limit")) ae.fail_limit = extract(d["fail_limit"]); - if (d.has_key("source")) - ae.source = extract(d["source"]); - if (d.has_key("verified")) - ae.verified = extract(d["verified"]); - if (d.has_key("send_stats")) - ae.send_stats = extract(d["send_stats"]); } void replace_trackers(torrent_handle& h, object trackers) @@ -245,6 +239,14 @@ list trackers(torrent_handle& h) { dict d; d["url"] = i->url; + d["trackerid"] = i->trackerid; + d["message"] = i->message; + d["last_error"] = i->last_error; + d["next_announce"] = i->next_announce; + d["min_announce"] = i->min_announce; + d["scrape_incomplete"] = i->scrape_incomplete; + d["scrape_complete"] = i->scrape_complete; + d["scrape_downloaded"] = i->scrape_downloaded; d["tier"] = i->tier; d["fail_limit"] = i->fail_limit; d["fails"] = i->fails; diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 97afbb447..a5a01ef2c 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -18,6 +18,7 @@ using namespace boost::python; using namespace libtorrent; +namespace lt = libtorrent; namespace { @@ -126,10 +127,10 @@ namespace return result; } - int get_tier(announce_entry const& ae) { return ae.tier; } - void set_tier(announce_entry& ae, int v) { ae.tier = v; } - int get_fail_limit(announce_entry const& ae) { return ae.fail_limit; } - void set_fail_limit(announce_entry& ae, int l) { ae.fail_limit = l; } + // Create getters for announce_entry data members with non-trivial types which need converting. + lt::time_point get_next_announce(announce_entry const& ae) { return ae.next_announce; } + lt::time_point get_min_announce(announce_entry const& ae) { return ae.min_announce; } + // announce_entry data member bit-fields. int get_fails(announce_entry const& ae) { return ae.fails; } int get_source(announce_entry const& ae) { return ae.source; } bool get_verified(announce_entry const& ae) { return ae.verified; } @@ -137,6 +138,11 @@ namespace bool get_start_sent(announce_entry const& ae) { return ae.start_sent; } bool get_complete_sent(announce_entry const& ae) { return ae.complete_sent; } bool get_send_stats(announce_entry const& ae) { return ae.send_stats; } + // announce_entry method requires lt::time_point. + bool can_announce(announce_entry const& ae, bool is_seed) { + lt::time_point now = lt::clock_type::now(); + return ae.can_announce(now, is_seed); + } #ifndef TORRENT_NO_DEPRECATE boost::int64_t get_size(file_entry const& fe) { return fe.size; } @@ -307,8 +313,16 @@ void bind_torrent_info() class_("announce_entry", init()) .def_readwrite("url", &announce_entry::url) - .add_property("tier", &get_tier, &set_tier) - .add_property("fail_limit", &get_fail_limit, &set_fail_limit) + .def_readonly("trackerid", &announce_entry::trackerid) + .def_readonly("message", &announce_entry::message) + .def_readonly("last_error", &announce_entry::last_error) + .add_property("next_announce", &get_next_announce) + .add_property("min_announce", &get_min_announce) + .def_readonly("scrape_incomplete", &announce_entry::scrape_incomplete) + .def_readonly("scrape_complete", &announce_entry::scrape_complete) + .def_readonly("scrape_downloaded", &announce_entry::scrape_downloaded) + .def_readwrite("tier", &announce_entry::tier) + .def_readwrite("fail_limit", &announce_entry::fail_limit) .add_property("fails", &get_fails) .add_property("source", &get_source) .add_property("verified", &get_verified) @@ -317,8 +331,10 @@ void bind_torrent_info() .add_property("complete_sent", &get_complete_sent) .add_property("send_stats", &get_send_stats) + .def("next_announce_in", &announce_entry::next_announce_in) + .def("min_announce_in", &announce_entry::min_announce_in) .def("reset", &announce_entry::reset) - .def("can_announce", &announce_entry::can_announce) + .def("can_announce", can_announce) .def("is_working", &announce_entry::is_working) .def("trim", &announce_entry::trim) ; diff --git a/bindings/python/test.py b/bindings/python/test.py index 51fa5260e..3ffa8c9ed 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -57,6 +57,20 @@ class test_torrent_handle(unittest.TestCase): self.h.prioritize_pieces([(0, 1)]) self.assertEqual(self.h.piece_priorities(), [1]) + def test_replace_trackers(self): + self.setup() + trackers = [] + for idx, tracker_url in enumerate(('udp://tracker1.com', 'udp://tracker2.com')): + tracker = lt.announce_entry(tracker_url) + tracker.tier = idx + tracker.fail_limit = 2 + trackers.append(tracker) + self.h.replace_trackers(trackers) + new_trackers = self.h.trackers() + self.assertEqual(new_trackers[0]['url'], 'udp://tracker1.com') + self.assertEqual(new_trackers[1]['tier'], 1) + self.assertEqual(new_trackers[1]['fail_limit'], 2) + def test_file_status(self): self.setup() l = self.h.file_status() @@ -138,6 +152,12 @@ class test_torrent_info(unittest.TestCase): self.assertEqual(os.path.split(os.path.split(f.path)[0]), ('temp', 'foo')) idx += 1 + def test_announce_entry(self): + ae = lt.announce_entry('test') + self.assertEquals(ae.can_announce(False), True) + self.assertEquals(ae.scrape_incomplete, -1) + self.assertEquals(ae.next_announce, None) + class test_alerts(unittest.TestCase): def test_alert(self): diff --git a/configure.ac b/configure.ac index 4aba9b2e2..c08e19dfc 100644 --- a/configure.ac +++ b/configure.ac @@ -556,6 +556,9 @@ AC_SUBST(DEBUGFLAGS) AC_SUBST(PYTHON_INSTALL_PARAMS) AC_SUBST(COMPILETIME_OPTIONS) +# Disable deprecated warnings for the Python binding builds. +PYTHON_CXXFLAGS="${PYTHON_CXXFLAGS} -Wno-deprecated-declarations" +AC_SUBST(PYTHON_CXXFLAGS) # Try to guess real git revision if any, fallback to hardcoded otherwise GIT_REVISION=`git log -1 --format=format:%h 2>/dev/null`