Image 01 Image 02

Planetplanet Installer

Posted on 24th July 2007 by Taggy
0

Planetplanet is a rss feed aggregator hacked in python.It’s extremely popular and we use it both internally and also on our GLUG site .

And the saddest thing ,it doesn’t have an installer yet :( and its a pain setting it up again and again .I have scribbled down a simple installer which *works* provided you obey all the rules it asks to :P .

here is the script
#!/usr/bin/env python
''' This script can be used to install planetplanet ,the python based RSS feed aggregator .
Author: S.Theyagarajan
Email: theyaga@gmail.com
URL : http://theyagar.info
Download URL: http://theyagar.info/code/planet-installer.txt '''


" Example Usage : ./installer-planet.py -p /home/codelabs/planet-2.0 -t fancy -o /home/codelabs/www/ -n Planet -a GLUG -e glugt@glugt.org "


from optparse import OptionParser
from commands import *
import commands
import optparse ,sys,os


usage = "Usage:\n %prog --p Planet_directory -t theme_name -o output_directory -n planet_name -a Admin_name -e Admin_email "
print usage
parser = OptionParser (usage)
parser.add_option ("-p", "--pdir", dest="pdirname")


parser.add_option ("-t", "--theme", dest="theme")


parser.add_option ("-o", "--outdir", dest="outdir")

parser.add_option ("-n", "--planetname", dest="pname")

parser.add_option ("-a", "--admin", dest="admin")

parser.add_option ("-e", "--email", dest="adminemail")

parser.add_option ("-l", "--link", dest="link")


(options, args) = parser.parse_args ()


if options.pdirname == None:
print "PlanetPlanet directory cannot be empty "
else:
pdirname=options.pdirname
print pdirname
theme=options.theme
print theme
outdir=options.outdir
print outdir
pname=options.pname
print pname
print "Planet Name is "+pname


admin=options.admin
print "Admin Name is"+ admin
adminemail=options.adminemail
print "Admin email is"+ adminemail
link=options.link
cmd= "cp -r "+ pdirname +"/examples/"+ theme +"/"+" "+ outdir
print cmd
cache_cmd= "cp -r "+ pdirname + "/examples/" + "cache" + "/" + " " + outdir
print cache_cmd
static_cmd= "cp -r "+ pdirname + "/examples/" + theme + "/*" + " " + outdir
print static_cmd
xml_cmd= "cp -r " + pdirname + "/examples/*.tmpl" + " " + outdir
print xml_cmd
rest_cmd= "cp -r " + pdirname + "/planet*" + " " + outdir
print rest_cmd


output=commands.getoutput(cmd)
output=commands.getoutput(cache_cmd)
output=commands.getoutput(xml_cmd)
output=commands.getoutput(rest_cmd)


import ConfigParser
cf=outdir + theme + "/config.ini"
print cf
config=ConfigParser.ConfigParser()
fp=file(cf,'rw')
config.readfp(fp)
print config.sections()
config.set('Planet','name',pname)
config.set('Planet','owner_name',admin)
config.set('Planet','owner_email',adminemail)
config.set('Planet','link',link)
config.set('Planet','days_per_page','100')
config.set('Planet','template_files',outdir + "" + theme + "/" + "index.html.tmpl" + " " + outdir + "atom.xml.tmpl" + " " + outdir + "foafroll.xml.tmpl" + " " + outdir + "opml.xml.tmpl" + " " + outdir+"rss20.xml.tmpl" + " " + outdir + "rss10.xml.tmpl" )
config.set('Planet','cache_directory',outdir + "/cache")
config.set('Planet','output_dir',outdir)
#config.remove_section('examples/fancy/index.html.tmpl')
config.add_section(outdir + "/" + theme + "/index.html.tmpl")
#config.set(outdir + theme + "/index.html.tmpl",'days_per_page','7')
fp.close()
fp=open(cf,'w')
config.write(fp)
fp.close()
cmd=" python " + outdir + "planet.py" + " " +outdir+theme+ "config.ini"
print cmd

output=commands.getstatusoutput(cmd)

And how do you use it ?

./installer-planet.py -p /home/codelabs/planet-2.0 -t fancy -o /home/codelabs/www/ -n Planet -a GLUG -e glugt@glugt.org

and you can also have the python file here http://theyagar.info/code/installer-python.txt

And what did i learn ? .

ConfigParser module.Its lovely ,makes it lot easier to edit the config files like the ones you find in httpd.conf so customization is just a program away no matter how many machines and time :-)

Go Python !!

[tags]planetplanet,python,hacks[/tags]



Leave a reply...