diff --git a/ChangeLog b/ChangeLog index 4081879ae..a53e1edc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/bindings/python/make_torrent.py b/bindings/python/make_torrent.py index 90c19b3d2..4b68ae81e 100644 --- a/bindings/python/make_torrent.py +++ b/bindings/python/make_torrent.py @@ -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() + diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index d94923ca1..f486b5a13 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -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); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 799cbc022..58aed73ee 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -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))