Update python bindings in RC branch

This commit is contained in:
Andrew Resch 2008-10-07 08:42:51 +00:00
parent eafb404b7b
commit a168265753
4 changed files with 101 additions and 39 deletions

View file

@ -278,6 +278,7 @@ void bind_alert()
class_<file_renamed_alert, bases<torrent_alert>, noncopyable>(
"file_renamed_alert", no_init
)
.def_readonly("index", &file_renamed_alert::index)
.def_readonly("name", &file_renamed_alert::name)
;
@ -285,6 +286,7 @@ void bind_alert()
"file_rename_failed_alert", no_init
)
.def_readonly("index", &file_rename_failed_alert::index)
.def_readonly("msg", &file_rename_failed_alert::msg)
;
class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>(

View file

@ -0,0 +1,54 @@
// Copyright Andrew Resch 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
#include <libtorrent/session.hpp>
#include <libtorrent/torrent.hpp>
#include <libtorrent/magnet_uri.hpp>
#include <boost/python.hpp>
#include "gil.hpp"
using namespace boost::python;
using namespace libtorrent;
namespace {
torrent_handle _add_magnet_uri(session& s, std::string uri, dict params)
{
add_torrent_params p;
std::string url;
if (params.has_key("tracker_url"))
{
url = extract<std::string>(params["tracker_url"]);
p.tracker_url = url.c_str();
}
std::string name;
if (params.has_key("name"))
{
name = extract<std::string>(params["name"]);
p.name = name.c_str();
}
p.save_path = fs::path(extract<std::string>(params["save_path"]));
std::vector<char> resume_buf;
if (params.has_key("resume_data"))
{
std::string resume = extract<std::string>(params["resume_data"]);
resume_buf.resize(resume.size());
std::memcpy(&resume_buf[0], &resume[0], resume.size());
p.resume_data = &resume_buf;
}
p.storage_mode = extract<storage_mode_t>(params["storage_mode"]);
p.paused = params["paused"];
p.auto_managed = params["auto_managed"];
p.duplicate_is_error = params["duplicate_is_error"];
return add_magnet_uri(s, uri, p);
}
}
void bind_magnet_uri()
{
def("add_magnet_uri", &_add_magnet_uri);
}

View file

@ -317,6 +317,7 @@ void bind_torrent_handle()
.def("move_storage", _(&torrent_handle::move_storage))
.def("info_hash", _(&torrent_handle::info_hash))
.def("force_recheck", _(&torrent_handle::force_recheck))
.def("rename_file", _(&torrent_handle::rename_file))
;
}

View file

@ -12,58 +12,61 @@ using namespace libtorrent;
namespace
{
std::vector<announce_entry>::const_iterator begin_trackers(torrent_info& i)
{
return i.trackers().begin();
}
std::vector<announce_entry>::const_iterator begin_trackers(torrent_info& i)
{
return i.trackers().begin();
}
std::vector<announce_entry>::const_iterator end_trackers(torrent_info& i)
{
return i.trackers().end();
}
std::vector<announce_entry>::const_iterator end_trackers(torrent_info& i)
{
return i.trackers().end();
}
void add_node(torrent_info& ti, char const* hostname, int port)
{
ti.add_node(std::make_pair(hostname, port));
}
void add_node(torrent_info& ti, char const* hostname, int port)
{
ti.add_node(std::make_pair(hostname, port));
}
list nodes(torrent_info const& ti)
{
list result;
list nodes(torrent_info const& ti)
{
list result;
typedef std::vector<std::pair<std::string, int> > list_type;
typedef std::vector<std::pair<std::string, int> > list_type;
for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
{
result.append(make_tuple(i->first, i->second));
}
for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
{
result.append(make_tuple(i->first, i->second));
}
return result;
}
return result;
}
file_storage::iterator begin_files(torrent_info& i)
{
return i.begin_files();
}
file_storage::iterator begin_files(torrent_info& i)
{
return i.begin_files();
}
file_storage::iterator end_files(torrent_info& i)
{
return i.end_files();
}
file_storage::iterator end_files(torrent_info& i)
{
return i.end_files();
}
//list files(torrent_info const& ti, bool storage) {
list files(torrent_info const& ti, bool storage) {
list result;
//list files(torrent_info const& ti, bool storage) {
list files(torrent_info const& ti, bool storage) {
list result;
typedef std::vector<file_entry> list_type;
typedef std::vector<file_entry> list_type;
for (list_type::const_iterator i = ti.begin_files(); i != ti.end_files(); ++i)
result.append(*i);
return result;
}
for (list_type::const_iterator i = ti.begin_files(); i != ti.end_files(); ++i)
result.append(*i);
return result;
}
std::string metadata(torrent_info const& ti) {
std::string result(ti.metadata().get(), ti.metadata_size());
return result;
}
} // namespace unnamed
void bind_torrent_info()
@ -101,6 +104,8 @@ void bind_torrent_info()
.def("add_node", &add_node)
.def("nodes", &nodes)
.def("metadata", &metadata)
.def("metadata_size", &torrent_info::metadata_size)
;
class_<file_entry>("file_entry")