#!/usr/bin/env python # # Automatic checkout, build, install, and test of kforge package. # Default setup (createDbUser = False) assumes that db user already exists import os import shutil import sys import tempfile svnurl = 'http://scm.kforge.net/svn/kforge/trunk' svnbin = 'svn' dbName = 'kforgetest' dbUser = 'kforgetest' basedir = tempfile.mkdtemp(prefix='kforge-install-test-') kforgeHome = os.path.join(basedir, 'kforge-deployment') kforgeBin = os.path.join(kforgeHome, 'bin') doDb = True createDbUser = False def dbUserCreate(): createDbUserBin = os.path.join(kforgeBin, 'kforge-dbuser-create') print "Creating database user '%s' using: %s" % (dbUser, createDbUserBin) os.system("%s %s" % (createDbUserBin, dbUser) ) def dbUserDelete(): dropDbUserBin = os.path.join(kforgeBin, 'kforge-dbuser-delete') print "Droping database user '%s' using: %s" % (dbUser, dropDbUserBin) os.system("%s %s" % (dropDbUserBin, dbUser)) def dbCreate(): createDbBin = os.path.join(kforgeBin, 'kforge-db create') print "Creating database using: %s" % (createDbBin) os.system(createDbBin) def dbDelete(): print "Removing database." dropDbBin = os.path.join(kforgeBin, 'kforge-db delete') print "Droping database using: %s" % dropDbBin os.system(dropDbBin) def buildConfiguration(): print "Configuring sub-systems." rebuildConfigBin = os.path.join(kforgeBin, 'kforge-config-rebuild') print "Rebuilding configuration using: %s" % rebuildConfigBin os.system(rebuildConfigBin) def doSourceCheckout(): print "Automated checkout and test running in temp directory: %s" % basedir os.chdir(basedir) print "Checking out source from: %s" % svnurl svncmd = "%s checkout %s" % (svnbin, svnurl) if os.system(svncmd): raise "Couldn't checkout source with command: %s" % svncmd os.chdir('trunk') print "Checking out completed." def deploySystem(): print "Deploying system to: %s" % kforgeHome instcmd = "python setup.py install --home=%s" % kforgeHome print instcmd if os.system(instcmd): raise "Couldn't install package with command: %s" % instcmd print "Deployment completed." def moveKforgeConf(): print "Moving new kforge.conf from %s/etc/kforge.conf." % kforgeHome cmd = "mv %s/etc/kforge.conf.new %s/etc/kforge.conf" % (kforgeHome, kforgeHome) print cmd if os.system(cmd): raise "Couldn't move new kforge.conf with command: %s" % cmd print "Moving kforge.conf completed." def switchToDevelopmentMode(): print "Switching to development mode." cmd = "perl -pi -e 's/#?(system_mode\s*=\s*)production/$1development/' %s/etc/kforge.conf" % (kforgeHome) print cmd if os.system(cmd): raise "Couldn't move new kforge.conf with command: %s" % cmd print "Switch to development mode completed." def configureEnvironment(): print "Configuring current environment." print "Setting environment variable KFORGEHOME to: %s" % kforgeHome os.environ['KFORGEHOME'] = kforgeHome pythonPath = os.path.join(kforgeHome, 'lib/python') print "Setting environment variable PYTHONPATH to: %s" % pythonPath os.environ['PYTHONPATH'] = pythonPath print "Configuring environment completed." if __name__ == '__main__': try: doSourceCheckout() deploySystem() moveKforgeConf() switchToDevelopmentMode() configureEnvironment() if doDb: print "Configuring database." if createDbUser: dbUserCreate() # print "First try deleting the db to make sure we create clean." try: dbDelete() except: pass dbCreate() print "Configuring database completed." else: print "Skipping database configuration." testcmd = os.path.join(kforgeBin, 'kforge-test') print "Testing deployment using: %s" % testcmd print "****** Test starting **********" os.system(testcmd) print "****** Testing completed ******" # ======== # clean up if doDb: dbDelete() if createDbUser: # now remove that user dbUserDelete() print "Removing database completed." else: print "Skipping remove database." print "Removing temp directory '%s' (and everything under it)." % (basedir) finally: shutil.rmtree(basedir) print "Automated build-and-test completed."