I had found this code for serving up a directory with a simple python command.
python -m SimpleHTTPServer 9914
The above command will start a simple HTTP server on port 9914 serving files out of the current directory and below.
For those looking for something just a bit more fancy the below script should do the trick while still keeping things simple. Again, this will serve files from the current directory down.
#!/usr/bin/python
import BaseHTTPServer, SimpleHTTPServer
import os
import sys
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
print 'Server version:',handler_class.server_version
port=8000
if len(sys.argv)>1:
if sys.argv[1].isdigit():
port=int(sys.argv[1])
server_address = ('', port)
httpd = server_class(server_address, handler_class)
myurl='http://localhost:'+str(server_address[1])+'/'
print 'Your Server is running on:',myurl
print 'and serving files from:',os.getcwd(),'and below.'
print 'To stop the server, type ^C.'
if 'b' in sys.argv:
print 'Trying to start webbrowser...'
import webbrowser
webbrowser.open(myurl)
httpd.serve_forever()
run()
The longer script was found here (site is in German but the code is clear). It may be advisable to get the script code from the actual site since my code plugin seems to be messing up the formatting which is kind of important in python code.
If you would rather use WebDAV I have used the code from the pywebdav project with some decent results.
NOTE: I believe both the above python code and pywebdav require Python2.4 or greater but I have not tested that myself.
If you use Transmission this little python script will start all of your downloads when your screensaver kicks on and pause them when it turns off, i.e. you are at your terminal.
#!/usr/bin/env python import dbus, urllib from dbus.mainloop.glib import DBusGMainLoop START_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-start" STOP_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-stop" DBusGMainLoop(set_as_default=True) sess=dbus.SessionBus() def sig(screensaverActive): if screensaverActive: data = urllib.urlopen(START_TORRENTS).read() else: data = urllib.urlopen(STOP_TORRENTS).read() sess.add_signal_receiver(sig, 'ActiveChanged','org.gnome.ScreenSaver') import gobject loop = gobject.MainLoop() loop.run()via I can’t find it at the moment but I will update once I get the link.
![]()
UPDATE:
I found my source here. The comments also include a patch for throttling the app rather than outright pausing everything.
SECURITY: I should point out, as mentioned in this comment, the RPC for Transmission will allow a nefarious person to control your application with a web page that includes elements like:
<img src="http://localhost:9091/transmission/rpc?method=torrent-stop">It is assumed that most (all?) other RPC calls for the web interface of Transmission could be called the same way. This is a fairly large security hole and I would suggest using a password on the Transmission web interface if you enable it. Though if you do that would render this tip pretty much useless.
Tags: automation, bittorrent, python, rpc, security