Package platecom :: Package utils :: Module setuphandlers
[hide private]
[frames] | no frames]

Source Code for Module icsemantic.core.setuphandlers

  1  ############################################################################## 
  2  # 
  3  # Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved. 
  4  # 
  5  # This software is subject to the provisions of the Zope Public License, 
  6  # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution. 
  7  # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED 
  8  # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  9  # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 
 10  # FOR A PARTICULAR PURPOSE. 
 11  # 
 12  ############################################################################## 
 13  """ CMFDefault setup handlers. 
 14   
 15  """ 
 16  from StringIO import StringIO 
 17   
 18  from zope.interface import alsoProvides, directlyProvides, directlyProvidedBy 
 19  from zope.component import getUtility 
 20  from zope.app.component.hooks import setSite 
 21  from zope.app.component.interfaces import ISite, IPossibleSite 
 22  from Products.CMFCore.utils import getToolByName 
 23  from Products.Five.site.localsite import enableLocalSiteHook 
 24   
 25  import interfaces 
 26  from preferences import PlatecomManagementContentTypes 
 27  from config import HAS_PLONE3 
 28   
29 -def ensure_site(context):
30 """Ensure the given context implements ISite. The importance of 31 this method is that it will ensure the given context is an ISite 32 regardless of the Zope version (Zope 2.9 had a really hacked up 33 SiteManager mechanism we have to account for). 34 35 >>> from zope.app.component.interfaces import ISite, IPossibleSite 36 >>> from OFS.Folder import Folder 37 >>> if not IPossibleSite.implementedBy(Folder): 38 ... from zope import interface 39 ... from Products.Five.site.metaconfigure import (FiveSite, 40 ... classSiteHook) 41 ... classSiteHook(Folder, FiveSite) 42 ... interface.classImplements(Folder, IPossibleSite) 43 >>> om = Folder('foo') 44 45 >>> ISite.providedBy(om) 46 False 47 48 >>> from icsemantic.core.setuphandlers import ensure_site 49 >>> ensure_site(om) 50 >>> ISite.providedBy(om) 51 True 52 53 """ 54 if not IPossibleSite.providedBy(context): 55 if hasattr(context, 'getPhysicalPath'): 56 p = '/'.join(context.getPhysicalPath()) 57 elif hasattr(context, 'getId'): 58 p = context.getId() 59 elif hasattr(context, 'id'): 60 p = id 61 else: 62 p = str(context) 63 64 raise TypeError('The object, "%s", is not an IPossibleSite' % p) 65 66 if not ISite.providedBy(context): 67 enableLocalSiteHook(context) 68 setSite(context) 69 70 if not ISite.providedBy(context): 71 raise TypeError('Somehow trying to configure "%s" as an ISite ' 72 'has failed' % '/'.join(context.getPhysicalPath()))
73
74 -def setup_site(portal, out):
75 """ 76 77 >>> from icsemantic.core import interfaces 78 >>> from zope.app.component.hooks import setSite 79 >>> setSite(portal) 80 81 >>> sm = portal.getSiteManager() 82 >>> pmct = sm.queryUtility(interfaces.IicSemanticManagementContentTypes, 83 ... name='icSemantic.configuration') 84 >>> pmct # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE 85 <PlatecomManagementContentTypes at /plone.../> 86 87 >>> pmct.fallback_types = [] 88 89 """ 90 alsoProvides(portal, interfaces.IicSemanticSite) 91 sm = portal.getSiteManager() 92 93 if not sm.queryUtility(interfaces.IicSemanticManagementContentTypes, name='platecom.configuration'): 94 if HAS_PLONE3: 95 sm.registerUtility(PlatecomManagementContentTypes(), 96 interfaces.IicSemanticManagementContentTypes, 97 'platecom.configuration') 98 else: 99 sm.registerUtility(interfaces.IicSemanticManagementContentTypes, 100 PlatecomManagementContentTypes(), 101 'platecom.configuration')
102
103 -def importVarious(context):
104 """ Import various settings. 105 106 This provisional handler will be removed again as soon as full handlers 107 are implemented for these steps. 108 """ 109 site = context.getSite() 110 out = StringIO() 111 logger = context.getLogger("icsemantic.core") 112 113 ensure_site(site) 114 setup_site(site, out) 115 116 print >> out, 'Various settings imported.' 117 118 logger.info(out.getvalue()) 119 return out.getvalue()
120
121 -def unimportVarious(context):
122 """ Import various settings. 123 124 This provisional handler will be removed again as soon as full handlers 125 are implemented for these steps. 126 """ 127 site = context.getSite() 128 out = StringIO() 129 logger = context.getLogger("icsemantic.langfallback") 130 131 print >> out, 'Various settings unimported.' 132 133 logger.info(out.getvalue()) 134 return out.getvalue()
135