Back to index

plone3  3.1.7
customizationpolicy.py
Go to the documentation of this file.
00001 """Archetypes customization policy for Plone sites
00002 
00003 Based on the multilingual policy from Plone Solutions
00004 """
00005 
00006 __author__  = 'Christian Heimes'
00007 __docformat__ = 'restructuredtext'
00008 
00009 from zope.component import getUtility
00010 from StringIO import StringIO
00011 
00012 from logging import getLogger
00013 logger = getLogger('Archetypes')
00014 
00015 try:
00016     import Products.CMFPlone
00017 except ImportError:
00018     class DefaultCustomizationPolicy:
00019         pass
00020     def addPolicy(*args, **kwargs):
00021         raise ValueError('CustomizationPolicies not available.')
00022         
00023 else:
00024     from Products.CMFPlone.Portal import addPolicy
00025     from Products.CMFPlone.CustomizationPolicy import DefaultCustomizationPolicy
00026 
00027 from Products.CMFCore.utils import getToolByName
00028 from Products.Archetypes.utils import shasattr
00029 
00030 HAS_PLONE21 = True
00031 
00032 PRODUCTS = ('MimetypesRegistry', 'PortalTransforms', 'Archetypes', )
00033 
00034 class ArchetypesSitePolicy(DefaultCustomizationPolicy):
00035     """Site policy for SA
00036     """
00037 
00038     def customize(self, portal):
00039         DefaultCustomizationPolicy.customize(self, portal)
00040         out = StringIO()
00041         self.installArchetypes(portal, out)
00042         return out.getvalue()
00043     
00044     def installArchetypes(self, portal, out):
00045         """Install Archetypes with all dependencies
00046         """
00047         print >>out, 'Installing Archetypes ...'
00048         qi = getToolByName(portal, 'portal_quickinstaller')
00049         for product in PRODUCTS:
00050             if not qi.isProductInstalled(product):
00051                 qi.installProduct(product)
00052                 # Refresh skins
00053                 if shasattr(portal, '_v_skindata'):
00054                     portal._v_skindata = None
00055                 if shasattr(portal, 'setupCurrentSkin'):
00056                     portal.setupCurrentSkin()
00057                 print >>out, '   Installed %s' % product
00058             else:
00059                 print >>out, '   %s already installed' % product
00060         print >>out, 'Done\n'
00061         
00062 def registerPolicy(context):
00063     if not HAS_PLONE21:
00064         addPolicy('Archetypes Site', ArchetypesSitePolicy())