[1] | 1 | from Products.Archetypes.public import listTypes |
---|
| 2 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
| 3 | from Products.CMFCore import CMFCorePermissions |
---|
| 4 | from Products.CMFCore.utils import getToolByName |
---|
| 5 | from StringIO import StringIO |
---|
| 6 | import sys |
---|
| 7 | |
---|
| 8 | from Products.qTrackSpam.config import * |
---|
| 9 | |
---|
| 10 | def install(self): |
---|
| 11 | """ install product """ |
---|
| 12 | out = StringIO(); |
---|
| 13 | portal = getToolByName(self,'portal_url').getPortalObject() |
---|
| 14 | installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) |
---|
| 15 | install_subskin(self, out, GLOBALS) |
---|
| 16 | install_configlet(self, out) |
---|
| 17 | try: |
---|
| 18 | portal.manage_addProduct[PROJECTNAME].manage_addTool(TOOL_METATYPE) |
---|
| 19 | except: |
---|
| 20 | # heuristics for testing if an instance with the same name already exists |
---|
| 21 | # only this error will be swallowed. |
---|
| 22 | # Zope raises in an unelegant manner a 'Bad Request' error |
---|
| 23 | e=sys.exc_info() |
---|
| 24 | if e[0] != 'Bad Request': |
---|
| 25 | raise |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | print >> out, "Successfully installed %s." % PROJECTNAME |
---|
| 30 | return out.getvalue() |
---|
| 31 | |
---|
| 32 | def uninstall(self): |
---|
| 33 | """ uninstall product """ |
---|
| 34 | out = StringIO() |
---|
| 35 | control_panel = getToolByName(self, 'portal_controlpanel', None) |
---|
| 36 | actions = control_panel._cloneActions() |
---|
| 37 | res = [a.id for a in actions if a.id == PROJECTNAME] |
---|
| 38 | for i in res: |
---|
| 39 | control_panel.unregisterConfiglet(i) |
---|
| 40 | out.write('Removed configlet %s\n' % i) |
---|
| 41 | |
---|
| 42 | print >> out, "Successfully uninstalled %s." % PROJECTNAME |
---|
| 43 | return out.getvalue() |
---|
| 44 | |
---|
| 45 | def install_configlet(self, out): |
---|
| 46 | control_panel=getToolByName(self,'portal_controlpanel') |
---|
| 47 | control_panel.registerConfiglet(PROJECTNAME, |
---|
| 48 | 'BlackList Importer', |
---|
| 49 | 'string:${portal_url}/prefs_blacklist_importer', |
---|
| 50 | permission = 'Manage Portal', |
---|
| 51 | category = 'Products', |
---|
| 52 | ) |
---|
| 53 | control_panel.registerConfiglet(PROJECTNAME, |
---|
| 54 | 'Clean TrackBacks', |
---|
| 55 | 'string:${portal_url}/prefs_clean_trackbacks', |
---|
| 56 | permission = 'Manage Portal', |
---|
| 57 | category = 'Products', |
---|
| 58 | ) |
---|
| 59 | print >> out, "Installed configlet.,," |
---|