source: publico/ILCertificados/trunk/Extensions/Install.py @ 2674

Última Alteração nesse arquivo desde 2674 foi 2674, incluída por jeanferri, 14 anos atrás

Importação do produto de certificados on-line

File size: 7.6 KB
Linha 
1# -*- coding: utf-8 -*-
2#
3# File: Install.py
4#
5# Copyright (c) 2006 by Interlegis
6# Generator: ArchGenXML Version 1.5.0 svn/devel
7#            http://plone.org/products/archgenxml
8#
9# GNU General Public License (GPL)
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24# 02110-1301, USA.
25#
26
27__author__ = """STC Interlegis <admin-stc@interlegis.gov.br>"""
28__docformat__ = 'plaintext'
29
30
31import os.path
32import sys
33from StringIO import StringIO
34from sets import Set
35from App.Common import package_home
36from Products.CMFCore.utils import getToolByName
37from Products.CMFCore.utils import manage_addTool
38from Products.ExternalMethod.ExternalMethod import ExternalMethod
39from zExceptions import NotFound, BadRequest
40
41from Products.Archetypes.Extensions.utils import installTypes
42from Products.Archetypes.Extensions.utils import install_subskin
43from Products.Archetypes.config import TOOL_NAME as ARCHETYPETOOLNAME
44from Products.Archetypes.atapi import listTypes
45from Products.ILCertificados.config import PROJECTNAME
46from Products.ILCertificados.config import product_globals as GLOBALS
47
48def install(self):
49    """ External Method to install ILCertificados """
50    out = StringIO()
51    print >> out, "Installation log of %s:" % PROJECTNAME
52
53    # If the config contains a list of dependencies, try to install
54    # them.  Add a list called DEPENDENCIES to your custom
55    # AppConfig.py (imported by config.py) to use it.
56    try:
57        from Products.ILCertificados.config import DEPENDENCIES
58    except:
59        DEPENDENCIES = []
60    portal = getToolByName(self,'portal_url').getPortalObject()
61    quickinstaller = portal.portal_quickinstaller
62    for dependency in DEPENDENCIES:
63        print >> out, "Installing dependency %s:" % dependency
64        quickinstaller.installProduct(dependency)
65        get_transaction().commit(1)
66
67    classes = listTypes(PROJECTNAME)
68    installTypes(self, out,
69                 classes,
70                 PROJECTNAME)
71    install_subskin(self, out, GLOBALS)
72
73
74    # try to call a workflow install method
75    # in 'InstallWorkflows.py' method 'installWorkflows'
76    try:
77        installWorkflows = ExternalMethod('temp', 'temp',
78                                          PROJECTNAME+'.InstallWorkflows',
79                                          'installWorkflows').__of__(self)
80    except NotFound:
81        installWorkflows = None
82
83    if installWorkflows:
84        print >>out,'Workflow Install:'
85        res = installWorkflows(self,out)
86        print >>out,res or 'no output'
87    else:
88        print >>out,'no workflow install'
89
90
91    # enable portal_factory for given types
92    factory_tool = getToolByName(self,'portal_factory')
93    factory_types=[
94        "Certificados",
95        "EventoCertificado",
96        "Certificado",
97        "AssinaturaCertificado",
98        "TemplateCertificado",
99        ] + factory_tool.getFactoryTypes().keys()
100    factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types)
101
102    from Products.ILCertificados.config import STYLESHEETS
103    try:
104        portal_css = getToolByName(portal, 'portal_css')
105        for stylesheet in STYLESHEETS:
106            try:
107                portal_css.unregisterResource(stylesheet['id'])
108            except:
109                pass
110            defaults = {'id': '',
111            'media': 'all',
112            'enabled': True}
113            defaults.update(stylesheet)
114            portal_css.manage_addStylesheet(**defaults)
115    except:
116        # No portal_css registry
117        pass
118    from Products.ILCertificados.config import JAVASCRIPTS
119    try:
120        portal_javascripts = getToolByName(portal, 'portal_javascripts')
121        for javascript in JAVASCRIPTS:
122            try:
123                portal_javascripts.unregisterResource(javascript['id'])
124            except:
125                pass
126            defaults = {'id': ''}
127            defaults.update(javascript)
128            portal_javascripts.registerScript(**defaults)
129    except:
130        # No portal_javascripts registry
131        pass
132
133    # try to call a custom install method
134    # in 'AppInstall.py' method 'install'
135    try:
136        install = ExternalMethod('temp', 'temp',
137                                 PROJECTNAME+'.AppInstall', 'install')
138    except NotFound:
139        install = None
140
141    if install:
142        print >>out,'Custom Install:'
143        res = install(self)
144        if res:
145            print >>out,res
146        else:
147            print >>out,'no output'
148    else:
149        print >>out,'no custom install'
150    return out.getvalue()
151
152def uninstall(self):
153    out = StringIO()
154
155    # try to call a workflow uninstall method
156    # in 'InstallWorkflows.py' method 'uninstallWorkflows'
157    try:
158        uninstallWorkflows = ExternalMethod('temp', 'temp',
159                                            PROJECTNAME+'.InstallWorkflows',
160                                            'uninstallWorkflows').__of__(self)
161    except NotFound:
162        uninstallWorkflows = None
163
164    if uninstallWorkflows:
165        print >>out, 'Workflow Uninstall:'
166        res = uninstallWorkflows(self, out)
167        print >>out, res or 'no output'
168    else:
169        print >>out,'no workflow uninstall'
170
171    # try to call a custom uninstall method
172    # in 'AppInstall.py' method 'uninstall'
173    try:
174        uninstall = ExternalMethod('temp', 'temp',
175                                   PROJECTNAME+'.AppInstall', 'uninstall')
176    except:
177        uninstall = None
178
179    if uninstall:
180        print >>out,'Custom Uninstall:'
181        res = uninstall(self)
182        if res:
183            print >>out,res
184        else:
185            print >>out,'no output'
186    else:
187        print >>out,'no custom uninstall'
188
189    return out.getvalue()
190
191def beforeUninstall(self, reinstall, product, cascade):
192    """ try to call a custom beforeUninstall method in 'AppInstall.py'
193        method 'beforeUninstall'
194    """
195    out = StringIO()
196    try:
197        beforeuninstall = ExternalMethod('temp', 'temp',
198                                   PROJECTNAME+'.AppInstall', 'beforeUninstall')
199    except:
200        beforeuninstall = []
201
202    if beforeuninstall:
203        print >>out, 'Custom beforeUninstall:'
204        res = beforeuninstall(self, reinstall=reinstall
205                                  , product=product
206                                  , cascade=cascade)
207        if res:
208            print >>out, res
209        else:
210            print >>out, 'no output'
211    else:
212        print >>out, 'no custom beforeUninstall'
213    return (out,cascade)
214
215def afterInstall(self, reinstall, product):
216    """ try to call a custom afterInstall method in 'AppInstall.py' method
217        'afterInstall'
218    """
219    out = StringIO()
220    try:
221        afterinstall = ExternalMethod('temp', 'temp',
222                                   PROJECTNAME+'.AppInstall', 'afterInstall')
223    except:
224        afterinstall = None
225
226    if afterinstall:
227        print >>out, 'Custom afterInstall:'
228        res = afterinstall(self, product=None
229                               , reinstall=None)
230        if res:
231            print >>out, res
232        else:
233            print >>out, 'no output'
234    else:
235        print >>out, 'no custom afterInstall'
236    return out
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.