Index: main/waeup.stress/trunk/README.rst
===================================================================
--- main/waeup.stress/trunk/README.rst	(revision 8671)
+++ main/waeup.stress/trunk/README.rst	(revision 8672)
@@ -67,11 +67,12 @@
 Basically, you run a stresstest like this::
 
-  (mysandbox) $ ./bin/multimech-run <PROJECT>
+  (mysandbox) $ ./bin/stress-run <PROJECT>
 
-where ``<PROJECT>`` is one of the directories in here like 'kofa01'.
+where ``<PROJECT>`` is the name of one of the directories in here like
+'kofa01'.
 
 So,::
 
-  (mysandbox) $ ./bin/multimech-run kofa01
+  (mysandbox) $ ./bin/stress-run kofa01
 
 should give some results.
@@ -82,4 +83,10 @@
 run each test.
 
+Generally, for each test project the configuration can be done in the
+test project root. Here you will find at least a `config.cfg` for
+ini-style configuration (required) and optionally a `pre_run.py` and
+`post_run.py` to care for things like setting up an instance and
+shutting it down afterwards.
+
 Please keep in mind, that these tests normally require some local or
 remote setup, for instance a running Kofa instance with certain
Index: main/waeup.stress/trunk/kofa01/config.cfg
===================================================================
--- main/waeup.stress/trunk/kofa01/config.cfg	(revision 8671)
+++ main/waeup.stress/trunk/kofa01/config.cfg	(revision 8672)
@@ -9,4 +9,8 @@
 post_run_script = kofa01/post_run.sh
 
+kofa_instance = kofa
+kofa_baseport = 8080
+
+
 [user_group-1]
 threads = 5
Index: main/waeup.stress/trunk/kofa01/post_run.py
===================================================================
--- main/waeup.stress/trunk/kofa01/post_run.py	(revision 8671)
+++ main/waeup.stress/trunk/kofa01/post_run.py	(revision 8672)
@@ -5,2 +5,3 @@
 
 waeup.stress.stop_instance(instance)
+waeup.stress.configure()
Index: main/waeup.stress/trunk/kofa01/post_run.sh
===================================================================
--- main/waeup.stress/trunk/kofa01/post_run.sh	(revision 8671)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-
-./bin/py kofa01/post_run.py
Index: main/waeup.stress/trunk/kofa01/pre_run.py
===================================================================
--- main/waeup.stress/trunk/kofa01/pre_run.py	(revision 8672)
+++ main/waeup.stress/trunk/kofa01/pre_run.py	(revision 8672)
@@ -0,0 +1,22 @@
+import waeup.stress
+
+print "RUN SETUP"
+
+instance='kofa'
+
+waeup.stress.configure()
+
+## removes any existing ZODB (for a clean ZODB at start)
+waeup.stress.remove_zodb(instance)
+
+## installs a University named 'stress_app' in root folder
+waeup.stress.install_app(instance)
+
+## starts an instance as daemon
+waeup.stress.start_instance(instance)
+waeup.stress.wait_for_startup('localhost', 8080) # wait until daemon is up
+## after starting an instance, we have to wait for the instance to come up
+#time.sleep(3)
+
+## we need a running instance, so leave this commented out.
+#waeup.stress.stop_instance(instance)
Index: main/waeup.stress/trunk/kofa01/test_scripts/config.py
===================================================================
--- main/waeup.stress/trunk/kofa01/test_scripts/config.py	(revision 8671)
+++ main/waeup.stress/trunk/kofa01/test_scripts/config.py	(revision 8672)
@@ -1,22 +1,4 @@
-import time
-import waeup.stress
+## Shared configuration parameters
+
 #register_url = 'http://localhost:8080/uniben/applicants/putme2012/register'
 register_url = 'http://localhost:8080/stress_app/@@index'
-print "RUN SETUP"
-
-instance = 'kofa'
-
-## removes any existing ZODB (for a clean ZODB at start)
-waeup.stress.remove_zodb(instance)
-
-## installs a University named 'stress_app' in root folder
-waeup.stress.install_app(instance)
-
-## starts an instance as daemon
-waeup.stress.start_instance(instance)
-waeup.stress.wait_for_startup('localhost', 8080) # wait until daemon is up
-## after starting an instance, we have to wait for the instance to come up
-#time.sleep(3)
-
-## we need a running instance, so leave this commented out.
-#waeup.stress.stop_instance(instance)
Index: main/waeup.stress/trunk/setup.py
===================================================================
--- main/waeup.stress/trunk/setup.py	(revision 8671)
+++ main/waeup.stress/trunk/setup.py	(revision 8672)
@@ -86,4 +86,5 @@
       [console_scripts]
       bootstrap_instances = waeup.stress:bootstrap
+      stress-run = waeup.stress.run:main
       """,
       )
Index: main/waeup.stress/trunk/src/waeup/stress/__init__.py
===================================================================
--- main/waeup.stress/trunk/src/waeup/stress/__init__.py	(revision 8671)
+++ main/waeup.stress/trunk/src/waeup/stress/__init__.py	(revision 8672)
@@ -122,4 +122,9 @@
     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
Index: main/waeup.stress/trunk/src/waeup/stress/run.py
===================================================================
--- main/waeup.stress/trunk/src/waeup/stress/run.py	(revision 8672)
+++ main/waeup.stress/trunk/src/waeup/stress/run.py	(revision 8672)
@@ -0,0 +1,80 @@
+import os
+import subprocess
+import sys
+import waeup.stress
+from optparse import OptionParser
+from ConfigParser import SafeConfigParser
+
+def configure_options():
+    usage = 'Usage: %prog <project name> [options]'
+    parser = OptionParser(usage=usage)
+    parser.add_option('-p', '--port', dest='port', type='int',
+                      help='rpc listener port')
+    parser.add_option('-r', '--results', dest='results_dir',
+                      help='results directory to reprocess')
+    parser.add_option('-b', '--bind-addr', dest='bind_addr',
+                      help='rpc bind address', default='localhost')
+    parser.add_option('-d', '--directory', dest='projects_dir',
+                      help='directory containing project folder', default='.')
+    cmd_opts, args = parser.parse_args()
+
+    try:
+        project_name = args[0]
+    except IndexError:
+        sys.stderr.write('\nERROR: no project specified\n\n')
+        sys.stderr.write('%s\n' % usage)
+        sys.stderr.write('Example: multimech-run my_project\n\n')
+        sys.exit(1)
+        pass
+
+    return cmd_opts, args
+
+DEFAULTS = dict(
+    instance='kofa', baseport='8080', server_port='8100',
+    zope_threads='10', cache='20MB', cached_objs='5000',
+    paster_threads='10', use_threadpool='true', buildout='',
+    instance_mode='paster', start_instance='true')
+
+def configure_project(name, path):
+    """Parse project in `path` with name `name`.
+
+    Extracts kofa-related settings and returns them as a dict.
+    """
+    print "CONFIGURE PROJECT: ", name, path
+    cfg_path = os.path.join(path, 'config.cfg')
+    cfg_defaults = dict([('kofa_' + name, value)
+                         for name, value in DEFAULTS.items()])
+    config = SafeConfigParser(cfg_defaults)
+    config.read(cfg_path)
+    params = dict()
+    params.update(DEFAULTS)
+    for name, value in config.items('global'):
+        if not name.startswith('kofa_'):
+            continue
+        name = name.split('_', 1)[-1]
+        print name, value
+        params.update(dict({name: value}))
+    if params['instance_mode'] not in ('paster', 'kofactl', 'zeo'):
+        print "Warning: invalid instance_mode in config.cfg, picking 'paster'."
+        params['instance_mode'] = 'paster'
+    params['start_instance'] = config.getboolean(
+        'global', 'kofa_start_instance')
+    return params
+
+def main():
+    # late import as this scripts mangles sys.argv
+    from multimechanize.utilities import run
+    cmd_opts, args = configure_options()
+    project_name = args[0]
+    path = os.path.abspath(os.path.join(cmd_opts.projects_dir, project_name))
+    cfg_opts = configure_project(project_name, path)
+    pre_run_path = os.path.join(path, 'pre_run.py')
+    post_run_path = os.path.join(path, 'post_run.py')
+    if os.path.exists(pre_run_path):
+        print "WAEUP.STRESS.RUN: running pre_run %s" % pre_run_path
+        execfile(pre_run_path)
+    run.main()
+    if os.path.exists(post_run_path):
+        print "WAEUP.STRESS.RUN: running post_run %s" % post_run_path
+        execfile(post_run_path)
+    return
