1 | import os |
---|
2 | import socket |
---|
3 | import subprocess |
---|
4 | import sys |
---|
5 | import time |
---|
6 | import waeup.kofa |
---|
7 | |
---|
8 | AVAILABLE_KOFA_PROJECTS = ['waeup.kofa',] |
---|
9 | packages = dict() |
---|
10 | kofa_projects = dict() |
---|
11 | |
---|
12 | for pkg_name in AVAILABLE_KOFA_PROJECTS: |
---|
13 | try: |
---|
14 | name = pkg_name.split('.')[-1] |
---|
15 | mod = sys.modules[pkg_name].__file__ |
---|
16 | packages[name] = os.path.dirname(mod) |
---|
17 | kofa_projects[name] = os.path.dirname(os.path.dirname(os.path.dirname( |
---|
18 | packages[name]))) |
---|
19 | except: |
---|
20 | # not a package |
---|
21 | pass |
---|
22 | |
---|
23 | print "PACKAGES: ", packages |
---|
24 | print "KOFA PROJECTS: ", kofa_projects |
---|
25 | |
---|
26 | def do_foo(): |
---|
27 | mydir = os.path.dirname(os.path.dirname(__file__)) |
---|
28 | print "MYDIR", mydir |
---|
29 | #import pdb; pdb.set_trace() |
---|
30 | |
---|
31 | def enable_datafs(path, proj_name): |
---|
32 | """Copy data.fs in `path` for kofa project `proj_name`. |
---|
33 | """ |
---|
34 | pkg = packages[proj_name] |
---|
35 | #src_path = os.path.join( |
---|
36 | |
---|
37 | def bootstrap(): |
---|
38 | """Run bootstrap and buildout for each of the KOFA instances |
---|
39 | """ |
---|
40 | for name, path in kofa_projects.items(): |
---|
41 | bootstrap_instance(name, path) |
---|
42 | return |
---|
43 | |
---|
44 | def bootstrap_instance(name, path): |
---|
45 | """Run bootstrap.py and buildout for instance `name` at `path`. |
---|
46 | """ |
---|
47 | print "WAEUP.STRESS: bootstrapping %s" % name |
---|
48 | print "WAEUP.STRESS: path: %s" % path |
---|
49 | old_cwd_ = os.getcwd() |
---|
50 | os.chdir(path) |
---|
51 | print "WAEUP.STRESS: bootstrapping %s" % name |
---|
52 | subprocess.call(['python', 'bootstrap/bootstrap.py']) |
---|
53 | print "WAEUP.STRESS: running buildout for %s" % name |
---|
54 | subprocess.call(['./bin/buildout'], shell=True) |
---|
55 | os.chdir(old_cwd_) |
---|
56 | return |
---|
57 | |
---|
58 | def remove_zodb(name): |
---|
59 | path = kofa_projects[name] |
---|
60 | print "WAEUP.STRESS: removing ZODB of %s at %s" % (name, path) |
---|
61 | filestorage_dir = os.path.join(path, 'var', 'filestorage') |
---|
62 | for filename in os.listdir(filestorage_dir): |
---|
63 | if filename in ['Data.fs', 'Data.fs.tmp', 'Data.fs.index', |
---|
64 | 'Data.fs.lock']: |
---|
65 | filepath = os.path.join(filestorage_dir, filename) |
---|
66 | print " removing %s" % filepath |
---|
67 | os.unlink(filepath) |
---|
68 | return |
---|
69 | |
---|
70 | def start_instance(name): |
---|
71 | path = kofa_projects[name] |
---|
72 | print "WAEUP.STRESS: starting instance %s at %s" % (name, path) |
---|
73 | old_cwd_ = os.getcwd() |
---|
74 | os.chdir(path) |
---|
75 | # yes, shell _is_ neccessary here |
---|
76 | subprocess.call( |
---|
77 | './bin/paster serve --daemon parts/etc/debug.ini', shell=True) |
---|
78 | os.chdir(old_cwd_) |
---|
79 | return |
---|
80 | |
---|
81 | def wait_for_startup(host, port): |
---|
82 | """Wait until a connection to host and port can be made. |
---|
83 | """ |
---|
84 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
---|
85 | while True: |
---|
86 | try: |
---|
87 | s.connect((host, port)) |
---|
88 | break |
---|
89 | except: |
---|
90 | time.sleep(0.1) |
---|
91 | s.close() |
---|
92 | return |
---|
93 | |
---|
94 | def stop_instance(name): |
---|
95 | path = kofa_projects[name] |
---|
96 | print "WAEUP.STRESS: shutting down instance %s at %s" % (name, path), |
---|
97 | old_cwd_ = os.getcwd() |
---|
98 | os.chdir(path) |
---|
99 | subprocess.call( |
---|
100 | './bin/paster serve --stop-daemon', shell=True) |
---|
101 | print "... done." |
---|
102 | os.chdir(old_cwd_) |
---|
103 | return |
---|
104 | |
---|
105 | def install_app(name): |
---|
106 | path = kofa_projects[name] |
---|
107 | old_cwd_ = os.getcwd() |
---|
108 | os.chdir(path) |
---|
109 | db_file = os.path.join(path, 'var', 'filestorage', 'Data.fs') |
---|
110 | config_file = os.path.join(path, 'parts', 'etc', 'site.zcml') |
---|
111 | #import waeup.kofa.meta |
---|
112 | #import grok.meta |
---|
113 | import grok |
---|
114 | #print "META: ", grok.meta |
---|
115 | import sys |
---|
116 | #print "PATHS: ", sys.path |
---|
117 | from zope.app.appsetup import database, config |
---|
118 | #config(config_file) |
---|
119 | #subprocess.call( |
---|
120 | # './bin/python-console -c "import grok.meta"', shell=True) |
---|
121 | script = os.path.join(os.path.dirname(__file__), 'scripts.py') |
---|
122 | subprocess.call( |
---|
123 | './bin/python-console %s' % script, shell=True) |
---|
124 | |
---|
125 | os.chdir(old_cwd_) |
---|