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