.. image:: https://secure.travis-ci.org/syslabcom/slc.zopescript.png
:target: http://travis-ci.org/#!/syslabcom/slc.zopescript
====================
slc.zopescript
====================
Base classes for running code as Zope console scripts
* `Source code @ GitHub <https://github.com/syslabcom/slc.zopescript>`_
* `Releases @ PyPI <http://pypi.python.org/pypi/slc.zopescript>`_
* `Documentation @ ReadTheDocs <http://slczopescript.readthedocs.org>`_
* `Continuous Integration @ Travis-CI <http://travis-ci.org/syslabcom/slc.zopescript>`_
Installation
============
To install `slc.zopescript` you add ``slc.zopescript``
to the dependencies of your own egg.
Usage
=====
slc.zopescript allows running code from the command line with a full Zope
instance and request available.
Console Script
--------------
To create a console script, i.e a script that you can run standalone from a
terminal, you can derive a class from `slc.zopescript.script.ConsoleScript` and
implement the `run()` method. The Zope app will be available as self.app and
the first Plone Site as self.portal. If you pass a context_path then
self.context will be the object represented by this path; otherwise
self.context will be the portal as well.
A request will be set up so that you can e.g. call browser views.
Example::
from my.egg import MailHandler
from slc.zopescript.script import ConsoleScript
class MailHandlerScript(ConsoleScript):
def run(self):
mailhandler_view = MailHandler(self.context, self.context.REQUEST)
mailhandler_view()
mail_handler = MailHandlerScript()
In your buildout you can generate the console script e.g. with zc.recipe.egg::
[mail_handler]
recipe = zc.recipe.egg
eggs = ${instance:eggs}
scripts = mail_handler
arguments = '${instance:location}/etc/zope.conf','admin',server_url='http://localhost:8081/Plone',context_path='/Plone/news'
The first argument must be the path to a valid zope.conf file. The second
argument is the user to run the script as. The optional server_url should be
the URL under which your site is externally reachable and allows you to use
meaningful absolute_url() calls. The optional context_path is the path to
an object that will be available as self.context in your script class.
Instance Script
---------------
To create an instance script, i.e. a script that you can pass to a zope
instance via `instance run my_script.py`, you can derive a class from
`slc.zopescript.script.InstanceScript` and implement the `run()` method. The
behaviour is similar to ConsoleScript, except that it doesn't set up the app
object but expects it to be passed in when it is instantiated.
Example::
from my.egg import MailHandler
from slc.zopescript.script import InstanceScript
class MailHandlerScript(InstanceScript):
def run(self):
mailhandler_view = MailHandler(self.context, self.context.REQUEST)
mailhandler_view()
if "app" in locals():
mail_handler = MailHandlerScript(app)
mail_handler('admin', server_url='http://localhost:8081/Plone', context_path='/Plone/news')
Save this code as e.g. `mail_handler.py` and call it with `instance run
mail_handler.py`. No buildout configuration is necessary. The arguments for the
call in the last line are the same as the ones you pass in the `arguments`
option for the console script, except that no zope.conf file can be passed.
:orphan:
Changelog
=========
1.1.4 (2021-11-30)
------------------
- Fix for Unauthorized on transaction commit.
[reinhardt]
1.1.3 (2021-10-07)
------------------
- Support for older Plone/Zope versions.
[reinhardt]
- Prevent the log level getting set to DEBUG
[goibhniu]
1.1.2 (2021-02-15)
------------------
- Support for WSGI.
[reinhardt]
1.1.1 (2021-02-15)
------------------
- ZCML namespace cleanup.
[thet]
1.1.0 (2019-01-28)
------------------
- Added InstanceScript class for use with `instance run`.
[reinhardt]
1.0.4 (2017-08-29)
------------------
- Improve log handling:
* only log errors during startup
* log INFO to stdout
* log ERROR to stderr
* log to instance's event.log too
This makes it possible to only escalate errors in cronjobs, send
normal logging to /dev/null and protocol what has been done in
the instance.log
[frisi]
1.0.3 (2016-05-19)
------------------
- traverse to context as run_as user [reinhardt]
- Allow selecting a portal by id [reinhardt]
1.0.2 (2016-03-18)
------------------
- better manifest [reinhardt]
1.0.1 (2016-03-18)
------------------
- Allow passing a context_path [reinhardt]
- Updated README [reinhardt]
1.0 (2015-12-11)
----------------
- Initial release.
[reinhardt]
:orphan:
License (3-clause BSD)
======================
Copyright (c) 2013, Syslab.com GmbH. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Syslab.com GmbH. nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SYSLAB.COM GMBH BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Raw data
{
"_id": null,
"home_page": "http://pypi.python.org/pypi/slc.zopescript",
"name": "slc.zopescript",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Zope console script",
"author": "Syslab.com GmbH",
"author_email": "info@syslab.com",
"download_url": "https://files.pythonhosted.org/packages/9d/d5/9b697068a8f252101d39cdbffb938bd7b2c7326f3370c230d7e50ffeabb5/slc.zopescript-1.1.4.tar.gz",
"platform": "",
"description": ".. image:: https://secure.travis-ci.org/syslabcom/slc.zopescript.png\n :target: http://travis-ci.org/#!/syslabcom/slc.zopescript\n\n====================\nslc.zopescript\n====================\n\nBase classes for running code as Zope console scripts\n\n* `Source code @ GitHub <https://github.com/syslabcom/slc.zopescript>`_\n* `Releases @ PyPI <http://pypi.python.org/pypi/slc.zopescript>`_\n* `Documentation @ ReadTheDocs <http://slczopescript.readthedocs.org>`_\n* `Continuous Integration @ Travis-CI <http://travis-ci.org/syslabcom/slc.zopescript>`_\n\nInstallation\n============\n\nTo install `slc.zopescript` you add ``slc.zopescript``\nto the dependencies of your own egg.\n\nUsage\n=====\n\nslc.zopescript allows running code from the command line with a full Zope\ninstance and request available.\n\nConsole Script\n--------------\n\nTo create a console script, i.e a script that you can run standalone from a\nterminal, you can derive a class from `slc.zopescript.script.ConsoleScript` and\nimplement the `run()` method. The Zope app will be available as self.app and\nthe first Plone Site as self.portal. If you pass a context_path then\nself.context will be the object represented by this path; otherwise\nself.context will be the portal as well.\nA request will be set up so that you can e.g. call browser views.\nExample::\n\n from my.egg import MailHandler\n from slc.zopescript.script import ConsoleScript\n\n\n class MailHandlerScript(ConsoleScript):\n def run(self):\n mailhandler_view = MailHandler(self.context, self.context.REQUEST)\n mailhandler_view()\n\n mail_handler = MailHandlerScript()\n\n\nIn your buildout you can generate the console script e.g. with zc.recipe.egg::\n\n [mail_handler]\n recipe = zc.recipe.egg\n eggs = ${instance:eggs}\n scripts = mail_handler\n arguments = '${instance:location}/etc/zope.conf','admin',server_url='http://localhost:8081/Plone',context_path='/Plone/news'\n\nThe first argument must be the path to a valid zope.conf file. The second\nargument is the user to run the script as. The optional server_url should be\nthe URL under which your site is externally reachable and allows you to use\nmeaningful absolute_url() calls. The optional context_path is the path to\nan object that will be available as self.context in your script class.\n\nInstance Script\n---------------\n\nTo create an instance script, i.e. a script that you can pass to a zope\ninstance via `instance run my_script.py`, you can derive a class from\n`slc.zopescript.script.InstanceScript` and implement the `run()` method. The\nbehaviour is similar to ConsoleScript, except that it doesn't set up the app\nobject but expects it to be passed in when it is instantiated.\nExample::\n\n from my.egg import MailHandler\n from slc.zopescript.script import InstanceScript\n\n\n class MailHandlerScript(InstanceScript):\n def run(self):\n mailhandler_view = MailHandler(self.context, self.context.REQUEST)\n mailhandler_view()\n\n\n if \"app\" in locals():\n mail_handler = MailHandlerScript(app)\n mail_handler('admin', server_url='http://localhost:8081/Plone', context_path='/Plone/news')\n\nSave this code as e.g. `mail_handler.py` and call it with `instance run\nmail_handler.py`. No buildout configuration is necessary. The arguments for the\ncall in the last line are the same as the ones you pass in the `arguments`\noption for the console script, except that no zope.conf file can be passed.\n:orphan:\n\nChangelog\n=========\n\n\n1.1.4 (2021-11-30)\n------------------\n\n- Fix for Unauthorized on transaction commit.\n [reinhardt]\n\n\n1.1.3 (2021-10-07)\n------------------\n\n- Support for older Plone/Zope versions.\n [reinhardt]\n- Prevent the log level getting set to DEBUG\n [goibhniu]\n\n\n1.1.2 (2021-02-15)\n------------------\n\n- Support for WSGI.\n [reinhardt]\n\n1.1.1 (2021-02-15)\n------------------\n\n- ZCML namespace cleanup.\n [thet]\n\n\n1.1.0 (2019-01-28)\n------------------\n\n- Added InstanceScript class for use with `instance run`.\n [reinhardt]\n\n\n1.0.4 (2017-08-29)\n------------------\n\n- Improve log handling:\n\n * only log errors during startup\n * log INFO to stdout\n * log ERROR to stderr\n * log to instance's event.log too\n\n This makes it possible to only escalate errors in cronjobs, send\n normal logging to /dev/null and protocol what has been done in\n the instance.log\n\n [frisi]\n\n\n1.0.3 (2016-05-19)\n------------------\n\n- traverse to context as run_as user [reinhardt]\n- Allow selecting a portal by id [reinhardt]\n\n\n1.0.2 (2016-03-18)\n------------------\n\n- better manifest [reinhardt]\n\n\n1.0.1 (2016-03-18)\n------------------\n\n- Allow passing a context_path [reinhardt]\n- Updated README [reinhardt]\n\n\n1.0 (2015-12-11)\n----------------\n\n- Initial release.\n [reinhardt]\n\n:orphan:\n\nLicense (3-clause BSD)\n======================\n\nCopyright (c) 2013, Syslab.com GmbH. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in the\n documentation and/or other materials provided with the distribution.\n\n * Neither the name of Syslab.com GmbH. nor the names of its contributors may\n be used to endorse or promote products derived from this software\n without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL SYSLAB.COM GMBH BE LIABLE FOR ANY\nDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Base classes for running code as Zope console scripts",
"version": "1.1.4",
"project_urls": {
"Homepage": "http://pypi.python.org/pypi/slc.zopescript"
},
"split_keywords": [
"zope",
"console",
"script"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9dd59b697068a8f252101d39cdbffb938bd7b2c7326f3370c230d7e50ffeabb5",
"md5": "aa9527e4acd7197ba1daa43d83c62825",
"sha256": "0dcb642fd555c9ae1f776fc9fb15beb6c1e5c3c6a0f23e6e3db77d3367b5b048"
},
"downloads": -1,
"filename": "slc.zopescript-1.1.4.tar.gz",
"has_sig": false,
"md5_digest": "aa9527e4acd7197ba1daa43d83c62825",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18201,
"upload_time": "2021-11-30T12:43:30",
"upload_time_iso_8601": "2021-11-30T12:43:30.258970Z",
"url": "https://files.pythonhosted.org/packages/9d/d5/9b697068a8f252101d39cdbffb938bd7b2c7326f3370c230d7e50ffeabb5/slc.zopescript-1.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-11-30 12:43:30",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "slc.zopescript"
}