-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_site.py
More file actions
76 lines (59 loc) · 2.09 KB
/
Copy pathcreate_site.py
File metadata and controls
76 lines (59 loc) · 2.09 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from AccessControl.SecurityManagement import newSecurityManager
from kitconcept.keywordmanager.interfaces import IBrowserLayer
from Products.CMFPlone.factory import _DEFAULT_PROFILE
from Products.CMFPlone.factory import addPloneSite
from Products.GenericSetup.tool import SetupTool
from Testing.makerequest import makerequest
from zope.interface import directlyProvidedBy
from zope.interface import directlyProvides
import os
import transaction
truthy = frozenset(("t", "true", "y", "yes", "on", "1"))
def asbool(s):
"""Return the boolean value ``True`` if the case-lowered value of string
input ``s`` is a :term:`truthy string`. If ``s`` is already one of the
boolean values ``True`` or ``False``, return it."""
if s is None:
return False
if isinstance(s, bool):
return s
s = str(s).strip()
return s.lower() in truthy
DELETE_EXISTING = asbool(os.getenv("DELETE_EXISTING"))
EXAMPLE_CONTENT = asbool(os.getenv("EXAMPLE_CONTENT", "1"))
app = makerequest(globals()["app"])
request = app.REQUEST
ifaces = [IBrowserLayer]
for iface in directlyProvidedBy(request):
ifaces.append(iface)
directlyProvides(request, *ifaces)
admin = app.acl_users.getUserById("admin")
admin = admin.__of__(app.acl_users)
newSecurityManager(None, admin)
site_id = "Plone"
payload = {
"title": "kitconcept-keywordmanager",
"profile_id": _DEFAULT_PROFILE,
"distribution_name": "volto",
"setup_content": False,
"default_language": "en",
"portal_timezone": "UTC",
}
if site_id in app.objectIds() and DELETE_EXISTING:
app.manage_delObjects([site_id])
transaction.commit()
app._p_jar.sync()
if site_id not in app.objectIds():
site = addPloneSite(app, site_id, **payload)
transaction.commit()
portal_setup: SetupTool = site.portal_setup
portal_setup.runAllImportStepsFromProfile(
"profile-kitconcept.keywordmanager:default"
)
transaction.commit()
if EXAMPLE_CONTENT:
portal_setup.runAllImportStepsFromProfile(
"profile-kitconcept.keywordmanager:initial"
)
transaction.commit()
app._p_jar.sync()