diff --git a/bindings/README.txt b/bindings/README.txt new file mode 100644 index 000000000..977ca8c1c --- /dev/null +++ b/bindings/README.txt @@ -0,0 +1,3 @@ +Documentation covering building and using the python binding for libtorrent +is located in the main doc directory. See docs/python_binding.html + diff --git a/bindings/python/simple_client.py b/bindings/python/simple_client.py new file mode 100755 index 000000000..b06aba6bc --- /dev/null +++ b/bindings/python/simple_client.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import libtorrent as lt +import time + +ses = lt.session() +ses.listen_on(6881, 6891) + +e = lt.bdecode(open("test.torrent", 'rb').read()) +info = lt.torrent_info(e) + +h = ses.add_torrent(info, "./", compact_mode = True) + +while (not h.is_seed()): + s = h.status() + + state_str = ['queued', 'checking', 'connecting', 'downloading metadata', \ + 'downloading', 'finished', 'seeding', 'allocating'] + print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ + (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \ + s.num_peers, state_str[s.state]) + + time.sleep(1) + diff --git a/bindings/python/src/entry.cpp b/bindings/python/src/entry.cpp index bccba78ce..b24f6a2cf 100755 --- a/bindings/python/src/entry.cpp +++ b/bindings/python/src/entry.cpp @@ -44,9 +44,9 @@ struct entry_to_python return convert(e.list()); case entry::dictionary_t: return convert(e.dict()); + default: + return object(); } - - return object(); } static PyObject* convert(entry const& e) diff --git a/docs/index.html b/docs/index.html index 511dc89c4..53d5ad1d3 100755 --- a/docs/index.html +++ b/docs/index.html @@ -37,7 +37,7 @@
Bindings
Author: | +Arvid Norberg, arvid@rasterbar.com |
---|
Building the libtorrent python bindings will produce a shared library (DLL) +which is a python module that can be imported in a python program.
+The only supported build system for the bindings are currently boost build. To +set up your build environment, you need to add some settings to your +$BOOST_BUILD_PATH/user-config.jam.
+Make sure your user config contains the following line:
++using python : 2.3 ; ++
Set the version to the version of python you have installed or want to use. If +you've installed python in a non-standard location, you have to add the prefix +path used when you installed python as a second option. Like this:
++using python : 2.3 : /usr ; ++
The bindings require at least python version 2.2.
+For more information on how to install and set up boost-build, see the +building libtorrent section.
+Once you have boost-build set up, you cd to the bindings/python +directory and invoke bjam with the apropriate settings. For the available +build variants, see libtorrent build options.
+For example:
++$ bjam dht-support=on release link=static ++
On Mac OS X, this will produce the following python module:
++bin/darwin-4.0/release/dht-support-on/link-static/logging-none/threading-multi/libtorrent.so ++
The python interface is nearly identical to the C++ interface. Please refer to +the main library reference.
+For an example python program, see client.py in the bindings/python +directory.
+A very simple example usage of the module would be something like this:
++import libtorrent as lt +import time + +ses = lt.session() +ses.listen_on(6881, 6891) + +e = lt.bdecode(open("test.torrent", 'rb').read()) +info = lt.torrent_info(e) + +h = ses.add_torrent(info, "./", compact_mode = True) + +while (not h.is_seed()): + s = h.status() + + state_str = ['queued', 'checking', 'connecting', 'downloading metadata', \ + 'downloading', 'finished', 'seeding', 'allocating'] + print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ + (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \ + s.num_peers, state_str[s.state]) + + time.sleep(1) ++