[1] | 1 | import string |
---|
| 2 | from cStringIO import StringIO |
---|
| 3 | from Products.CMFCore.utils import getToolByName |
---|
| 4 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
| 5 | from Products.Plone4ArtistsAudioPatch.config import * |
---|
| 6 | |
---|
| 7 | def setupSkin(self, out, skinFolder): |
---|
| 8 | """ Setup product skin layer """ |
---|
| 9 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 10 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
| 11 | for skin in skinstool.getSkinSelections(): |
---|
| 12 | path = skinstool.getSkinPath(skin) |
---|
| 13 | path = map(string.strip, string.split(path,',')) |
---|
| 14 | if not skinFolder in path: |
---|
| 15 | try: |
---|
| 16 | path.insert( path.index('custom')+1, skinFolder) |
---|
| 17 | except ValueError: |
---|
| 18 | path.append(skinFolder) |
---|
| 19 | path = string.join(path, ', ') |
---|
| 20 | skinstool.addSkinSelection(skin, path) |
---|
| 21 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 22 | else: |
---|
| 23 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 24 | |
---|
| 25 | def removeSkin(self, skins=[]): |
---|
| 26 | """ Setup product skin layer """ |
---|
| 27 | if skins: |
---|
| 28 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 29 | for skinName in skinstool.getSkinSelections(): |
---|
| 30 | path = skinstool.getSkinPath(skinName) |
---|
| 31 | path = [i.strip() for i in path.split(',')] |
---|
| 32 | for s in skins: |
---|
| 33 | if s in path: |
---|
| 34 | path.remove(s) |
---|
| 35 | s += '/' |
---|
| 36 | for layer in path: |
---|
| 37 | if layer.startswith(s): |
---|
| 38 | path.remove(layer) |
---|
| 39 | path = ','.join(path) |
---|
| 40 | skinstool.addSkinSelection(skinName, path) |
---|
| 41 | |
---|
| 42 | def installAction(self): |
---|
| 43 | ptypes = getToolByName(self, 'portal_types') |
---|
| 44 | type = ptypes.getTypeInfo('File') |
---|
| 45 | type.addAction('encode', |
---|
| 46 | name='Encode', |
---|
| 47 | action='string:${object_url}/audio_encoded_view', |
---|
| 48 | condition='python: object.get_content_type() == "audio/mpeg"', |
---|
| 49 | permission='Modify portal content', |
---|
| 50 | category='object') |
---|
| 51 | |
---|
| 52 | def uninstallAction(self): |
---|
| 53 | ptypes = getToolByName(self, 'portal_types') |
---|
| 54 | type = ptypes.getTypeInfo('File') |
---|
| 55 | actions = type._cloneActions() |
---|
| 56 | actions = [a for a in actions if a.id != 'encode'] |
---|
| 57 | type._actions = tuple(actions) |
---|
| 58 | |
---|
| 59 | def install(self): |
---|
| 60 | """ Product installation """ |
---|
| 61 | out = StringIO() |
---|
| 62 | out.write('setupSkin... \n') |
---|
| 63 | setupSkin(self, out, PROJECTNAME) |
---|
| 64 | installAction(self) |
---|
| 65 | out.write('Added new action for file content type') |
---|
| 66 | return out.getvalue() |
---|
| 67 | |
---|
| 68 | def uninstall(self): |
---|
| 69 | out = StringIO() |
---|
| 70 | removeSkin(self, [PROJECTNAME,]) |
---|
| 71 | uninstallAction(self) |
---|
| 72 | out.write('Removed audio_enc action for file content type') |
---|