[1] | 1 | from StringIO import StringIO |
---|
| 2 | from Products.Archetypes.public import listTypes |
---|
| 3 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
| 4 | from Products.CMFCore.CMFCorePermissions import ManagePortal |
---|
| 5 | from Products.CMFCore.utils import getToolByName |
---|
| 6 | from Products.qPingTool.config import * |
---|
| 7 | from Products.qPingTool import PingTool |
---|
| 8 | from Products.CMFCore.TypesTool import ContentFactoryMetadata |
---|
| 9 | from Products.CMFCore.utils import getToolByName |
---|
| 10 | from Products.CMFPlone.migrations.migration_util import safeEditProperty |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | def install(self): |
---|
| 14 | out = StringIO() |
---|
| 15 | |
---|
| 16 | installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) |
---|
| 17 | portal = getToolByName(self, 'portal_url').getPortalObject() |
---|
| 18 | if not hasattr(portal, TOOL_ID): |
---|
| 19 | portal.invokeFactory(id=TOOL_ID, type_name='PingTool') |
---|
| 20 | |
---|
| 21 | # Add PortalActions Tool Configlet. Delete old version before adding, if exist one. |
---|
| 22 | controlpanel_tool = getToolByName(self, 'portal_controlpanel') |
---|
| 23 | controlpanel_tool.unregisterConfiglet(TOOL_ID) |
---|
| 24 | controlpanel_tool.registerConfiglet(id=TOOL_ID, name='Ping Tool', category='Products', |
---|
| 25 | action='string:${portal_url}/'+TOOL_ID+'/folder_contents', |
---|
| 26 | appId=PROJECTNAME, permission=ManagePortal, imageUrl='group.gif') |
---|
| 27 | |
---|
| 28 | # Add 'portal_actionstool' to action provider list, if not yet exist |
---|
| 29 | action_tool = getToolByName(portal, 'portal_actions') |
---|
| 30 | if TOOL_ID not in action_tool.listActionProviders(): |
---|
| 31 | action_tool.addActionProvider(TOOL_ID) |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | install_subskin(self,out,GLOBALS) |
---|
| 35 | existent_sites = portal.portal_pingtool.objectIds() |
---|
| 36 | for site in SITES_LIST: |
---|
| 37 | if not site[0] in existent_sites: |
---|
| 38 | portal.portal_pingtool.invokeFactory(id = site[0], type_name = "PingInfo", title = site[1],url = site[2]) |
---|
| 39 | |
---|
| 40 | pp = getToolByName(self,'portal_properties') |
---|
| 41 | np = getattr(pp,'navtree_properties') |
---|
| 42 | meta_types = list(np.getProperty('metaTypesNotToList')) |
---|
| 43 | if 'PingTool' not in meta_types: |
---|
| 44 | meta_types.append('PingTool') |
---|
| 45 | safeEditProperty(np,'metaTypesNotToList', meta_types, 'lines') |
---|
| 46 | |
---|
| 47 | sp = getattr(pp,'site_properties', None) |
---|
| 48 | if hasattr(sp, 'typesUseViewActionInListings'): |
---|
| 49 | sp.typesUseViewActionInListings += ('PingInfo',) |
---|
| 50 | |
---|
| 51 | print >> out, "\nSuccessfully installed %s." % PROJECTNAME |
---|
| 52 | return out.getvalue() |
---|
| 53 | |
---|
| 54 | def uninstall(portal): |
---|
| 55 | action_tool = getToolByName(portal, 'portal_actions') |
---|
| 56 | # Delete ActionProvider |
---|
| 57 | action_tool.deleteActionProvider(TOOL_ID) |
---|
| 58 | |
---|
| 59 | controlpanel_tool = getToolByName(portal, 'portal_controlpanel') |
---|
| 60 | controlpanel_tool.unregisterConfiglet(TOOL_ID) |
---|
| 61 | |
---|
| 62 | removeSkin(portal, ('ping_tool.pt',)) |
---|
| 63 | |
---|
| 64 | #wf_tool=getToolByName(self, 'portal_workflow') |
---|
| 65 | #wf=wf_tool.plone_workflow |
---|
| 66 | #tdef = wf.transitions['publish'] |
---|
| 67 | #tdef.after_script_name=None |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | return '%s actionProvider successfully uninstalled' % TOOL_ID |
---|
| 71 | |
---|
| 72 | def removeSkin(self, skins = []): |
---|
| 73 | if skins: |
---|
| 74 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 75 | for skinName in skinstool.getSkinSelections(): |
---|
| 76 | path = skinstool.getSkinPath(skinName) |
---|
| 77 | path = [i.strip() for i in path.split(',')] |
---|
| 78 | for s in skins: |
---|
| 79 | if s in path: |
---|
| 80 | path.remove(s) |
---|
| 81 | path = ','.join(path) |
---|
| 82 | skinstool.addSkinSelection(skinName, path) |
---|