source: cmfdeployment/branches/kenw-p4-wip/transports/sitecopy.py @ 2380

Last change on this file since 2380 was 2380, checked in by kenw, 8 years ago

Committing new branch intended for Plone 4 compatibility; mostly required imports of new zope packages

File size: 5.9 KB
Line 
1##################################################################
2#
3# (C) Copyright 2004-2005 Kapil Thangavelu and Contributors
4#
5# All Rights Reserved
6#
7# This file is part of CMFDeployment.
8#
9# CMFDeployment is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# CMFDeployment 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 CMFDeployment; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22##################################################################
23"""
24Transfer deployed content via ftp or webdav using sitecopy.
25$Id: sitecopy.py 1657 2006-09-13 22:00:32Z hazmat $
26"""
27
28from Products.CMFDeployment.DeploymentInterfaces import IDeploymentProtocol, IDeploymentTarget
29from Products.CMFDeployment.lib import pexpect
30from Products.CMFDeployment.DeploymentExceptions import ProtocolError
31from Products.CMFDeployment.Namespace import *
32from Products.CMFDeployment.utils import SerializablePlugin
33from os import path
34from cStringIO import StringIO
35
36""" sitecopy config options
37
38       site sitename
39          server server-name
40          remote remote-root-directory
41          local local-root-directory
42        [ port port-number ]
43        [ username username ]
44        [ password password ]
45        [ proxy-server proxy-name
46          proxy-port port-number ]
47        [ url siteURL ]
48        [ protocol { ftp | webdav } ]
49        [ ftp nopasv ]
50        [ ftp showquit ]
51        [ ftp { usecwd | nousecwd } ]
52        [ http expect ]
53        [ http secure ]
54        [ safe ]
55        [ state { checksum | timesize } ]
56        [ permissions { ignore | exec | all | dir } ]
57        [ symlinks { ignore | follow | maintain } ]
58        [ nodelete ]
59        [ nooverwrite ]
60        [ checkmoved [renames] ]
61        [ tempupload ]
62        [ exclude pattern ]...
63        [ ignore pattern ]...
64        [ ascii pattern ]...
65"""       
66
67class SiteCopyProtocol(object):
68
69    __implements__ = IDeploymentProtocol
70
71    def execute(self, target, structure):
72
73        # you need to setup .sitecopyrc
74        host = target.getHost()
75
76        rcfile = CLIENT_HOME + '/.sitecopyrc'
77        storepath = CLIENT_HOME + '/.sitecopy'
78        command = 'sitecopy --rcfile=%s --storepath=%s' % (
79            target._rcfile, target._storepath)
80
81        rendered_command = '%s %s %s' % (command, '-uk', host)
82
83        log = StringIO()
84        conn = pexpect.spawn(rendered_command)
85        conn.setlog(log)
86        conn.expect(pexpect.EOF, 30) # 30 s timeout
87       
88        if conn.isalive():
89            conn.kill(1)
90
91        if conn.exitstatus != 0:
92            log.seek(0)
93            raise ProtocolError, log.read()
94
95addSiteCopyTransportForm = DTMLFile('../ui/SiteCopyTransportAddForm', globals())
96
97def addSiteCopyTransport( self,
98                          id,
99                          rcfile='',
100                          storepath='',
101                          RESPONSE=None):
102    """ add site copy transport """
103   
104    transport = SiteCopyTransport( id )
105    transport.edit( rcfile, storepath )
106    self._setObject( id, transport )
107   
108    if RESPONSE is not None:
109        RESPONSE.redirect('manage_main')
110
111class SiteCopyTransport( SerializablePlugin ):
112
113    __implements__ = IDeploymentTarget
114
115    meta_type = 'SiteCopy Target'
116   
117    security = ClassSecurityInfo()
118
119    _tprotocol = SiteCopyProtocol()
120    xml_factory = "addSiteCopyTransport"
121   
122    manage_options = (
123       
124        {'label':'Settings',
125         'action':'target_settings'},
126
127        ) + App.Undo.UndoSupport.manage_options
128
129    target_settings = DTMLFile('../ui/SiteCopyTransportSettingsForm', globals())
130
131    def __init__(self, id):
132        self.id = id
133        self._rcfile = None
134        self._storepath = None
135       
136    security.declareProtected(CMFCorePermissions.ManagePortal, 'edit')
137    def edit(self,
138             rcfile,
139             storepath,
140             RESPONSE=None):
141        """ edit transport """
142
143        self.checkRCFile( rcfile )
144        self.checkStorePath( storepath )
145
146        self._rcfile = path.abspath(path.expandvars(path.expanduser( rcfile )))
147        self._storepath = storepath
148
149        if RESPONSE is not None:
150            RESPONSE.redirect('manage_workspace')
151
152    def checkRCFile( self, rcfile ):
153        if not path.exists(
154                  path.abspath(
155                     path.expandvars(
156                        path.expanduser( rcfile )
157                        )
158                     )
159                  ):
160            raise SyntaxError("invalid rcfile %s"%rcfile)
161
162    security.declareProtected(CMFCorePermissions.ManagePortal, 'getRCFile')
163    def getRCFile(self):
164        return self._rcfile
165
166    def checkStorePath( self, storepath ):
167        pass
168
169    security.declareProtected(CMFCorePermissions.ManagePortal, 'getStorePath')
170    def getStorePath(self):
171        return self._storepath
172   
173    security.declareProtected(CMFCorePermissions.ManagePortal, 'transfer')
174    def transfer(self, structure ):
175        protocol = self.getProtocol()
176        protocol.execute( self, structure)
177       
178    security.declareProtected(CMFCorePermissions.ManagePortal, 'getProtocol')
179    def getProtocol(self):
180        return self._tprotocol
181
182    security.declarePrivate('getInfoForXml')
183    def getInfoForXml( self ):
184        d = SerializablePlugin.getInfoForXml( self )
185        del d['attributes']['title']
186        d.update( {
187            'rcfile':self._rcfile,
188            'storepath':self._storepath
189                  } )
190        return d
191       
192       
193InitializeClass( SiteCopyTransport )
Note: See TracBrowser for help on using the repository browser.