-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeploymentPolicy.py
267 lines (204 loc) · 8.38 KB
/
DeploymentPolicy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
##################################################################
#
# (C) Copyright 2002-2006 Kapil Thangavelu <k_vertigo@objectrealms.net>
# All Rights Reserved
#
# This file is part of CMFDeployment.
#
# CMFDeployment is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# CMFDeployment is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CMFDeployment; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##################################################################
"""
Purpose: Organizes Content in a Deployment Target Structure
Author: kapil thangavelu <k_vertigo@objectrealms.net> @2002-2006
License: GPL
Created: 8/10/2002
$Id$
"""
from xml.dom.minidom import parseString
import DefaultConfiguration
import Log
import pipeline
import io
from Namespace import *
from DeploymentInterfaces import IDeploymentPolicy
class DeploymentPolicy(Folder):
meta_type = 'Deployment Policy'
__implements__ = IDeploymentPolicy
security = ClassSecurityInfo()
security.declareObjectProtected(CMFCorePermissions.ManagePortal)
manage_options = (
{'label':'Overview',
'action':'overview'},
{'label':'Identification',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentIdentification},
{'label':'Organization',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentOrganization},
{'label':'Resources',
'action':'%s/manage_workspace'%DefaultConfiguration.SiteResources},
{'label':'URIs',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentURIs},
{'label':'Rendering',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentMastering},
{'label':'Transports',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentDeployment},
{'label':'Transforms',
'action':'%s/manage_workspace'%DefaultConfiguration.ContentTransforms},
{'label':'History',
'action':'%s/manage_workspace'%DefaultConfiguration.DeploymentHistory},
)
overview = DTMLFile('ui/PolicyOverview', globals())
preview = DTMLFile('ui/PolicyPreview', globals())
identification = DTMLFile('ui/ContentIdentification', globals())
_active = 1
_reset_date = False
policy_xml = DTMLFile('ui/PolicyExport', globals())
xml_key = 'policy'
icon = 'misc_/CMFDeployment/policy.png'
def __init__(self, id, title, pipeline_id):
self.id = id
self.title = title
self.pipeline_id = pipeline_id
assert pipeline_id in pipeline.getPipelineNames(), "invalid pipeline"
def getContentIdentification(self):
return self._getOb(DefaultConfiguration.ContentIdentification)
def getContentOrganization(self):
return self._getOb(DefaultConfiguration.ContentOrganization)
def getContentMastering(self):
return self._getOb(DefaultConfiguration.ContentMastering)
def getContentDeployment(self):
return self._getOb(DefaultConfiguration.ContentDeployment)
def getContentTransforms(self):
return self._getOb(DefaultConfiguration.ContentTransforms)
def getContentSources( self ):
return self.getContentIdentification().sources
def getDeploymentTransports( self ):
return self._getOb(DefaultConfiguration.ContentDeployment)
def getSiteResources( self ):
return self._getOb(DefaultConfiguration.SiteResources)
def getContentRules( self ):
return self.getContentMastering().rules
def getDeploymentHistory(self):
return self._getOb(DefaultConfiguration.DeploymentHistory)
def getDeploymentURIs(self):
return self._getOb(DefaultConfiguration.ContentURIs)
def getDeploymentPolicy(self):
return self
security.declareProtected('Manage Portal', 'clearState')
def clearState(self, RESPONSE=None):
"""
clear all persistent state from the policy, not including
configuration.
"""
self.getDeploymentHistory().clear()
self.getDeploymentURIs().clear()
factory = pipeline.getPipeline( self.pipeline_id )
factory.clearState( self )
if RESPONSE is not None:
RESPONSE.redirect('manage_workspace')
security.declarePrivate('getPipeline')
def getPipeline(self):
factory = pipeline.getPipeline( self.pipeline_id )
deployment_pipeline = factory()
return deployment_pipeline
def setActive(self, flag, RESPONSE=None):
self._active = not not flag
if RESPONSE is not None:
RESPONSE.redirect('overview')
def isActive(self):
return self._active
def setResetDate(self, flag):
""" Set the state of the reset flag
"""
self._reset_date = flag
def getResetDate(self):
""" Returns true if the incremental date should be ignored in the next deploy
"""
return self._reset_date
security.declareProtected('Manage Portal', 'previewDeployment')
def previewDeployment( self ):
preview_factory = pipeline.PreviewPipelineFactory()
preview = preview_factory()
preview.process( self )
return {'descriptors':preview.variables.get('descriptors'),
'deletions':preview.variables.get('deletions') }
def execute(self, REQUEST=None, RESPONSE=None):
""" """
if not self.isActive():
return
if getattr(REQUEST, 'reset_date', False):
self.setResetDate(True)
histories = self.getDeploymentHistory()
history = histories.makeHistory()
Log.attachLogMonitor(history)
try:
try:
pipeline = self.getPipeline()
pipeline.process( self )
except:
if not DefaultConfiguration.DEPLOYMENT_DEBUG:
raise
import sys, pdb, traceback
ec, e, tb = sys.exc_info()
print ec, e
print traceback.print_tb( tb )
#pdb.post_mortem( tb )
raise
finally:
Log.detachLogMonitor(history)
#history.recordStatistics(display)
histories.attachHistory(history)
self.getDeploymentPolicy().setResetDate(False)
if RESPONSE:
return RESPONSE.redirect('manage_workspace')
return True
def manage_afterAdd(self, item, container):
DefaultConfiguration.install(self)
factory = pipeline.getPipeline( self.pipeline_id )
factory.finishPolicyConstruction( self )
def manage_beforeDelete(self, *args):
factory = pipeline.getPipeline( self.pipeline_id )
factory.beginPolicyRemoval( self )
def export( self, compact=False, RESPONSE=None ):
"""
export to xml for download
"""
ctx = io.ExportContext()
ctx.load( self )
try:
export = ctx.construct()
except:
import pdb, traceback, sys
exc_info = sys.exc_info()
traceback.print_exception( *exc_info )
#pdb.post_mortem( exc_info[-1] )
raise
if not compact:
dom = parseString( export )
export = dom.toprettyxml()
if RESPONSE is not None:
RESPONSE.setHeader("Content-Type", 'text/xml')
RESPONSE.setHeader("Content-Length", len( export ) )
RESPONSE.setHeader("Content-Disposition",
'attachment; filename="%s.xml"'%(self.getId()))
return export
def getInfoForXml( self ):
info = {'attributes':{'id':self.id,
'title': self.title_or_id(),
'pipeline_id': self.pipeline_id } }
for ob in self.objectValues():
if hasattr( aq_base( ob ), 'xml_key' ):
info[ob.xml_key] = ob.getInfoForXml()
return info
InitializeClass(DeploymentPolicy)