forked from premiere/premiere-libtorrent
Add missing announce_entry properties to python bindings
Fix and refactor the announce_entry class - Removed verified from torrent_handle dict to announce_entry as it's read-only. - Changed source and send_stats to read_write properties. - Switched trivial type properties to using read_only or read_write.
This commit is contained in:
parent
964542e53b
commit
de30f357b3
|
@ -26,6 +26,7 @@
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
libtool
|
||||||
|
|
||||||
*.m4
|
*.m4
|
||||||
*.in
|
*.in
|
||||||
|
@ -50,3 +51,8 @@ bindings/python/*flags
|
||||||
# Logs
|
# Logs
|
||||||
libtorrent_logs*
|
libtorrent_logs*
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
# Python related files and dirs
|
||||||
|
*.pyc
|
||||||
|
dist
|
||||||
|
*.egg-info
|
||||||
|
|
|
@ -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@
|
||||||
|
|
|
@ -191,12 +191,6 @@ void dict_to_announce_entry(dict d, announce_entry& ae)
|
||||||
ae.tier = extract<int>(d["tier"]);
|
ae.tier = extract<int>(d["tier"]);
|
||||||
if (d.has_key("fail_limit"))
|
if (d.has_key("fail_limit"))
|
||||||
ae.fail_limit = extract<int>(d["fail_limit"]);
|
ae.fail_limit = extract<int>(d["fail_limit"]);
|
||||||
if (d.has_key("source"))
|
|
||||||
ae.source = extract<int>(d["source"]);
|
|
||||||
if (d.has_key("verified"))
|
|
||||||
ae.verified = extract<bool>(d["verified"]);
|
|
||||||
if (d.has_key("send_stats"))
|
|
||||||
ae.send_stats = extract<bool>(d["send_stats"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void replace_trackers(torrent_handle& h, object trackers)
|
void replace_trackers(torrent_handle& h, object trackers)
|
||||||
|
@ -245,6 +239,14 @@ list trackers(torrent_handle& h)
|
||||||
{
|
{
|
||||||
dict d;
|
dict d;
|
||||||
d["url"] = i->url;
|
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["tier"] = i->tier;
|
||||||
d["fail_limit"] = i->fail_limit;
|
d["fail_limit"] = i->fail_limit;
|
||||||
d["fails"] = i->fails;
|
d["fails"] = i->fails;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
namespace lt = libtorrent;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -126,10 +127,10 @@ namespace
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_tier(announce_entry const& ae) { return ae.tier; }
|
// Create getters for announce_entry data members with non-trivial types which need converting.
|
||||||
void set_tier(announce_entry& ae, int v) { ae.tier = v; }
|
lt::time_point get_next_announce(announce_entry const& ae) { return ae.next_announce; }
|
||||||
int get_fail_limit(announce_entry const& ae) { return ae.fail_limit; }
|
lt::time_point get_min_announce(announce_entry const& ae) { return ae.min_announce; }
|
||||||
void set_fail_limit(announce_entry& ae, int l) { ae.fail_limit = l; }
|
// announce_entry data member bit-fields.
|
||||||
int get_fails(announce_entry const& ae) { return ae.fails; }
|
int get_fails(announce_entry const& ae) { return ae.fails; }
|
||||||
int get_source(announce_entry const& ae) { return ae.source; }
|
int get_source(announce_entry const& ae) { return ae.source; }
|
||||||
bool get_verified(announce_entry const& ae) { return ae.verified; }
|
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_start_sent(announce_entry const& ae) { return ae.start_sent; }
|
||||||
bool get_complete_sent(announce_entry const& ae) { return ae.complete_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; }
|
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
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
boost::int64_t get_size(file_entry const& fe) { return fe.size; }
|
boost::int64_t get_size(file_entry const& fe) { return fe.size; }
|
||||||
|
@ -307,8 +313,16 @@ void bind_torrent_info()
|
||||||
|
|
||||||
class_<announce_entry>("announce_entry", init<std::string const&>())
|
class_<announce_entry>("announce_entry", init<std::string const&>())
|
||||||
.def_readwrite("url", &announce_entry::url)
|
.def_readwrite("url", &announce_entry::url)
|
||||||
.add_property("tier", &get_tier, &set_tier)
|
.def_readonly("trackerid", &announce_entry::trackerid)
|
||||||
.add_property("fail_limit", &get_fail_limit, &set_fail_limit)
|
.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("fails", &get_fails)
|
||||||
.add_property("source", &get_source)
|
.add_property("source", &get_source)
|
||||||
.add_property("verified", &get_verified)
|
.add_property("verified", &get_verified)
|
||||||
|
@ -317,8 +331,10 @@ void bind_torrent_info()
|
||||||
.add_property("complete_sent", &get_complete_sent)
|
.add_property("complete_sent", &get_complete_sent)
|
||||||
.add_property("send_stats", &get_send_stats)
|
.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("reset", &announce_entry::reset)
|
||||||
.def("can_announce", &announce_entry::can_announce)
|
.def("can_announce", can_announce)
|
||||||
.def("is_working", &announce_entry::is_working)
|
.def("is_working", &announce_entry::is_working)
|
||||||
.def("trim", &announce_entry::trim)
|
.def("trim", &announce_entry::trim)
|
||||||
;
|
;
|
||||||
|
|
|
@ -57,6 +57,20 @@ class test_torrent_handle(unittest.TestCase):
|
||||||
self.h.prioritize_pieces([(0, 1)])
|
self.h.prioritize_pieces([(0, 1)])
|
||||||
self.assertEqual(self.h.piece_priorities(), [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):
|
def test_file_status(self):
|
||||||
self.setup()
|
self.setup()
|
||||||
l = self.h.file_status()
|
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'))
|
self.assertEqual(os.path.split(os.path.split(f.path)[0]), ('temp', 'foo'))
|
||||||
idx += 1
|
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):
|
class test_alerts(unittest.TestCase):
|
||||||
|
|
||||||
def test_alert(self):
|
def test_alert(self):
|
||||||
|
|
|
@ -556,6 +556,9 @@ AC_SUBST(DEBUGFLAGS)
|
||||||
AC_SUBST(PYTHON_INSTALL_PARAMS)
|
AC_SUBST(PYTHON_INSTALL_PARAMS)
|
||||||
AC_SUBST(COMPILETIME_OPTIONS)
|
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
|
# Try to guess real git revision if any, fallback to hardcoded otherwise
|
||||||
GIT_REVISION=`git log -1 --format=format:%h 2>/dev/null`
|
GIT_REVISION=`git log -1 --format=format:%h 2>/dev/null`
|
||||||
|
|
Loading…
Reference in New Issue