python bindings and examples fixes

This commit is contained in:
Arvid Norberg 2008-08-18 12:29:01 +00:00
parent e8d691eed9
commit 59767d0e61
3 changed files with 11 additions and 8 deletions

View File

@ -244,7 +244,7 @@ def main():
resume_data = None
h = ses.add_torrent(info, options.save_path,
resume_data=resume_data, compact_mode=compact_allocation)
resume_data, lt.storage_mode_t.storage_mode_sparse)
handles.append(h)
@ -266,7 +266,7 @@ def main():
for h in handles:
if h.has_metadata():
name = h.torrent_info().name()[:40]
name = h.get_torrent_info().name()[:40]
else:
name = '-'
out += 'name: %-40s\n' % name
@ -306,7 +306,7 @@ def main():
if True and s.state != lt.torrent_status.seeding:
out = '\n'
fp = h.file_progress()
ti = h.torrent_info()
ti = h.get_torrent_info()
for f,p in zip(ti.files(), fp):
out += progress_bar(p, 20)
out += ' ' + f.path + '\n'
@ -349,7 +349,7 @@ def main():
continue
h.pause()
data = lt.bencode(h.write_resume_data())
open(os.path.join(options.save_path, h.torrent_info().name() + '.fastresume'), 'wb').write(data)
open(os.path.join(options.save_path, h.get_torrent_info().name() + '.fastresume'), 'wb').write(data)
main()

View File

@ -13,16 +13,16 @@ ses.listen_on(6881, 6891)
e = lt.bdecode(open("test.torrent", 'rb').read())
info = lt.torrent_info(e)
h = ses.add_torrent(info, "./", compact_mode = True)
h = ses.add_torrent(info, "./")
while (not h.is_seed()):
s = h.status()
state_str = ['queued', 'checking', 'connecting', 'downloading metadata', \
'downloading', 'finished', 'seeding', 'allocating']
print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
s.num_peers, state_str[s.state])
s.num_peers, state_str[s.state]),
time.sleep(1)

View File

@ -4,6 +4,7 @@
#include <libtorrent/torrent_handle.hpp>
#include <boost/python.hpp>
#include <boost/python/tuple.hpp>
#include <boost/lexical_cast.hpp>
#include "gil.hpp"
@ -170,6 +171,8 @@ void replace_trackers(torrent_handle& info, object trackers)
list get_download_queue(torrent_handle& handle)
{
using boost::python::make_tuple;
list ret;
std::vector<partial_piece_info> downloading;
@ -193,7 +196,7 @@ list get_download_queue(torrent_handle& handle)
block_info["num_peers"] = i->blocks[k].num_peers;
block_info["bytes_progress"] = i->blocks[k].bytes_progress;
block_info["block_size"] = i->blocks[k].block_size;
block_info["peer"] = std::make_pair(
block_info["peer"] = make_tuple(
boost::lexical_cast<std::string>(i->blocks[k].peer.address()), i->blocks[k].peer.port());
block_list.append(block_info);
}