Package ZenUtils :: Module Skins
[hide private]
[frames] | no frames]

Source Code for Module ZenUtils.Skins

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13  import sys, os 
14  import string  
15   
16   
17 -def skinDirs(base):
18 layers = [] 19 for p, ds, fs in os.walk(os.path.join(base, 'skins')): 20 for d in ds: 21 if not d.startswith('.'): 22 layers.append(d) 23 # stop at one level 24 return layers
25 26
27 -def registerSkin(self, base, positionAfter='custom'):
28 """setup the skins in a product""" 29 layers = skinDirs(base) 30 try: 31 from Products.CMFCore.utils import getToolByName 32 from Products.CMFCore.DirectoryView import addDirectoryViews 33 skinstool = getToolByName(self, 'portal_skins') 34 for layer in layers: 35 if layer not in skinstool.objectIds(): 36 addDirectoryViews(skinstool, 'skins', base) 37 skins = skinstool.getSkinSelections() 38 for skin in skins: 39 path = skinstool.getSkinPath(skin) 40 path = map(string.strip, string.split(path,',')) 41 for layer in layers: 42 if layer not in path: 43 try: 44 path.insert(path.index(positionAfter)+1, layer) 45 except ValueError: 46 path.append(layer) 47 path = ','.join(path) 48 skinstool.addSkinSelection(skin, path) 49 except ImportError, e: 50 if "Products.CMFCore.utils" in e.args: pass 51 else: raise 52 except AttributeError, e: 53 if "portal_skin" in e.args: pass 54 else: raise
55
56 -def unregisterSkin(self, base, positionAfter='custom'):
57 """setup the skins in a product""" 58 layers = skinDirs(base) 59 if layers is None: return 60 try: 61 from Products.CMFCore.utils import getToolByName 62 skinstool = getToolByName(self, 'portal_skins') 63 for layer in layers: 64 if layer in skinstool.objectIds(): 65 try: 66 skinstool._delOb(layer) 67 except AttributeError: 68 pass 69 obs = skinstool._objects 70 goodlayers = filter(lambda x:getattr(skinstool, x['id'], False), obs) 71 skinstool._objects = tuple(goodlayers) 72 except ImportError, e: 73 if "Products.CMFCore.utils" in e.args: pass 74 else: raise 75 except AttributeError, e: 76 if "portal_skin" in e.args: pass 77 else: raise
78