This project aims to bring some of the fun and ease of the Pyramid development style into Plone.
At its current stage it only has some helpers to simplify GenericSetup handling, especially around upgrade steps.
The code and issue tracker can be found at https://github.com/hannosch/plutonian
This project assumes you are writing a specific application based on top of Plone. You have one policy package that manages the specifics of one site.
This library wasn't intended for writing reusable add-ons for Plone, but what's here should work for such a use-case.
Preliminary notes on using the GenericSetup helpers:
In your policy package's (for example named
def initialize(context): from policy import config config.config.register_profile() config.config.scan()
For the initialize function to be picked up, you need a
<configure xmlns="http://namespaces.zope.org/zope" xmlns:five="http://namespaces.zope.org/five" i18n_domain="policy"> <five:registerPackage package="." initialize=".initialize"/> </configure>
from plutonian import Configurator config = Configurator('policy')
from plone.app.upgrade.utils import loadMigrationProfile from plutonian.gs import import_step from plutonian.gs import upgrade_to from Products.CMFCore.utils import getToolByName from policy.config import config def set_profile_version(site): # while creating a new site, assign the last version number and thus # treat it as not needing any of the existing upgrade steps setup = getToolByName(site, 'portal_setup') setup.setLastVersionForProfile( config.policy_profile, config.last_upgrade_to()) @import_step() def various(context): if context.readDataFile('policy-various.txt') is None: return site = context.getSite() set_profile_version(site) @upgrade_to(2) def do_something(context): # apply some existing GS files again from the policy profile if they # have changed or do anything else you might need to do loadMigrationProfile(context, 'profile-policy:default', steps=('cssregistry', 'jsregistry', 'plone.app.registry', ))
And finally create a GS profile with a folder structure of
and put a
metadata.xml file in there::
<?xml version="1.0"?> <metadata> <!-- The version is determined based on the registered upgrade steps and must not be set here --> <!-- <version>unknown</version> --> </metadata>
You also need to create the empty flag file named
upgrade_to decorator takes integers. No number can be taken multiple
times, but there can be numbers missing in the sequence.
The upgrade steps are registered in the normal place and can be run via the
portal_setup ZMI screens. As an alternative you can create a
command to run them from the command line. In your
setup.py add an entry::
entry_points=""" [zopectl.command] upgrade = policy.commands:upgrade """
And create a
commands.py with the function::
You can then call this script via::
It will currently recook the CSS/JS resources on each run, but otherwise has no ill side-effects, so you can run it as many times as you want.