Skip to content

Commit

Permalink
more fine grained control over plone-site creation/purging
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Jul 28, 2024
1 parent c3afefd commit 577f922
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/mxmake/templates/plone-site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TRUTHY = frozenset(("t", "true", "y", "yes", "on", "1"))


def asbool(value: str|bool|None) -> bool:
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.
Expand All @@ -22,7 +22,14 @@ def asbool(value: str|bool|None) -> bool:
return value.strip().lower() in TRUTHY


PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE"))
PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE", "false"))
PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS = asbool(
os.getenv("PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS", "true")
)
PLONE_SITE_CREATE = asbool(os.getenv("PLONE_SITE_CREATE", "true"))
PLONE_SITE_CREATE_FAIL_IF_EXISTS = asbool(
os.getenv("PLONE_SITE_CREATE_FAIL_IF_EXISTS", "true")
)

config = {
{% for key, value in site.items() %}
Expand All @@ -49,15 +56,30 @@ def asbool(value: str|bool|None) -> bool:
app.manage_delObjects([config["site_id"]])
transaction.commit()
app._p_jar.sync()
print(f"Existing site with id={config['site_id']} purged!")
if not PLONE_SITE_CREATE:
print("Done.")
exit(0)
else:
print(f"Site with id {config['site_id']} does not exist!")
exit(0)
print(f"Site with id={config['site_id']} does not exist!")
if PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS:
print("...failure!")
exit(1)
if not PLONE_SITE_CREATE:
print("Done.")
exit(0)

if PLONE_SITE_CREATE:
if config["site_id"] in app.objectIds():
print(f"Site with id={config['site_id']} already exists!")
if PLONE_SITE_CREATE_FAIL_IF_EXISTS:
print("...failure!")
exit(1)
print("Done.")
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()
site = create(app, "{{ distribution }}", config)
transaction.commit()
app._p_jar.sync()
print(f"New site with id={config['site_id']} created!")
print("Done.")
22 changes: 22 additions & 0 deletions src/mxmake/topics/applications/plone.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@
#:[target.plone-site-purge]
#:description = Removes the Plone instance from the database, but the database itself is kept.
#:
#:[target.plone-site-recreate]
#:description = Removes the Plone instance from the database like in plone-site-purge,
#: then creates a new one like in plone-site-create.
#:
#:[setting.PLONE_SITE_SCRIPT]
#:description = Path to the script to create or purge a Plone site
#:default = .mxmake/files/plone-site.py
#:#:
#:[setting.PLONE_SITE_CREATE_FAIL_IF_EXISTS]
#:description = Exit with an error if the Plone site already exists
#:default = True

#:[setting.PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS]
#:description = Exit with an error if the Plone site does not exists
#:default = True

##############################################################################
# plone
Expand All @@ -20,10 +32,20 @@
.PHONY: plone-site-create
plone-site-create: $(ZOPE_RUN_TARGET)
@echo "Creating Plone Site"
@export PLONE_SITE_PURGE=False
@export PLONE_SITE_CREATE=True
@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
@export PLONE_SITE_CREATE=False
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT)

.PHONY: plone-site-recreate
plone-site-recreate: $(ZOPE_RUN_TARGET)
@echo "Purging Plone Site"
@export PLONE_SITE_PURGE=True
@export PLONE_SITE_CREATE=True
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT)

0 comments on commit 577f922

Please sign in to comment.