Skip to content

Commit

Permalink
Merge pull request #6 from IMIO/PM-3809_auto_install
Browse files Browse the repository at this point in the history
Automatically install External methods at the root of Zope app
  • Loading branch information
sgeulette committed Jun 14, 2022
2 parents cb79ae7 + d29f882 commit fd12efe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,8 @@ Changelog
1.22 (unreleased)
-----------------

- Nothing changed yet.
- Automatically install External methods at the root of Zope app.
[odelaere]


1.21 (2022-03-15)
Expand Down
8 changes: 8 additions & 0 deletions src/Products/CPUtils/profiles/default/import_steps.xml
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<import-steps>
<import-step id="installCPUtils" version="20080501-01"
handler="Products.CPUtils.setuphandlers.install"
title="Install CPUtils.">
Install Products.CPUtils.
</import-step>
</import-steps>
18 changes: 18 additions & 0 deletions src/Products/CPUtils/setuphandlers.py
@@ -1,5 +1,7 @@
from OFS.Application import Application
from Products.CMFPlone.utils import base_hasattr
from Products.CPUtils.config import FILES_FOLDER
from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
from zope.i18nmessageid import MessageFactory

import os
Expand Down Expand Up @@ -51,3 +53,19 @@ def setRobots(context):
)

return "\n".join(output)


def install(context):
app = context.getSite()
count = 0
while not isinstance(app, Application) and count < 10:
app = app.getParentNode()
count += 1

if not isinstance(app, Application):
raise ValueError("Couldn't find parent Application")

if not hasattr(app, 'cputils_install'):
manage_addExternalMethod(app, 'cputils_install', '', 'CPUtils.utils', 'install')
# we run this method
app.cputils_install(app)
5 changes: 0 additions & 5 deletions src/Products/CPUtils/tests/testMethods.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from Products.CPUtils.tests.CPUtilsTestCase import CPUtilsTestCase
from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod

import os
import sys
Expand All @@ -19,10 +18,6 @@ def afterSetUp(self):
CPUtilsTestCase.afterSetup(self)

self.loginAsPortalOwner()
method = "install"
method_name = "cputils_" + method
manage_addExternalMethod(self.app, method_name, "", "CPUtils.utils", method)
self.app.cputils_install()

# Manually created methods

Expand Down
6 changes: 0 additions & 6 deletions src/Products/CPUtils/tests/testNewsLetter.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from Products.CPUtils.config import PROJECTNAME
from Products.CPUtils.tests.CPUtilsTestCase import CPUtilsTestCase
from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
from Products.PloneTestCase import PloneTestCase
from Testing import ZopeTestCase

Expand Down Expand Up @@ -31,12 +30,7 @@ def afterSetUp(self):
"""
"""
CPUtilsTestCase.afterSetup(self)

self.loginAsPortalOwner()
method = "install"
method_name = "cputils_" + method
manage_addExternalMethod(self.app, method_name, "", "CPUtils.utils", method)
self.app.cputils_install()

"""from Products.Five import zcml
from Products.Five import fiveconfigure
Expand Down

0 comments on commit fd12efe

Please sign in to comment.