| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # File: Install.py |
|---|
| 4 | # |
|---|
| 5 | # Copyright (c) 2006 by CommunesPlone |
|---|
| 6 | # |
|---|
| 7 | # GNU General Public License (GPL) |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or |
|---|
| 10 | # modify it under the terms of the GNU General Public License |
|---|
| 11 | # as published by the Free Software Foundation; either version 2 |
|---|
| 12 | # of the License, or (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 22 | # 02110-1301, USA. |
|---|
| 23 | # |
|---|
| 24 | |
|---|
| 25 | __author__ = """Gauthier BASTIEN <gbastien@commune.sambreville.be>""" |
|---|
| 26 | __docformat__ = 'plaintext' |
|---|
| 27 | |
|---|
| 28 | import os.path |
|---|
| 29 | import sys |
|---|
| 30 | from StringIO import StringIO |
|---|
| 31 | |
|---|
| 32 | from App.Common import package_home |
|---|
| 33 | from Products.CMFCore.utils import getToolByName |
|---|
| 34 | from Products.CMFCore.utils import manage_addTool |
|---|
| 35 | from Products.ExternalMethod.ExternalMethod import ExternalMethod |
|---|
| 36 | from zExceptions import NotFound, BadRequest |
|---|
| 37 | |
|---|
| 38 | from Products.Archetypes.Extensions.utils import installTypes |
|---|
| 39 | from Products.Archetypes.Extensions.utils import install_subskin |
|---|
| 40 | try: |
|---|
| 41 | from Products.Archetypes.lib.register import listTypes |
|---|
| 42 | except ImportError: |
|---|
| 43 | from Products.Archetypes.public import listTypes |
|---|
| 44 | from Products.CPComarquage.config import PROJECTNAME |
|---|
| 45 | from Products.CPComarquage.config import product_globals as GLOBALS |
|---|
| 46 | |
|---|
| 47 | def install(self): |
|---|
| 48 | """ External Method to install CPComarquage """ |
|---|
| 49 | out = StringIO() |
|---|
| 50 | print >> out, "Installation log of %s:" % PROJECTNAME |
|---|
| 51 | |
|---|
| 52 | # If the config contains a list of dependencies, try to install |
|---|
| 53 | # them. Add a list called DEPENDENCIES to your custom |
|---|
| 54 | # AppConfig.py (imported by config.py) to use it. |
|---|
| 55 | try: |
|---|
| 56 | from Products.CPComarquage.config import DEPENDENCIES |
|---|
| 57 | except: |
|---|
| 58 | DEPENDENCIES = [] |
|---|
| 59 | portal = getToolByName(self,'portal_url').getPortalObject() |
|---|
| 60 | quickinstaller = portal.portal_quickinstaller |
|---|
| 61 | for dependency in DEPENDENCIES: |
|---|
| 62 | print >> out, "Installing dependency %s:" % dependency |
|---|
| 63 | quickinstaller.installProduct(dependency) |
|---|
| 64 | get_transaction().commit(1) |
|---|
| 65 | |
|---|
| 66 | classes = listTypes(PROJECTNAME) |
|---|
| 67 | installTypes(self, out, |
|---|
| 68 | classes, |
|---|
| 69 | PROJECTNAME) |
|---|
| 70 | install_subskin(self, out, GLOBALS) |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | # try to call a workflow install method |
|---|
| 74 | # in 'InstallWorkflows.py' method 'installWorkflows' |
|---|
| 75 | try: |
|---|
| 76 | installWorkflows = ExternalMethod('temp','temp',PROJECTNAME+'.InstallWorkflows', 'installWorkflows').__of__(self) |
|---|
| 77 | except NotFound: |
|---|
| 78 | installWorkflows = None |
|---|
| 79 | |
|---|
| 80 | if installWorkflows: |
|---|
| 81 | print >>out,'Workflow Install:' |
|---|
| 82 | res = installWorkflows(self,out) |
|---|
| 83 | print >>out,res or 'no output' |
|---|
| 84 | else: |
|---|
| 85 | print >>out,'no workflow install' |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | # enable portal_factory for given types |
|---|
| 89 | factory_tool = getToolByName(self,'portal_factory') |
|---|
| 90 | factory_types=[ |
|---|
| 91 | ] + factory_tool.getFactoryTypes().keys() |
|---|
| 92 | factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) |
|---|
| 93 | |
|---|
| 94 | from Products.CPComarquage.config import STYLESHEETS |
|---|
| 95 | try: |
|---|
| 96 | portal_css = getToolByName(portal, 'portal_css') |
|---|
| 97 | for stylesheet in STYLESHEETS: |
|---|
| 98 | try: |
|---|
| 99 | portal_css.unregisterResource(stylesheet['id']) |
|---|
| 100 | except: |
|---|
| 101 | pass |
|---|
| 102 | defaults = {'id': '', |
|---|
| 103 | 'media': 'all', |
|---|
| 104 | 'enabled': True} |
|---|
| 105 | defaults.update(stylesheet) |
|---|
| 106 | portal_css.manage_addStylesheet(**defaults) |
|---|
| 107 | except: |
|---|
| 108 | # No portal_css registry |
|---|
| 109 | pass |
|---|
| 110 | from Products.CPComarquage.config import JAVASCRIPTS |
|---|
| 111 | try: |
|---|
| 112 | portal_javascripts = getToolByName(portal, 'portal_javascripts') |
|---|
| 113 | for javascript in JAVASCRIPTS: |
|---|
| 114 | try: |
|---|
| 115 | portal_javascripts.unregisterResource(stylesheet['id']) |
|---|
| 116 | except: |
|---|
| 117 | pass |
|---|
| 118 | defaults = {'id': ''} |
|---|
| 119 | defaults.update(javascript) |
|---|
| 120 | portal_javascripts.registerScript(**defaults) |
|---|
| 121 | except: |
|---|
| 122 | # No portal_javascripts registry |
|---|
| 123 | pass |
|---|
| 124 | |
|---|
| 125 | # try to call a custom install method |
|---|
| 126 | # in 'AppInstall.py' method 'install' |
|---|
| 127 | try: |
|---|
| 128 | install = ExternalMethod('temp','temp',PROJECTNAME+'.AppInstall', 'install') |
|---|
| 129 | except NotFound: |
|---|
| 130 | install = None |
|---|
| 131 | |
|---|
| 132 | if install: |
|---|
| 133 | print >>out,'Custom Install:' |
|---|
| 134 | res = install(self) |
|---|
| 135 | if res: |
|---|
| 136 | print >>out,res |
|---|
| 137 | else: |
|---|
| 138 | print >>out,'no output' |
|---|
| 139 | else: |
|---|
| 140 | print >>out,'no custom install' |
|---|
| 141 | return out.getvalue() |
|---|
| 142 | |
|---|
| 143 | def uninstall(self): |
|---|
| 144 | out = StringIO() |
|---|
| 145 | |
|---|
| 146 | # try to call a workflow uninstall method |
|---|
| 147 | # in 'InstallWorkflows.py' method 'uninstallWorkflows' |
|---|
| 148 | |
|---|
| 149 | # TODO: this is buggy code. There is no workflow uninstaller in |
|---|
| 150 | # the generated InstallWorkflows.py. |
|---|
| 151 | try: |
|---|
| 152 | uninstallWorkflows = ExternalMethod('temp','temp',PROJECTNAME+'.InstallWorkflows', 'uninstallWorkflows').__of__(self) |
|---|
| 153 | except NotFound: |
|---|
| 154 | uninstallWorkflows = None |
|---|
| 155 | |
|---|
| 156 | if uninstallWorkflows: |
|---|
| 157 | print >>out, 'Workflow Uninstall:' |
|---|
| 158 | res = uninstallWorkflows(self, out) |
|---|
| 159 | print >>out, res or 'no output' |
|---|
| 160 | else: |
|---|
| 161 | print >>out,'no workflow uninstall' |
|---|
| 162 | |
|---|
| 163 | # try to call a custom uninstall method |
|---|
| 164 | # in 'AppInstall.py' method 'uninstall' |
|---|
| 165 | try: |
|---|
| 166 | uninstall = ExternalMethod('temp','temp',PROJECTNAME+'.AppInstall', 'uninstall') |
|---|
| 167 | except: |
|---|
| 168 | uninstall = None |
|---|
| 169 | |
|---|
| 170 | if uninstall: |
|---|
| 171 | print >>out,'Custom Uninstall:' |
|---|
| 172 | res = uninstall(self) |
|---|
| 173 | if res: |
|---|
| 174 | print >>out,res |
|---|
| 175 | else: |
|---|
| 176 | print >>out,'no output' |
|---|
| 177 | else: |
|---|
| 178 | print >>out,'no custom uninstall' |
|---|
| 179 | |
|---|
| 180 | return out.getvalue() |
|---|