Back to index

plone3  3.1.7
Public Member Functions | Private Attributes
Install.PloneSkinRegistrar Class Reference

List of all members.

Public Member Functions

def __init__
def install
def uninstall

Private Attributes

 _skinsdir
 _prodglobals

Detailed Description

Controls (un)registering of a layer in the skins tool:
 - the layer in the content of the skin tool
 - the layer in the path of all skins
@author: U{Gilles Lenfant <glenfant@bigfoot.com>}
@version: 0.1.0
@ivar _layer: Name of the Product's subdirectory that contains
    the various layers for the Product.
@type _layer: string
@ivar _prodglobals: Globals from this Product.
@type _propglobals: mapping object

Definition at line 14 of file Install.py.


Constructor & Destructor Documentation

def Install.PloneSkinRegistrar.__init__ (   self,
  skinsdir,
  prodglobals 
)
Constructor
@param skinsdir: Name of the Product's subdirectory that
    contains the various layers for the Product.
@type skinsdir: string
@param prodglobals: Globals from this Product.

    should be provided by Product's C{__init__.py} like this:

    C{product_globals = globals()}

@type propglobals: mapping object
@return: None

Definition at line 28 of file Install.py.

00028 
00029     def __init__(self, skinsdir, prodglobals):
00030         """Constructor
00031         @param skinsdir: Name of the Product's subdirectory that
00032             contains the various layers for the Product.
00033         @type skinsdir: string
00034         @param prodglobals: Globals from this Product.
00035 
00036             should be provided by Product's C{__init__.py} like this:
00037 
00038             C{product_globals = globals()}
00039 
00040         @type propglobals: mapping object
00041         @return: None
00042         """
00043 
00044         self._skinsdir = skinsdir
00045         self._prodglobals = prodglobals
00046         return


Member Function Documentation

def Install.PloneSkinRegistrar.install (   self,
  aq_obj,
  position = None,
  mode = 'after',
  layerName = None 
)
Installs and registers the skin resources
@param aq_obj: object from which cmf site object is acquired
@type aq_obj: any Zope object in the CMF
@return: Installation log
@rtype: string

Definition at line 47 of file Install.py.

00047 
00048     def install(self, aq_obj,position=None,mode='after',layerName=None):
00049         """Installs and registers the skin resources
00050         @param aq_obj: object from which cmf site object is acquired
00051         @type aq_obj: any Zope object in the CMF
00052         @return: Installation log
00053         @rtype: string
00054         """
00055 
00056         rpt = '=> Installing and registering layers from directory %s\n' % self._skinsdir
00057         skinstool = getToolByName(aq_obj, 'portal_skins')
00058 
00059         # Create the layer in portal_skins
00060 
00061         try:
00062             if self._skinsdir not in skinstool.objectIds():
00063                 addDirectoryViews(skinstool, self._skinsdir, self._prodglobals)
00064                 rpt += 'Added "%s" directory view to portal_skins\n' % self._skinsdir
00065             else:
00066                 rpt += 'Warning: directory view "%s" already added to portal_skins\n' % self._skinsdir
00067         except:
00068             # ugh, but i am in stress
00069             rpt += 'Warning: directory view "%s" already added to portal_skins\n' % self._skinsdir
00070 
00071 
00072         # Insert the layer in all skins
00073         # XXX FIXME: Actually assumes only one layer directory with the name of the Product
00074         # (should be replaced by a smarter solution that finds individual Product's layers)
00075 
00076         if not layerName:
00077             layerName = self._prodglobals['__name__'].split('.')[-1]
00078 
00079         skins = skinstool.getSkinSelections()
00080 
00081         for skin in skins:
00082             layers = skinstool.getSkinPath(skin)
00083             layers = [layer.strip() for layer in layers.split(',')]
00084             if layerName not in layers:
00085                 try:
00086                     pos=layers.index(position)
00087                     if mode=='after': pos=pos+1
00088                 except ValueError:
00089                     pos=len(layers)
00090 
00091                 layers.insert(pos, layerName)
00092 
00093                 layers = ','.join(layers)
00094                 skinstool.addSkinSelection(skin, layers)
00095                 rpt += 'Added "%s" to "%s" skin\n' % (layerName, skin)
00096             else:
00097                 rpt += '! Warning: skipping "%s" skin, "%s" is already set up\n' % (skin, type)
00098         return rpt

Here is the call graph for this function:

Here is the caller graph for this function:

def Install.PloneSkinRegistrar.uninstall (   self,
  aq_obj 
)
Uninstalls and unregisters the skin resources
@param aq_obj: object from which cmf site object is acquired
@type aq_obj: any Zope object in the CMF
@return: Uninstallation log
@rtype: string

Definition at line 99 of file Install.py.

00099 
00100     def uninstall(self, aq_obj):
00101         """Uninstalls and unregisters the skin resources
00102         @param aq_obj: object from which cmf site object is acquired
00103         @type aq_obj: any Zope object in the CMF
00104         @return: Uninstallation log
00105         @rtype: string
00106         """
00107 
00108         rpt = '=> Uninstalling and unregistering %s layer\n' % self._skinsdir
00109         skinstool = getToolByName(aq_obj, 'portal_skins')
00110 
00111         # Removing layer from portal_skins
00112         # XXX FIXME: Actually assumes only one layer directory with the name of the Product
00113         # (should be replaced by a smarter solution that finds individual Product's layers)
00114 
00115         if not layerName:
00116             layerName = self._prodglobals['__name__'].split('.')[-1]
00117 
00118         if layerName in skinstool.objectIds():
00119             skinstool.manage_delObjects([layerName])
00120             rpt += 'Removed "%s" directory view from portal_skins\n' % layerName
00121         else:
00122             rpt += '! Warning: directory view "%s" already removed from portal_skins\n' % layerName
00123 
00124         # Removing from skins selection
00125 
00126         skins = skinstool.getSkinSelections()
00127         for skin in skins:
00128             layers = skinstool.getSkinPath(skin)
00129             layers = [layer.strip() for layer in layers.split(',')]
00130             if layerName in layers:
00131                 layers.remove(layerName)
00132                 layers = ','.join(layers)
00133                 skinstool.addSkinSelection(skin, layers)
00134                 rpt += 'Removed "%s" to "%s" skin\n' % (layerName, skin)
00135             else:
00136                 rpt += 'Skipping "%s" skin, "%s" is already removed\n' % (skin, layerName)
00137         return rpt
00138 # /class PloneSkinRegistrar

Here is the call graph for this function:


Member Data Documentation

Definition at line 44 of file Install.py.

Definition at line 43 of file Install.py.


The documentation for this class was generated from the following file: