merged python fixes from RC_0_16

This commit is contained in:
Arvid Norberg 2014-03-23 00:49:58 +00:00
parent 6a824ba2df
commit 6120b78704
4 changed files with 44 additions and 3 deletions

View File

@ -43,6 +43,7 @@
* fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP
* add missing add_files overload to the python bindings
* improve error handling in http gunzip
* fix debug logging for banning web seeds
* improve support for de-selected files in full allocation mode

View File

@ -11,7 +11,30 @@ if len(sys.argv) < 3:
input = os.path.abspath(sys.argv[1])
fs = libtorrent.file_storage()
libtorrent.add_files(fs, input)
#def predicate(f):
# print f
# return True
#libtorrent.add_files(fs, input, predicate)
parent_input = os.path.split(input)[0]
for root, dirs, files in os.walk(input):
# skip directories starting with .
if os.path.split(root)[1][0] == '.': continue
for f in files:
# skip files starting with .
if f[0] == '.': continue
# skip thumbs.db on windows
if f == 'Thumbs.db': continue
fname = os.path.join(root[len(parent_input)+1:], f)
size = os.path.getsize(os.path.join(parent_input, fname))
print '%10d kiB %s' % (size / 1024, fname)
fs.add_file(fname, size);
if fs.num_files() == 0:
print 'no files added'
sys.exit(1)
@ -21,7 +44,10 @@ t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
t.add_tracker(sys.argv[2])
t.set_creator('libtorrent %s' % libtorrent.version)
libtorrent.set_piece_hashes(t, os.path.split(input)[0], lambda x: sys.stderr.write('.'))
libtorrent.set_piece_hashes(t, parent_input, lambda x: sys.stderr.write('.'))
sys.stderr.write('\n')
print libtorrent.bencode(t.generate())
f = open('out.torrent', 'wb+')
print >>f, libtorrent.bencode(t.generate())
f.close()

View File

@ -60,6 +60,17 @@ namespace
char const* filestorage_name(file_storage const& fs)
{ return fs.name().c_str(); }
bool call_python_object2(boost::python::object const& obj, std::string& i)
{
return obj(i);
}
void add_files_callback(file_storage& fs, std::string const& file
, boost::python::object cb, boost::uint32_t flags)
{
add_files(fs, file, boost::bind(&call_python_object2, cb, _1), flags);
}
}
void bind_create_torrent()
@ -147,6 +158,8 @@ void bind_create_torrent()
;
def("add_files", add_files0, (arg("fs"), arg("path"), arg("flags") = 0));
def("add_files", add_files_callback, (arg("fs"), arg("path")
, arg("predicate"), arg("flags") = 0));
def("set_piece_hashes", set_piece_hashes0);
def("set_piece_hashes", set_piece_hashes_callback);

View File

@ -398,6 +398,7 @@ namespace libtorrent
void file_storage::add_file(std::string const& file, size_type size, int flags
, std::time_t mtime, std::string const& symlink_path)
{
TORRENT_ASSERT(!is_complete(file));
TORRENT_ASSERT(size >= 0);
if (size < 0) size = 0;
if (!has_parent_path(file))