Fabric RPM Package
I’ve packaged Fabric–the simple pythonic remote deployment tool–as an RPM.
Here is a simple guide on creating binary RPMs from source RPMs.
IPython + Python: Single Bash Command
The following is a simple Bash function you can paste into your bashrc file to start Python/IPython depending on the context.
~/.bashrc
function python {
IPYTHON="/usr/bin/ipython"
PYTHON="/usr/bin/python"
if [[ -n $1 ]]; then
$PYTHON $@
elif [[ -e $IPYTHON ]]; then
$IPYTHON
else
$PYTHON
fi
}
Push: Func Module to Run Arbitrary Python Code
Func is a nifty, although not yet polished, Python-based service for running tasks on many hosts at once. It lets you do things like restart Apache instances, run yum updates or provision virtual machines.
You can accomplish theses tasks via the command line interface
func web-*.example.net call service restart httpd
or through the Python API
import func.overlord.client as fc client = fc.Client('web-*.example.net') print client.service.restart('httpd')
One of the annoying issues I’m dealing with right now is the distribution of Func modules, which for various reasons isn’t as simple as packaging the modules and pushing them to all the hosts (it is, just not in my network).
My solution is Push, a Func module which lets you instantly run Python code on any or all hosts in your network.
Example usage:
import func.overlord.client as fc client = fc.Client('web-*.example.net') source = """ def main(): return 'Hello World' """ print client.push.code(source)
I realize this isn’t the most elegant solution, but its very useful and extremely simple.
I also realize that I could use the copyfile module to push modules via Func, but I haven’t found a way to restart funcd via Func (required to initialize modules), so until that happens I need a solution which doesn’t require restarting Func.
Python SDK for PhoneFactor
A first (and very alpha) attempt at creating a Python SDK for PhoneFactor.
Link: http://code.google.com/p/silassewell/source/browse/trunk/2008/06/07/python-phonefactor/
Universal Feed Parser to JSON
My attempt at wrangling a Universal Feed Parser object into JSON.
import feedparser def json_make_normal(obj): if type(obj) in [str, unicode, int, float, bool, dict, set, list, tuple]: return obj try: return dict(obj) except: pass try: return list(obj) except: pass return None def json_handle(obj): obj = json_make_normal(obj) if type(obj) in [str, unicode]: obj = obj.replace('\\', '\\\\') obj = obj.replace('"', '\\"') obj = obj.replace('\b', '\\\b') obj = obj.replace('\f', '\\\f') obj = obj.replace('\n', '\\\n') obj = obj.replace('\r', '\\\r') obj = obj.replace('\t', '\\\t') return '"%s"' % obj elif type(obj) in [int, float]: return obj elif type(obj) is bool: if obj: return 'true' else: return 'false' elif type(obj) is type(None): return 'null' elif type(obj) is dict: temp = '' for key in obj.keys(): temp += '%s:%s, ' % (json_handle(key), json_handle(obj[key])) return '{%s}' % temp[:-2] elif type(obj) in [set, list, tuple]: temp = '' for value in obj: temp += '%s, ' % json_handle(value) return '[%s]' % temp[:-2] return 'null' data = feedparser.parse('http://digg.com/rss/index.xml') print json_handle(data)
Link: feed_parser_to_json.py
Update: According to John Paulett jsonpickle now supports Universal Feed Parser objects. Thanks for letting me know!
opml2html Updates
I’ve made some tweaks to opml2html to make it a little cleaner and more useful.
The main two additions are a class so opml2html can be called programmatically and a command line argument so the input file isn’t static.
Convert Google Reader subscriptions (OPML) to HTML
I’ve created a simple Python script to convert Google Reader’s OPML to HTML.