List all Plone Sites in a Zope Instance
October 12, 2012Calling plone_sites
in the following code snippet will return a flat list of Plone Sites that are part of the current Zope Instance. As should be apparent it is possible for Plone Sites to be nested in other Plone Sites.
from OFS.interfaces import IApplication from Products.CMFPlone.interfaces import IPloneSiteRoot from zope.component.hooks import getSite def zope_root(): this = getSite() while not IApplication.providedBy(this): this = this.aq_inner.aq_parent return this def plone_sites(root=None): root = root or zope_root() sites = [] for id, item in root.items(): if not IPloneSiteRoot.providedBy(item): continue sites.append(item) sites.extend(plone_sites(item)) return sites