def _removeImportStep(portal): to_remove = ('example.gs',) registry = portal.portal_setup.getImportStepRegistry() for step in to_remove: if step in registry._registered: registry.unregisterStep(step) logger.info("Removing import_step %s" % step)
def registerProperties(context): ptool = getToolByName(context, 'portal_properties') props = ptool.example_properties for prop in _PROPERTIES: if not props.hasProperty(prop['name']): props.manage_addProperty(prop['name'], prop['value'], prop['type_']) logger.info("Added missing %s property" % prop['name']) else: logger.info("Property %s already present. Skipping" % prop['name'])
def uninstall(portal, reinstall=False): if not reinstall: setup_tool = portal.portal_setup setup_tool.runAllImportStepsFromProfile('profile-example.gs:uninstall') _removeUserProperty(portal) _removePersistentUtility(portal) _removeProperties(portal) _removeTool(portal) _removeImportStep(portal) logger.info("Uninstall done")
def _removePersistentUtility(portal): sm = portal.getSiteManager() sm.unregisterUtility(provided=IFooUtility) util = sm.getUtility(IFooUtility) try: del util sm.utilities.unsubscribe((), IFooUtility) del sm.utilities.__dict__['_provided'][IFooUtility] logger.info("Removed utility") except KeyError: pass
def registerIndexes(portal): catalog = getToolByName(portal, 'portal_catalog') indexes = catalog.indexes() # Specify the indexes you want, with ('index_name', 'index_type') WANTED_INDEXES = (('getFoo', 'FieldIndex'), ) indexables = [] for name, meta_type in WANTED_INDEXES: if name not in indexes: catalog.addIndex(name, meta_type) indexables.append(name) logger.info("Added %s for field %s." % (meta_type, name)) else: logger.info("Index %s already found. Skipping" % name) # lines below if you want also reindex items when executing it if len(indexables) > 0: logger.info("Indexing new indexes %s." % ', '.join(indexables)) catalog.manage_reindexIndex(ids=indexables)
def migrateTo1100(context): setup_tool = getToolByName(context, 'portal_setup') # setup_tool.runImportStepFromProfile('profile-example.gs:default', 'single-step-you-want') logger.info('Migrated to version 0.2')
def _removeTool(portal): try: portal.manage_delObjects(['portal_foo']) logger.info("Portal tool removed") except AttributeError: pass
def _removeProperties(portal): try: portal.portal_properties.manage_delObjects(['example_properties']) logger.info("Property sheet removed") except BadRequest: pass
def _removeUserProperty(portal): try: portal.portal_memberdata.manage_delProperties(['foo']) logger.info("User property removed") except BadRequest: pass