<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tail -f /dev/null &#187; python</title>
	<atom:link href="http://tfdn.radiofreeomaha.net/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://tfdn.radiofreeomaha.net</link>
	<description>Tips, notes, HOWTOs</description>
	<lastBuildDate>Fri, 20 Aug 2010 04:13:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Serving Files Simply With Python</title>
		<link>http://tfdn.radiofreeomaha.net/2009/06/serving-files-simply-with-python/</link>
		<comments>http://tfdn.radiofreeomaha.net/2009/06/serving-files-simply-with-python/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 02:20:22 +0000</pubDate>
		<dc:creator>Uncle Jubba</dc:creator>
				<category><![CDATA[CLI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://tfdn.radiofreeomaha.net/?p=76</guid>
		<description><![CDATA[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 [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I had found this code for serving up a directory with a simple python command.</p>
<pre class="brush: bash">python -m SimpleHTTPServer 9914</pre>
<p>The above command will start a simple HTTP server on port 9914 serving files out of the current directory and below.</p>
<p>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.</p>
<pre class="brush: python">

#!/usr/bin/python

import BaseHTTPServer, SimpleHTTPServer

import os
import sys

def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
print &#039;Server version:&#039;,handler_class.server_version

port=8000

if len(sys.argv)&gt;1:
if sys.argv[1].isdigit():
port=int(sys.argv[1])
server_address = (&#039;&#039;, port)

httpd = server_class(server_address, handler_class)

myurl=&#039;http://localhost:&#039;+str(server_address[1])+&#039;/&#039;
print &#039;Your Server is running on:&#039;,myurl
print &#039;and serving files from:&#039;,os.getcwd(),&#039;and below.&#039;
print &#039;To stop the server, type ^C.&#039;

if &#039;b&#039; in sys.argv:
print &#039;Trying to start webbrowser...&#039;
import webbrowser
webbrowser.open(myurl)

httpd.serve_forever()

run()
</pre>
<p>The longer script was found <a href="http://user.baden-online.de/~pjanssen/ad-hoc-server/index.html" target="_blank">here</a> (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.</p>
<p>If you would rather use WebDAV I have used the code from the <a href="http://code.google.com/p/pywebdav/" target="_blank">pywebdav project</a> with some decent results.</p>
<p>NOTE: I believe both the above python code and pywebdav require Python2.4 or greater but I have not tested that myself.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://tfdn.radiofreeomaha.net/2009/06/serving-files-simply-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pause Torrent Downloads When Screensaver Is Inactive</title>
		<link>http://tfdn.radiofreeomaha.net/2008/12/pause-torrent-downloads-when-screensaver-is-inactive/</link>
		<comments>http://tfdn.radiofreeomaha.net/2008/12/pause-torrent-downloads-when-screensaver-is-inactive/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 05:39:41 +0000</pubDate>
		<dc:creator>Uncle Jubba</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bittorrent]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://tfdn.radiofreeomaha.net/?p=10</guid>
		<description><![CDATA[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 = &#34;http://localhost:9091/transmission/rpc?method=torrent-start&#34; STOP_TORRENTS = &#34;http://localhost:9091/transmission/rpc?method=torrent-stop&#34; DBusGMainLoop(set_as_default=True) sess=dbus.SessionBus() def sig(screensaverActive): if screensaverActive: data = [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you use <a href="http://www.transmissionbt.com/" target="_blank">Transmission</a> 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.</p>
<pre>
<pre class="brush: python">#!/usr/bin/env python
import dbus, urllib
from dbus.mainloop.glib import DBusGMainLoop

START_TORRENTS = &quot;http://localhost:9091/transmission/rpc?method=torrent-start&quot;
STOP_TORRENTS = &quot;http://localhost:9091/transmission/rpc?method=torrent-stop&quot;

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, &#039;ActiveChanged&#039;,&#039;org.gnome.ScreenSaver&#039;)
import gobject
loop = gobject.MainLoop()
loop.run()</pre>
<p>via <span style="color: #ff0000;">I can&#8217;t find it at the moment but I will update once I get the link.  <img src='http://tfdn.radiofreeomaha.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </span></p>
<p>UPDATE:</p>
<p>I found my source <a href="http://www.kryogenix.org/days/2008/11/15/pause-torrents-while-im-using-the-computer" target="_blank">here</a>.  The comments also include a patch for throttling the app rather than outright pausing everything.</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #ff0000;">SECURITY</span></span></strong>: I should point out, as mentioned in <a href="http://www.kryogenix.org/days/2008/11/15/pause-torrents-while-im-using-the-computer#comment-122886" target="_blank">this</a> comment, the RPC for Transmission will allow a nefarious person to control your application with a web page that includes elements like:</p>
<pre>
<pre class="brush: html">&lt;img src=&quot;http://localhost:9091/transmission/rpc?method=torrent-stop&quot;&gt;</pre>
<p>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.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://tfdn.radiofreeomaha.net/2008/12/pause-torrent-downloads-when-screensaver-is-inactive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

