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