Skip to content

Commit

Permalink
purge and more rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Jun 6, 2024
1 parent e748ca2 commit 16c9eb1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ python_version = 3.8
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
"src/mxmake/templates/plone-createsite.py",
"src/mxmake/templates/plone-site.py",
]
36 changes: 22 additions & 14 deletions src/mxmake/templates/plone-site.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ def asbool(value: str|bool|None) -> bool:
return value.strip().lower() in TRUTHY


DELETE_EXISTING = asbool(os.getenv("DELETE_EXISTING"))


app = makerequest(globals()["app"])
admin = app.acl_users.getUserById("admin")
newSecurityManager(None, admin.__of__(app.acl_users))
PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE"))

config = {
{% for key, value in site.items() %}
Expand All @@ -43,13 +38,26 @@ def asbool(value: str|bool|None) -> bool:
{% 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() and DELETE_EXISTING:
app.manage_delObjects([config["site_id"]])
transaction.commit()
app._p_jar.sync()
if config["site_id"] in app.objectIds():
print(f"Site with id {config['site_id']} already exists!")
exit(1)

if config["site_id"] not in app.objectIds():
site = create(app, "{{ distribution }}", config)
transaction.commit()
app._p_jar.sync()
site = create(app, "{{ distribution }}", config)
transaction.commit()
app._p_jar.sync()
46 changes: 27 additions & 19 deletions src/mxmake/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def test_MxIni(self, tempdir):
)

@testing.template_directory()
def test_PloneCreateSite_all_defaults(self, tempdir):
def test_PloneSite_all_defaults(self, tempdir):
mxini = tempdir / "mx.ini"
with mxini.open("w") as fd:
fd.write(
Expand Down Expand Up @@ -859,7 +859,7 @@ def test_PloneCreateSite_all_defaults(self, tempdir):
template.write()
with (tempdir / "plone-site.py").open() as f:
self.checkOutput(
"""
'''
from AccessControl.SecurityManagement import newSecurityManager
from plone.distribution.api.site import create
from Products.CMFPlone.factory import _DEFAULT_PROFILE
Expand All @@ -873,23 +873,18 @@ def test_PloneCreateSite_all_defaults(self, tempdir):
def asbool(value: str|bool|None) -> bool:
\"\"\"Return the boolean value ``True`` if the case-lowered value of string
"""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
DELETE_EXISTING = asbool(os.getenv("DELETE_EXISTING"))
app = makerequest(globals()["app"])
admin = app.acl_users.getUserById("admin")
newSecurityManager(None, admin.__of__(app.acl_users))
PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE"))
config = {
"site_id": "Plone",
Expand All @@ -902,16 +897,29 @@ def asbool(value: str|bool|None) -> bool:
],
"profile_id": _DEFAULT_PROFILE,
}
config["setup_content"] = asbool(config["setup_content"])
if config["site_id"] in app.objectIds() and DELETE_EXISTING:
app.manage_delObjects([config["site_id"]])
transaction.commit()
app._p_jar.sync()
app = makerequest(globals()["app"])
admin = app.acl_users.getUserById("admin")
newSecurityManager(None, admin.__of__(app.acl_users))
if config["site_id"] not in app.objectIds():
site = create(app, "", config)
transaction.commit()
app._p_jar.sync()
""",
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, "", config)
transaction.commit()
app._p_jar.sync()
''',
f.read(),
)
44 changes: 23 additions & 21 deletions src/mxmake/topics/applications/plone.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@
#:title = plone
#:description = Plone application related
#:depends = applications.zope
#:[target.plone-createsite]
#:description = Creates a Plone site using the script provided in `PLONE_CREATESITE_SCRIPT` configuration.
#:[target.plone-site-create]
#:description = Creates a Plone site using the script provided in `PLONE_SITE_SCRIPT` configuration.
#:
#:[setting.PLONE_CREATESITE_SCRIPT]
#:description = Path to the script to create a Plone site
#:default = .mxmake/files/plone-createsite.py
#:[setting.PLONE_SITE_SCRIPT]
#:description = Path to the script to create or purge a Plone site
#:default = .mxmake/files/plone-site.py
#:
#:[target.plone-createsite-dirty]
#:[target.plone-site-dirty]
#:description = Touches the sentinel file to force a rebuild of the Plone instance. This will not touch the database.
#:
#:[target.plone-createsite-clean]
#:[target.plone-site-clean]
#:description = Removes the sentinel file to force files but keeps Plone database.
#:
#:[target.plone-createsite-purge]
#:[target.plone-site-purge]
#:description = Removes the Plone instance from the database, but the database itself is kept.


##############################################################################
# plone
##############################################################################

PLONE_CREATESITE_SENTINEL:=$(SENTINEL_FOLDER)/plone-createsite.sentinel
PLONE_SITE_TARGET: $(FILES_TARGET) $(ZOPE_RUN_TARGET)

PLONE_CREATESITE_TARGET: $(FILES_TARGET) $(ZOPE_RUN_TARGET)

.PHONY: plone-createsite
plone-createsite: PLONE_CREATESITE_TARGET
.PHONY: plone-site-create
plone-site-create: PLONE_SITE_TARGET
@echo "Creating Plone Site"
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_CREATESITE_SCRIPT)
@touch $(PLONE_CREATESITE_SENTINEL)
@zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT)

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

.PHONY: plone-createsite-dirty
plone-createsite-dirty:
@touch $(PLONE_CREATESITE_SENTINEL)
.PHONY: plone-site-dirty
plone-site-dirty:
@touch $(PLONE_SITE_SENTINEL)

.PHONY: plone-createsite-clean
plone-createsite-clean:
@touch $(PLONE_CREATESITE_SENTINEL)
.PHONY: plone-site-clean
plone-site-clean:
@touch $(PLONE_SITE_SENTINEL)

0 comments on commit 16c9eb1

Please sign in to comment.