| 1 | import string |
|---|
| 2 | from cStringIO import StringIO |
|---|
| 3 | |
|---|
| 4 | from Products.CMFCore.utils import getToolByName |
|---|
| 5 | from Products.CMFCore.DirectoryView import addDirectoryViews |
|---|
| 6 | |
|---|
| 7 | from Products.CMFPlone.migrations.migration_util import safeEditProperty |
|---|
| 8 | from Products.qPloneTabs.config import * |
|---|
| 9 | |
|---|
| 10 | configlets = ({'id':PROJECTNAME, |
|---|
| 11 | 'name':'Plone Tabs', |
|---|
| 12 | 'action':'string:${portal_url}/prefs_tabs_form', |
|---|
| 13 | 'condition':'', |
|---|
| 14 | 'category':'Products', |
|---|
| 15 | 'visible':1, |
|---|
| 16 | 'appId':PROJECTNAME, |
|---|
| 17 | 'permission':VIEW_PERMISSION, |
|---|
| 18 | 'imageUrl':'qplonetabs.gif' },) |
|---|
| 19 | |
|---|
| 20 | def installResources(self, out): |
|---|
| 21 | # register stylesheets |
|---|
| 22 | portal_css = getToolByName(self, 'portal_css', None) |
|---|
| 23 | if portal_css is not None: |
|---|
| 24 | for css in CSSES: |
|---|
| 25 | if css['id'] not in portal_css.getResourceIds(): |
|---|
| 26 | portal_css.registerStylesheet(**css) |
|---|
| 27 | out.write("Registered %s stylesheet\n" % css['id']) |
|---|
| 28 | else: |
|---|
| 29 | out.write("Skipped registering %s stylesheet\n" % css['id']) |
|---|
| 30 | |
|---|
| 31 | # register javascripts |
|---|
| 32 | portal_javascripts = getToolByName(self, 'portal_javascripts', None) |
|---|
| 33 | if portal_javascripts is not None: |
|---|
| 34 | for js in JAVASCRIPTS: |
|---|
| 35 | if js['id'] not in portal_javascripts.getResourceIds(): |
|---|
| 36 | portal_javascripts.registerScript(**js) |
|---|
| 37 | out.write("Registered %s javascript " % js['id']) |
|---|
| 38 | else: |
|---|
| 39 | out.write("Skipped registering %s javascript\n" % js['id']) |
|---|
| 40 | |
|---|
| 41 | # register kss sheets |
|---|
| 42 | portal_kss = getToolByName(self, 'portal_kss', None) |
|---|
| 43 | if portal_kss is not None: |
|---|
| 44 | for kss in KSSES: |
|---|
| 45 | if kss['id'] not in portal_kss.getResourceIds(): |
|---|
| 46 | portal_kss.registerKineticStylesheet(**kss) |
|---|
| 47 | out.write("Registered %s kss " % kss['id']) |
|---|
| 48 | else: |
|---|
| 49 | out.write("Skipped registering %s kss\n" % kss['id']) |
|---|
| 50 | |
|---|
| 51 | def addPropertySheet(self, out): |
|---|
| 52 | """ Add tabs_properties property sheet to portal_properties and some needed field to it """ |
|---|
| 53 | portal_props = getToolByName(self, 'portal_properties') |
|---|
| 54 | if not hasattr(portal_props, PROPERTY_SHEET): |
|---|
| 55 | portal_props.addPropertySheet(PROPERTY_SHEET, SHEET_TITLE) |
|---|
| 56 | out.write('Added %s property sheet to portal_properties\n' % PROPERTY_SHEET) |
|---|
| 57 | else: |
|---|
| 58 | out.write('Skipped adding %s property sheet to portal_properties\n' % PROPERTY_SHEET) |
|---|
| 59 | sheet = getattr(portal_props, PROPERTY_SHEET) |
|---|
| 60 | |
|---|
| 61 | if not hasattr(sheet, FIELD_NAME): |
|---|
| 62 | safeEditProperty(sheet, FIELD_NAME, PROPERTY_FIELD, 'lines') |
|---|
| 63 | out.write('Added %s property field to %s property sheet\n' % (FIELD_NAME, PROPERTY_SHEET)) |
|---|
| 64 | else: |
|---|
| 65 | out.write('Skipped adding %s property field to %s property sheet\n' % (FIELD_NAME, PROPERTY_SHEET)) |
|---|
| 66 | |
|---|
| 67 | def setupSkin(self, out, skinFolder): |
|---|
| 68 | """ Setup product skin layer """ |
|---|
| 69 | |
|---|
| 70 | skinstool=getToolByName(self, 'portal_skins') |
|---|
| 71 | for skin in skinstool.getSkinSelections(): |
|---|
| 72 | path = skinstool.getSkinPath(skin) |
|---|
| 73 | path = map(string.strip, string.split(path,',')) |
|---|
| 74 | if not skinFolder in path: |
|---|
| 75 | try: |
|---|
| 76 | path.insert( path.index('custom')+1, skinFolder) |
|---|
| 77 | except ValueError: |
|---|
| 78 | path.append(skinFolder) |
|---|
| 79 | path = string.join(path, ', ') |
|---|
| 80 | skinstool.addSkinSelection(skin, path) |
|---|
| 81 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
|---|
| 82 | else: |
|---|
| 83 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
|---|
| 84 | |
|---|
| 85 | def removeSkin(self, skins=[]): |
|---|
| 86 | """ Setup product skin layer """ |
|---|
| 87 | |
|---|
| 88 | if skins: |
|---|
| 89 | skinstool = getToolByName(self, 'portal_skins') |
|---|
| 90 | for skinName in skinstool.getSkinSelections(): |
|---|
| 91 | path = skinstool.getSkinPath(skinName) |
|---|
| 92 | path = [i.strip() for i in path.split(',')] |
|---|
| 93 | for s in skins: |
|---|
| 94 | if s in path: |
|---|
| 95 | path.remove(s) |
|---|
| 96 | s += '/' |
|---|
| 97 | for layer in path: |
|---|
| 98 | if layer.startswith(s): |
|---|
| 99 | path.remove(layer) |
|---|
| 100 | path = ','.join(path) |
|---|
| 101 | skinstool.addSkinSelection(skinName, path) |
|---|
| 102 | |
|---|
| 103 | def addConfiglet(self, out): |
|---|
| 104 | """ Add tabs configlet to portal control panel """ |
|---|
| 105 | |
|---|
| 106 | configTool = getToolByName(self, 'portal_controlpanel', None) |
|---|
| 107 | if configTool: |
|---|
| 108 | for conf in configlets: |
|---|
| 109 | configTool.registerConfiglet(**conf) |
|---|
| 110 | out.write('Added configlet %s\n' % conf['id']) |
|---|
| 111 | |
|---|
| 112 | def removeConfiglet(self, out): |
|---|
| 113 | """ Remove tabs configlet from portal control panel """ |
|---|
| 114 | |
|---|
| 115 | configTool = getToolByName(self, 'portal_controlpanel', None) |
|---|
| 116 | if configTool: |
|---|
| 117 | for conf in configlets: |
|---|
| 118 | configTool.unregisterConfiglet(conf['id']) |
|---|
| 119 | out.write('Removed configlet %s\n' % conf['id']) |
|---|
| 120 | |
|---|
| 121 | def install(self): |
|---|
| 122 | """ Product installation """ |
|---|
| 123 | |
|---|
| 124 | out = StringIO() |
|---|
| 125 | |
|---|
| 126 | out.write('setupSkin... \n') |
|---|
| 127 | skinstool = getToolByName(self, 'portal_skins') |
|---|
| 128 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
|---|
| 129 | setupSkin(self, out, PROJECTNAME) |
|---|
| 130 | |
|---|
| 131 | installResources(self, out) |
|---|
| 132 | out.write("Installed Resources... \n") |
|---|
| 133 | |
|---|
| 134 | mtool = getToolByName(self, 'portal_migration') |
|---|
| 135 | plone_version = mtool.getFileSystemVersion() |
|---|
| 136 | if plone_version == '2.0.5': |
|---|
| 137 | setupSkin(self, out, PROJECTNAME+'/2.0.5') |
|---|
| 138 | out.write('Added %s/2.0.5 Layer to portal_skins\n' % PROJECTNAME) |
|---|
| 139 | |
|---|
| 140 | addPropertySheet(self, out) |
|---|
| 141 | |
|---|
| 142 | addConfiglet(self, out) |
|---|
| 143 | |
|---|
| 144 | return out.getvalue() |
|---|
| 145 | |
|---|
| 146 | def uninstall(self): |
|---|
| 147 | """ Product uninstallation """ |
|---|
| 148 | |
|---|
| 149 | out = StringIO() |
|---|
| 150 | |
|---|
| 151 | removeConfiglet(self, out) |
|---|
| 152 | |
|---|
| 153 | out.write('removeSkin... \n') |
|---|
| 154 | removeSkin(self, [PROJECTNAME, PROJECTNAME+'/2.0.5']) |
|---|
| 155 | |
|---|
| 156 | return out.getvalue() |
|---|