I use a VPN service with my torrenting and have written a bash script for controlling openvpn. To complement the bash script I wrote a few python scripts to interact with deluge. First I was happy that the torrents all go paused when the tunnel went down and resumed when it went up. But there were room for improvements like automatically setting the correct listen port (it's random, but easy to calculate on my side, on each connect with my VPN-provider) and set deluged to add torrents in paused mode when not in a tunnel (to avoid unprotected downloading, it's just not safe anymore ;o)
The script I have now (a bit bloated by debug stuff but still short):
Code: Select all
#!/usr/bin/python
from deluge.ui.client import client
from twisted.internet import reactor
import sys
d = client.connect()
def on_connect_success(result):
def on_set_active(status):
print status
def on_set_port(status):
print status
def on_get_port(status):
print sys.argv[1]," == ",status,"?"
client.disconnect()
reactor.stop()
client.core.set_config({"active_port":sys.argv[1]}).addCallback(on_set_active)
client.core.set_config({"listen_ports":[sys.argv[1], sys.argv[1]]}).addCallback(on_set_port)
client.core.get_listen_port().addCallback(on_get_port)
d.addCallback(on_connect_success)
def on_connect_fail(result):
print "connection to deluge failed"
d.addErrback(on_connect_fail)
reactor.run()
So the gist is that it changes the listen_ports just fine but not the active_port and I cant figure out how to do it ... Any help would be great ...
I'm not a great python programmer (I prefer Ruby myself) but I get around. Most of this is copy paste and some modifications of stuff I found in the forums, docs and by browsing the deluge source code. I might be way off here, there might be better ways to do stuff and I'll happily update the script with any suggestions. Just don't forget the main issue ;o)
My specs:
Ubuntu 10.10 x64
Deluge 1.3
libTorrent 0.15.4.0
GTK and CLI UI
localhost server, but in daemon mode
no special user or server config
Thank you for your time!