Adding Console Scripts to a Plone Buildout
In a straight setupttools
-based application, adding one or more
console scripts is straightforward: you just declare them in the
setup.py
, and set setuptools build them for you. However, when
using zc.buildout
for Plone 3.0.x or 3.1.x, you have to arrange to
get the non-eggified Zope2 products on the path, which is not easy.
This recipe works for me.
-
In the package's setup, declare the console script entry point as ususal:
-
Add a part to your buildout for the script(s) you want added to your
bin
directory: -
In the package, use the passed 'config_file' to get the root object:
class DoSomething: config_file = 'etc/zope.conf' app = None def __init__(self, config_file, argv): if config_file is not None: self.config_file = config_file self.argv = argv def getApplication(self): from Zope2.Startup.run import configure configure(self.config_file) import Zope2 return Zope2.app() def __call__(self): app = self.getApplication() # Do the actual work here, using self.app def main(config_file=None, argv=sys.argv): importer = DoSomething(config_file, argv) importer()
Re-run buildout.