source: publico/ILSAALMaterial/trunk/Extensions/Install.py @ 1523

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

Atualizada a versão do ArchGenXml para a 1.4RC2

File size: 7.5 KB
Linha 
1""" Extensions/Install.py """
2
3# Copyright (c) 2005 by Interlegis
4#
5# Generated:
6# Generator: ArchGenXML Version 1.4.0-RC2 svn/development
7#            http://plone.org/products/archgenxml
8#
9# GNU General Public Licence (GPL)
10#
11# This program is free software; you can redistribute it and/or modify it under
12# the terms of the GNU General Public License as published by the Free Software
13# Foundation; either version 2 of the License, or (at your option) any later
14# version.
15# This program is distributed in the hope that it will be useful, but WITHOUT
16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18# details.
19# You should have received a copy of the GNU General Public License along with
20# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21# Place, Suite 330, Boston, MA  02111-1307  USA
22#
23__author__    = '''STC Interlegis <stc@interlegis.gov.br>'''
24__docformat__ = 'plaintext'
25__version__   = '$ Revision 0.0 $'[11:-2]
26
27import os.path
28import sys
29from StringIO import StringIO
30
31from App.Common import package_home
32from Products.CMFCore.utils import getToolByName
33from Products.CMFCore.utils import manage_addTool
34from Products.ExternalMethod.ExternalMethod import ExternalMethod
35from zExceptions import NotFound, BadRequest
36
37from Products.Archetypes.Extensions.utils import installTypes
38from Products.Archetypes.Extensions.utils import install_subskin
39try:
40    from Products.Archetypes.lib.register import listTypes
41except ImportError:
42    from Products.Archetypes.public import listTypes
43from Products.ILSAALMaterial.config import PROJECTNAME
44from Products.ILSAALMaterial.config import product_globals as GLOBALS
45
46def install(self):
47    """ External Method to install ILSAALMaterial """
48    out = StringIO()
49    print >> out, "Installation log of %s:" % PROJECTNAME
50
51    # If the config contains a list of dependencies, try to install
52    # them.  Add a list called DEPENDENCIES to your custom
53    # AppConfig.py (imported by config.py) to use it.
54    try:
55        from Products.ILSAALMaterial.config import DEPENDENCIES
56    except:
57        DEPENDENCIES = []
58    portal = getToolByName(self,'portal_url').getPortalObject()
59    quickinstaller = portal.portal_quickinstaller
60    for dependency in DEPENDENCIES:
61        print >> out, "Installing dependency %s:" % dependency
62        quickinstaller.installProduct(dependency)
63        get_transaction().commit(1)
64
65    classes = listTypes(PROJECTNAME)
66    installTypes(self, out,
67                 classes,
68                 PROJECTNAME)
69    install_subskin(self, out, GLOBALS)
70
71               
72    # Create vocabularies in vocabulary lib
73    atvm = getToolByName(self, 'portal_vocabularies')
74    vocabmap = {u'local_requisicao': ('SimpleVocabulary', 'SimpleVocabularyTerm'),
75         u'local_almoxarifado': ('SimpleVocabulary', 'SimpleVocabularyTerm'),
76         u'unidade_medida': ('SimpleVocabulary', 'SimpleVocabularyTerm'),
77        }
78    for vocabname in vocabmap.keys():
79        if not vocabname in atvm.contentIds():
80            atvm.invokeFactory(vocabmap[vocabname][0], vocabname)
81           
82        if len(atvm[vocabname].contentIds()) < 1:
83            if vocabmap[vocabname][0] == "VdexVocabulary":
84                vdexpath = os.path.join(
85                    package_home(GLOBALS), 'data', '%s.vdex' % vocabname)
86                if not (os.path.exists(vdexpath) and os.path.isfile(vdexpath)):
87                    print >>out, 'No VDEX import file provided at %s.' % vdexpath
88                    continue
89                try:
90                    #read data
91                    f = open(vdexpath, 'r')
92                    data = f.read()
93                    f.close()
94                except:
95                    print >>out, 'Problems while reading VDEX import file provided at %s.' % vdexpath
96                    continue
97                atvm[vocabname].importXMLBinding(data)                   
98            else:
99                atvm[vocabname].invokeFactory(vocabmap[vocabname][1],'default')
100                atvm[vocabname]['default'].setTitle('Default term, replace it by your own stuff')
101
102    # try to call a workflow install method
103    # in 'InstallWorkflows.py' method 'installWorkflows'
104    try:
105        installWorkflows = ExternalMethod('temp','temp',PROJECTNAME+'.InstallWorkflows', 'installWorkflows').__of__(self)
106    except NotFound:
107        installWorkflows = None
108
109    if installWorkflows:
110        print >>out,'Workflow Install:'
111        res = installWorkflows(self,out)
112        print >>out,res or 'no output'
113    else:
114        print >>out,'no workflow install'
115
116    #bind classes to workflows
117    wft = getToolByName(self,'portal_workflow')
118
119    # enable portal_factory for given types
120    factory_tool = getToolByName(self,'portal_factory')
121    factory_types=[
122        ] + factory_tool.getFactoryTypes().keys()
123    factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types)
124
125    from Products.ILSAALMaterial.config import STYLESHEETS
126    try:
127        portal_css = getToolByName(portal, 'portal_css')
128        for stylesheet in STYLESHEETS:
129            try:
130                portal_css.unregisterResource(stylesheet['id'])
131            except:
132                pass
133            defaults = {'id': '',
134            'media': 'all',
135            'enabled': True}
136            defaults.update(stylesheet)
137            portal_css.manage_addStylesheet(**defaults)
138    except:
139        # No portal_css registry
140        pass
141    from Products.ILSAALMaterial.config import JAVASCRIPTS
142    try:
143        portal_javascripts = getToolByName(portal, 'portal_javascripts')
144        for javascript in JAVASCRIPTS:
145            try:
146                portal_javascripts.unregisterResource(stylesheet['id'])
147            except:
148                pass
149            defaults = {'id': ''}
150            defaults.update(javascript)
151            portal_javascripts.registerScript(**defaults)
152    except:
153        # No portal_javascripts registry
154        pass
155
156    # try to call a custom install method
157    # in 'AppInstall.py' method 'install'
158    try:
159        install = ExternalMethod('temp','temp',PROJECTNAME+'.AppInstall', 'install')
160    except NotFound:
161        install = None
162
163    if install:
164        print >>out,'Custom Install:'
165        res = install(self)
166        if res:
167            print >>out,res
168        else:
169            print >>out,'no output'
170    else:
171        print >>out,'no custom install'
172    return out.getvalue()
173
174def uninstall(self):
175    out = StringIO()
176
177    # try to call a workflow uninstall method
178    # in 'InstallWorkflows.py' method 'uninstallWorkflows'
179   
180    # TODO: this is buggy code. There is no workflow uninstaller in
181    # the generated InstallWorkflows.py.
182    try:
183        uninstallWorkflows = ExternalMethod('temp','temp',PROJECTNAME+'.InstallWorkflows', 'uninstallWorkflows').__of__(self)
184    except NotFound:
185        uninstallWorkflows = None
186
187    if uninstallWorkflows:
188        print >>out, 'Workflow Uninstall:'
189        res = uninstallWorkflows(self, out)
190        print >>out, res or 'no output'
191    else:
192        print >>out,'no workflow uninstall'
193
194    # try to call a custom uninstall method
195    # in 'AppInstall.py' method 'uninstall'
196    try:
197        uninstall = ExternalMethod('temp','temp',PROJECTNAME+'.AppInstall', 'uninstall')
198    except:
199        uninstall = None
200
201    if uninstall:
202        print >>out,'Custom Uninstall:'
203        res = uninstall(self)
204        if res:
205            print >>out,res
206        else:
207            print >>out,'no output'
208    else:
209        print >>out,'no custom uninstall'
210
211    return out.getvalue()
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.