source: main/waeup.stress/trunk/src/waeup/stress/run.py @ 8690

Last change on this file since 8690 was 8674, checked in by uli, 13 years ago

Add 'host' as configuration param.

File size: 3.0 KB
Line 
1import os
2import subprocess
3import sys
4import waeup.stress
5from optparse import OptionParser
6from ConfigParser import SafeConfigParser
7
8def configure_options():
9    usage = 'Usage: %prog <project name> [options]'
10    parser = OptionParser(usage=usage)
11    parser.add_option('-p', '--port', dest='port', type='int',
12                      help='rpc listener port')
13    parser.add_option('-r', '--results', dest='results_dir',
14                      help='results directory to reprocess')
15    parser.add_option('-b', '--bind-addr', dest='bind_addr',
16                      help='rpc bind address', default='localhost')
17    parser.add_option('-d', '--directory', dest='projects_dir',
18                      help='directory containing project folder', default='.')
19    cmd_opts, args = parser.parse_args()
20
21    try:
22        project_name = args[0]
23    except IndexError:
24        sys.stderr.write('\nERROR: no project specified\n\n')
25        sys.stderr.write('%s\n' % usage)
26        sys.stderr.write('Example: multimech-run my_project\n\n')
27        sys.exit(1)
28        pass
29
30    return cmd_opts, args
31
32DEFAULTS = dict(
33    instance='kofa', baseport='8080', server_port='8100',
34    zope_threads='10', cache='20MB', cached_objs='5000',
35    paster_threads='10', use_threadpool='true', buildout='',
36    instance_mode='paster', start_instance='true', host='localhost')
37
38def configure_project(name, path):
39    """Parse project in `path` with name `name`.
40
41    Extracts kofa-related settings and returns them as a dict.
42    """
43    print "CONFIGURE PROJECT: ", name, path
44    cfg_path = os.path.join(path, 'config.cfg')
45    cfg_defaults = dict([('kofa_' + name, value)
46                         for name, value in DEFAULTS.items()])
47    config = SafeConfigParser(cfg_defaults)
48    config.read(cfg_path)
49    params = dict()
50    params.update(DEFAULTS)
51    for name, value in config.items('global'):
52        if not name.startswith('kofa_'):
53            continue
54        name = name.split('_', 1)[-1]
55        print name, value
56        params.update(dict({name: value}))
57    if params['instance_mode'] not in ('paster', 'kofactl', 'zeo'):
58        print "Warning: invalid instance_mode in config.cfg, picking 'paster'."
59        params['instance_mode'] = 'paster'
60    params['start_instance'] = config.getboolean(
61        'global', 'kofa_start_instance')
62    return params
63
64def main():
65    # late import as this scripts mangles sys.argv
66    from multimechanize.utilities import run
67    cmd_opts, args = configure_options()
68    project_name = args[0]
69    path = os.path.abspath(os.path.join(cmd_opts.projects_dir, project_name))
70    cfg_opts = configure_project(project_name, path)
71    pre_run_path = os.path.join(path, 'pre_run.py')
72    post_run_path = os.path.join(path, 'post_run.py')
73    if os.path.exists(pre_run_path):
74        print "WAEUP.STRESS.RUN: running pre_run %s" % pre_run_path
75        execfile(pre_run_path)
76    run.main()
77    if os.path.exists(post_run_path):
78        print "WAEUP.STRESS.RUN: running post_run %s" % post_run_path
79        execfile(post_run_path)
80    return
Note: See TracBrowser for help on using the repository browser.