From dfe541ecec0b905407d05b36726925555ba1fce8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 29 Mar 2013 02:46:12 +0000 Subject: [PATCH] merged python fix from RC_0_16 --- ChangeLog | 2 +- bindings/python/client.py | 20 ++++++++++---------- bindings/python/simple_client.py | 5 ++--- bindings/python/src/torrent_info.cpp | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c7198ca8..2bd6fb32c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,7 +20,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP - * add missing functions to python binding (flush_cache() and remap_files()) + * add missing functions to python binding (flush_cache(), remap_files() and orig_files()) * improve handling of filenames that are invalid on windows * support 'implied_port' in DHT announce_peer * don't use pool allocator for disk blocks (cache may now return pages to the kernel) diff --git a/bindings/python/client.py b/bindings/python/client.py index c8429774b..3a244daa8 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright Daniel Wallin 2006. Use, modification and distribution is # subject to the Boost Software License, Version 1.0. (See accompanying @@ -117,11 +117,11 @@ def print_peer_info(console, peers): out += progress_bar(0, 15) out += ' ' - if p.flags & lt.peer_info.handshake: + if p.flags & lt.peer_info.handshake: id = 'waiting for handshake' - elif p.flags & lt.peer_info.connecting: + elif p.flags & lt.peer_info.connecting: id = 'connecting to peer' - elif p.flags & lt.peer_info.queued: + elif p.flags & lt.peer_info.queued: id = 'queued' else: id = p.client @@ -156,22 +156,22 @@ def main(): parser = OptionParser() - parser.add_option('-p', '--port', + parser.add_option('-p', '--port', type='int', help='set listening port') - parser.add_option('-d', '--max-download-rate', + parser.add_option('-d', '--max-download-rate', type='float', help='the maximum download rate given in kB/s. 0 means infinite.') - parser.add_option('-u', '--max-upload-rate', + parser.add_option('-u', '--max-upload-rate', type='float', help='the maximum upload rate given in kB/s. 0 means infinite.') - parser.add_option('-s', '--save-path', + parser.add_option('-s', '--save-path', type='string', help='the path where the downloaded file/folder should be placed.') - parser.add_option('-a', '--allocation-mode', + parser.add_option('-a', '--allocation-mode', type='string', help='sets mode used for allocating the downloaded files on disk. Possible options are [full | compact]') - parser.add_option('-r', '--proxy-host', + parser.add_option('-r', '--proxy-host', type='string', help='sets HTTP proxy host and port (separated by \':\')') parser.set_defaults( diff --git a/bindings/python/simple_client.py b/bindings/python/simple_client.py index 848bfca8f..6b56bb535 100755 --- a/bindings/python/simple_client.py +++ b/bindings/python/simple_client.py @@ -1,8 +1,8 @@ -#!/bin/python +#!/usr/bin/env python # Copyright Arvid Norberg 2008. Use, modification and distribution is # subject to the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - +from __future__ import print_function import libtorrent as lt import time @@ -28,4 +28,3 @@ while (not h.is_seed()): time.sleep(1) print(h.name(), 'complete') - diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index b51c1a7c0..d96a0b1c3 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -71,6 +71,17 @@ namespace return result; } + list orig_files(torrent_info const& ti, bool storage) { + list result; + + file_storage const& st = ti.orig_files(); + + for (int i = 0; i < st.num_files(); ++i) + result.append(st.at(i)); + + return result; + } + std::string hash_for_piece(torrent_info const& ti, int i) { return ti.hash_for_piece(i).to_string(); @@ -111,6 +122,8 @@ namespace size_type get_size(file_entry const& fe) { return fe.size; } size_type get_offset(file_entry const& fe) { return fe.offset; } + size_type get_file_base(file_entry const& fe) { return fe.file_base; } + void set_file_base(file_entry& fe, int b) { fe.file_base = b; } bool get_pad_file(file_entry const& fe) { return fe.pad_file; } bool get_executable_attribute(file_entry const& fe) { return fe.executable_attribute; } bool get_hidden_attribute(file_entry const& fe) { return fe.hidden_attribute; } @@ -162,9 +175,10 @@ void bind_torrent_info() .def("piece_size", &torrent_info::piece_size) .def("num_files", &torrent_info::num_files, (arg("storage")=false)) - .def("file_at", &torrent_info::file_at) + .def("file_at", &torrent_info::file_at) .def("file_at_offset", &torrent_info::file_at_offset) .def("files", &files, (arg("storage")=false)) + .def("orig_files", &orig_files, (arg("storage")=false)) .def("rename_file", rename_file0) #if TORRENT_USE_WSTRING .def("rename_file", rename_file1) @@ -194,6 +208,7 @@ void bind_torrent_info() .add_property("symlink_attribute", &get_symlink_attribute) .add_property("offset", &get_offset) .add_property("size", &get_size) + .add_property("file_base", &get_file_base, &set_file_base) ; class_("announce_entry", init())