#!/usr/bin/python import os import sys import commands sys.path = ['/usr/lib/portage/pym/'] + sys.path import output # from portage def die(msg): sys.stderr.write(' %s %s\n' % (output.red('*'), msg)) sys.exit(-1) def warn(msg): sys.stderr.write(' %s %s\n' % (output.yellow('*'), msg)) def say(msg): sys.stderr.write(' %s %s\n' % (output.green('*'), msg)) def makedirs(d): try: try: old_mask = os.umask(000) os.makedirs(d, 0755) finally: os.umask(old_mask) except OSError, e: if e.errno != 17: raise def run(cmd): status, output = commands.getstatusoutput(cmd) if status: raise Exception, output if len(sys.argv) != 2 or sys.argv[1] not in ('install', 'clean'): die('must be called with install or clean') # check the environment variables try: vhost_root = os.environ["VHOST_ROOT"] instdir = os.environ["MY_INSTALLDIR"] appdir = os.environ["VHOST_APPDIR"] except KeyError, e: die("%s environment variable was not properly set" % e) datadir = vhost_root + '/webapps/' + appdir + '/data/' plugindir = vhost_root + '/webapps/' + appdir + '/plugin/' logdir = vhost_root + '/webapps/' + appdir + '/logs/' config = instdir + '/config.py' if sys.argv[1] == "install": try: say('creating directory structures') makedirs(datadir) makedirs(logdir) makedirs(plugindir) say('modifying %s/config.py' % instdir) sed = 'sed -i "s|%s|%s|g" %s' run(sed % ('/path/to/blog', datadir, config)) run(sed % ('/path/to/my/plugins', plugindir, config)) run(sed % ('/path/to/logdir', logdir, config)) say("modifying CGI perms") run("chmod +x %s/*.cgi" % instdir) except Exception, e: die('%s: %s' % (type(e).__name__, e)) say('') say('The configuration file has been modified so that you can get') say('your web application up and running. Please go in and customize') say('some of the other settings - name, email, etc.') say('') elif sys.argv[1] == "clean": say('') say('The PyBlosxom application data will not be deleted at this time.') say('If you do not wish to keep it anymore, you must delete it manually.') say('')