merged python fixes from RC_0_16
This commit is contained in:
parent
6a824ba2df
commit
6120b78704
|
@ -43,6 +43,7 @@
|
||||||
* fix uTP edge case where udp socket buffer fills up
|
* fix uTP edge case where udp socket buffer fills up
|
||||||
* fix nagle implementation in uTP
|
* fix nagle implementation in uTP
|
||||||
|
|
||||||
|
* add missing add_files overload to the python bindings
|
||||||
* improve error handling in http gunzip
|
* improve error handling in http gunzip
|
||||||
* fix debug logging for banning web seeds
|
* fix debug logging for banning web seeds
|
||||||
* improve support for de-selected files in full allocation mode
|
* improve support for de-selected files in full allocation mode
|
||||||
|
|
|
@ -11,7 +11,30 @@ if len(sys.argv) < 3:
|
||||||
input = os.path.abspath(sys.argv[1])
|
input = os.path.abspath(sys.argv[1])
|
||||||
|
|
||||||
fs = libtorrent.file_storage()
|
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:
|
if fs.num_files() == 0:
|
||||||
print 'no files added'
|
print 'no files added'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -21,7 +44,10 @@ t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
|
||||||
t.add_tracker(sys.argv[2])
|
t.add_tracker(sys.argv[2])
|
||||||
t.set_creator('libtorrent %s' % libtorrent.version)
|
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')
|
sys.stderr.write('\n')
|
||||||
|
|
||||||
print libtorrent.bencode(t.generate())
|
f = open('out.torrent', 'wb+')
|
||||||
|
print >>f, libtorrent.bencode(t.generate())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,17 @@ namespace
|
||||||
|
|
||||||
char const* filestorage_name(file_storage const& fs)
|
char const* filestorage_name(file_storage const& fs)
|
||||||
{ return fs.name().c_str(); }
|
{ 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()
|
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_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_hashes0);
|
||||||
def("set_piece_hashes", set_piece_hashes_callback);
|
def("set_piece_hashes", set_piece_hashes_callback);
|
||||||
|
|
||||||
|
|
|
@ -398,6 +398,7 @@ namespace libtorrent
|
||||||
void file_storage::add_file(std::string const& file, size_type size, int flags
|
void file_storage::add_file(std::string const& file, size_type size, int flags
|
||||||
, std::time_t mtime, std::string const& symlink_path)
|
, std::time_t mtime, std::string const& symlink_path)
|
||||||
{
|
{
|
||||||
|
TORRENT_ASSERT(!is_complete(file));
|
||||||
TORRENT_ASSERT(size >= 0);
|
TORRENT_ASSERT(size >= 0);
|
||||||
if (size < 0) size = 0;
|
if (size < 0) size = 0;
|
||||||
if (!has_parent_path(file))
|
if (!has_parent_path(file))
|
||||||
|
|
Loading…
Reference in New Issue