Skip to content

Commit

Permalink
Merge pull request #91 from plone/issue_90
Browse files Browse the repository at this point in the history
Add the ability to specify a custom WSGI configuration file
  • Loading branch information
jensens authored Apr 18, 2019
2 parents 18b6f65 + 76b90c4 commit 7eeda14
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/90.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the ability to specify a custom WSGI configuration file
9 changes: 4 additions & 5 deletions src/plone/recipe/zope2instance/ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,22 +922,22 @@ def main(args=None):
"""Customized entry point for launching Zope without forking other processes
"""

if '--wsgi' in args:
if '--wsgi' in args or '-w' in args:
options = WSGICtlOptions()
else:
options = ZServerCtlOptions()
options.add(name="no_request", short="R", long="no-request", flag=1)
options.add(name="no_login", short="L", long="no-login", flag=1)
options.add(name="object_path", short="O:", long="object-path=")
options.add(name="wsgi", short='w', long='wsgi', flag=1)
options.add(name="wsgi", short='w:', long='wsgi=')
# Realize arguments and set documentation which is used in the -h option
options.realize(args, doc=__doc__)

# Run the right command depending on whether we have ZServer
options.interpreter = os.path.join(options.directory, 'bin', 'interpreter')
if sys.platform == 'win32':
options.interpreter += '-script.py'
if six.PY2 and not options.wsgi:
if six.PY2 and (options.wsgi or '').lower() in ('off', 'false', '0'):
# only use zserver in Python 2 and if wsgi is disabled
from ZServer.Zope2.Startup import run
script = os.path.join(os.path.dirname(run.__file__), 'run.py')
Expand All @@ -949,9 +949,8 @@ def main(args=None):
# wsgi is the default
from Zope2.Startup import serve
script = os.path.join(os.path.dirname(serve.__file__), 'serve.py')
wsgi_ini = os.path.join(options.directory, 'etc', 'wsgi.ini')
options.program = [
options.python, options.interpreter, script, wsgi_ini
options.python, options.interpreter, script, options.wsgi
]

c = ZopeCmd(options)
Expand Down
10 changes: 7 additions & 3 deletions src/plone/recipe/zope2instance/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ def __init__(self, buildout, name, options):
) not in ('off', 'disable', 'false')

self.wsgi = True
if six.PY2 and options.get('wsgi') in ('off', 'false'):
self.wsgi_config = os.path.join(options['location'], 'etc', 'wsgi.ini')
wsgi_opt = options.get('wsgi', 'on')
if six.PY2 and wsgi_opt.lower() in ('off', 'false', '0'):
self.wsgi = False
elif wsgi_opt.lower() not in ('on', 'true', '1'):
self.wsgi_config = wsgi_opt

# Get Scripts' attributes
return Scripts.__init__(self, buildout, name, options)
Expand Down Expand Up @@ -754,8 +758,8 @@ def __repr__(self):
arguments = ["-C", zope_conf_path, '-p', program_path]
if zopectl_umask:
arguments.extend(["--umask", int(zopectl_umask, 8)])
if self.wsgi:
arguments.append("--wsgi")
if self.wsgi and self.wsgi_config:
arguments.extend(['-w', self.wsgi_config])
script_arguments = ('\n ' + repr(arguments) +
'\n + sys.argv[1:]')

Expand Down
37 changes: 36 additions & 1 deletion src/plone/recipe/zope2instance/tests/zope2instance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ We should have a zope instance script with the custom config file::
>>> if WINDOWS:
... instance_path += '-script.py'
>>> open(instance_path).read()
"...plone.recipe.zope2instance.ctl.main(...['-C', '/some/path/my.conf', '-p', '.../bin/interpreter', '--wsgi']..."
"...plone.recipe.zope2instance.ctl.main(...['-C', '/some/path/my.conf', '-p', '.../bin/interpreter', '-w', '...etc/wsgi.ini']..."

Custom Zope Conf Imports
========================
Expand Down Expand Up @@ -1506,6 +1506,41 @@ We should have a zope instance, with custom imports::
...
<BLANKLINE>

Custom WSGI configuration
=========================

`wsgi` is an option that allows you to use a specific WSGI config file.

>>> write('buildout.cfg',
... '''
... [buildout]
... parts = instance
... find-links = %(sample_buildout)s/eggs
...
... [instance]
... recipe = plone.recipe.zope2instance
... eggs =
... user = me:me
... wsgi = /some/path/service.ini
... ''' % options)

Let's run it::

>>> print(system(join('bin', 'buildout'))),
Uninstalling instance.
Installing instance.
Generated script '...instance'.
Generated interpreter '.../parts/instance/bin/interpreter'...

We should have a zope instance script with the custom config file::

>>> instance_path = join('bin', 'instance')
>>> if WINDOWS:
... instance_path += '-script.py'
>>> open(instance_path).read()
"...plone.recipe.zope2instance.ctl.main(...[...'-w', '/some/path/service.ini']..."


Resources directory
===================

Expand Down

0 comments on commit 7eeda14

Please sign in to comment.