-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from mxstack/plone-createsite
Add plone domain to enable site creation
- Loading branch information
Showing
8 changed files
with
246 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from AccessControl.SecurityManagement import newSecurityManager | ||
from plone.distribution.api.site import create | ||
from Products.CMFPlone.factory import _DEFAULT_PROFILE | ||
from Testing.makerequest import makerequest | ||
|
||
import os | ||
import transaction | ||
|
||
|
||
TRUTHY = frozenset(("t", "true", "y", "yes", "on", "1")) | ||
|
||
|
||
def asbool(value: str|bool|None) -> bool: | ||
"""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 value is None: | ||
return False | ||
if isinstance(value, bool): | ||
return value | ||
return value.strip().lower() in TRUTHY | ||
|
||
|
||
PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE")) | ||
|
||
config = { | ||
{% for key, value in site.items() %} | ||
{% if key == "extension_ids" %} | ||
{% for extension_id in value %} | ||
"extension_ids": [ | ||
"{{ extension_id }}", | ||
], | ||
{% endfor %} | ||
{% else %} | ||
"{{ key }}": "{{ value }}", | ||
{% endif %} | ||
{% endfor %} | ||
"profile_id": _DEFAULT_PROFILE, | ||
} | ||
config["setup_content"] = asbool(config["setup_content"]) | ||
|
||
app = makerequest(globals()["app"]) | ||
admin = app.acl_users.getUserById("admin") | ||
newSecurityManager(None, admin.__of__(app.acl_users)) | ||
|
||
if PLONE_SITE_PURGE: | ||
if config["site_id"] in app.objectIds(): | ||
app.manage_delObjects([config["site_id"]]) | ||
transaction.commit() | ||
app._p_jar.sync() | ||
else: | ||
print(f"Site with id {config['site_id']} does not exist!") | ||
exit(0) | ||
|
||
|
||
if config["site_id"] in app.objectIds(): | ||
print(f"Site with id {config['site_id']} already exists!") | ||
exit(1) | ||
|
||
site = create(app, "{{ distribution }}", config) | ||
transaction.commit() | ||
app._p_jar.sync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#:[plone] | ||
#:title = plone | ||
#:description = Plone application related | ||
#:depends = applications.zope | ||
#: | ||
#:[target.plone-site-create] | ||
#:description = Creates a Plone site using the script provided in `PLONE_SITE_SCRIPT` configuration. | ||
#: | ||
#:[target.plone-site-purge] | ||
#:description = Removes the Plone instance from the database, but the database itself is kept. | ||
#: | ||
#:[setting.PLONE_SITE_SCRIPT] | ||
#:description = Path to the script to create or purge a Plone site | ||
#:default = .mxmake/files/plone-site.py | ||
|
||
############################################################################## | ||
# plone | ||
############################################################################## | ||
|
||
.PHONY: plone-site-create | ||
plone-site-create: $(ZOPE_RUN_TARGET) | ||
@echo "Creating Plone Site" | ||
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT) | ||
|
||
.PHONY: plone-site-purge | ||
plone-site-purge: $(ZOPE_RUN_TARGET) | ||
@echo "Purging Plone Site" | ||
@export PLONE_SITE_PURGE=True | ||
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters