-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-initialize.py
executable file
·53 lines (39 loc) · 1.33 KB
/
docker-initialize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/plone/instance/bin/python
"""Configure RelStorage."""
import os
class Environment(object):
"""Configure container via environment variables."""
def __init__(self, env=os.environ,
zope_conf='/plone/instance/parts/instance/etc/zope.conf'):
"""Initialize the environment."""
self.env = env
self.zope_conf = zope_conf
def relstorage(self):
"""Relstorage configuration."""
DATABASE_URL = self.env.get('DATABASE_URL', None)
if not DATABASE_URL:
return
config = ""
with open(self.zope_conf, "r") as cfile:
config = cfile.read()
config = config.replace(
'HOST', DATABASE_URL.split('@')[1].split(':')[0]
).replace(
'DBNAME', DATABASE_URL.split('/')[-1]
).replace(
'USER', DATABASE_URL.split('//')[1].split(':')[0]
).replace(
'PASS', DATABASE_URL.split('//')[1].split(':')[1].split('@')[0]
)
with open(self.zope_conf, "w") as cfile:
cfile.write(config)
def setup(self, **kwargs):
"""Setup environment."""
self.relstorage()
__call__ = setup
def initialize():
"""Configure Plone instance using RelStorage."""
environment = Environment()
environment.setup()
if __name__ == "__main__":
initialize()