import os import socket import subprocess import sys import time import waeup.kofa AVAILABLE_KOFA_PROJECTS = ['waeup.kofa',] packages = dict() kofa_projects = dict() for pkg_name in AVAILABLE_KOFA_PROJECTS: try: name = pkg_name.split('.')[-1] mod = sys.modules[pkg_name].__file__ packages[name] = os.path.dirname(mod) kofa_projects[name] = os.path.dirname(os.path.dirname(os.path.dirname( packages[name]))) except: # not a package pass print "PACKAGES: ", packages print "KOFA PROJECTS: ", kofa_projects def do_foo(): mydir = os.path.dirname(os.path.dirname(__file__)) print "MYDIR", mydir #import pdb; pdb.set_trace() def enable_datafs(path, proj_name): """Copy data.fs in `path` for kofa project `proj_name`. """ pkg = packages[proj_name] #src_path = os.path.join( def bootstrap(): """Run bootstrap and buildout for each of the KOFA instances """ for name, path in kofa_projects.items(): bootstrap_instance(name, path) return def bootstrap_instance(name, path): """Run bootstrap.py and buildout for instance `name` at `path`. """ print "WAEUP.STRESS: bootstrapping %s" % name print "WAEUP.STRESS: path: %s" % path old_cwd_ = os.getcwd() os.chdir(path) print "WAEUP.STRESS: bootstrapping %s" % name subprocess.call(['python', 'bootstrap/bootstrap.py']) print "WAEUP.STRESS: running buildout for %s" % name subprocess.call(['./bin/buildout'], shell=True) os.chdir(old_cwd_) return def remove_zodb(name): path = kofa_projects[name] print "WAEUP.STRESS: removing ZODB of %s at %s" % (name, path) filestorage_dir = os.path.join(path, 'var', 'filestorage') for filename in os.listdir(filestorage_dir): if filename in ['Data.fs', 'Data.fs.tmp', 'Data.fs.index', 'Data.fs.lock']: filepath = os.path.join(filestorage_dir, filename) print " removing %s" % filepath os.unlink(filepath) return def start_instance(name): path = kofa_projects[name] print "WAEUP.STRESS: starting instance %s at %s" % (name, path) old_cwd_ = os.getcwd() os.chdir(path) # yes, shell _is_ neccessary here subprocess.call( './bin/paster serve --daemon parts/etc/debug.ini', shell=True) os.chdir(old_cwd_) return def wait_for_startup(host, port): """Wait until a connection to host and port can be made. """ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while True: try: s.connect((host, port)) break except: time.sleep(0.1) s.close() return def stop_instance(name): path = kofa_projects[name] print "WAEUP.STRESS: shutting down instance %s at %s" % (name, path), old_cwd_ = os.getcwd() os.chdir(path) subprocess.call( './bin/paster serve --stop-daemon', shell=True) print "... done." os.chdir(old_cwd_) return def install_app(name): path = kofa_projects[name] old_cwd_ = os.getcwd() os.chdir(path) db_file = os.path.join(path, 'var', 'filestorage', 'Data.fs') config_file = os.path.join(path, 'parts', 'etc', 'site.zcml') #import waeup.kofa.meta #import grok.meta import grok #print "META: ", grok.meta import sys #print "PATHS: ", sys.path from zope.app.appsetup import database, config #config(config_file) #subprocess.call( # './bin/python-console -c "import grok.meta"', shell=True) script = os.path.join(os.path.dirname(__file__), 'scripts.py') subprocess.call( './bin/python-console %s' % script, shell=True) os.chdir(old_cwd_) def configure(): import ConfigParser from multimechanize.utilities.run import project_name, cmd_opts, args print "Configure" print "PROJECT NAME: ", project_name