Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 290 lines (221 sloc) 9.116 kb
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
1 # -*- coding: utf-8 -*-
2 #
3 # Cherokee-admin
4 #
5 # Authors:
6 # Alvaro Lopez Ortega <alvaro@alobbs.com>
7 #
8 # Copyright (C) 2001-2011 Alvaro Lopez Ortega
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of version 2 of the GNU General Public
12 # License as published by the Free Software Foundation.
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 import os
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
26 import re
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
27 import CTK
28 import popen
29 import Install_Log
30
31
32 class Wizard (object):
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
33 """
34 self.params
35 -----------
7768a57 @alobbs WIP: Implements internal Virtual Server wizards support.
alobbs authored
36 type : 'directory' or 'vserver'
37 vserver_num: 10, 20, ..
38 web_directory: /webdir
39 vserver_nick: example.com
40 app_fetch: /tmp/bat.tgz, http://_/foo.tgz
41 app_dir: /var/www_apps/worpress
42 targz_path: /tmp/foobar.tgz
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
43 """
44
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
45 type = property (lambda s: s.params.get('type'), lambda s,v: s.params.update({'type': v}))
46 app_dir = property (lambda s: s.params.get('app_dir'), lambda s,v: s.params.update({'app_dir': v}))
47 app_fetch = property (lambda s: s.params.get('app_fetch'), lambda s,v: s.params.update({'app_fetch': v}))
48 targz_path = property (lambda s: s.params.get('targz_path'), lambda s,v: s.params.update({'targz_path': v}))
49
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
50 def __init__ (self, app_info, params=None):
51 self.app_info = app_info
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
52
53 # Do not copy the params. We do want a child wizard to
54 # reference its parent params dict.
55 #
56 self.params = params or {}
57
58 #
59 # Public
60 #
61 def Check_Parameters (self):
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
62 return []
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
63
64 def Check_Prerequisites (self):
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
65 return []
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
66
15a3beb @alobbs WIP: Splits the 'Download_Unpack' phase
alobbs authored
67 def Download (self):
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
68 return []
15a3beb @alobbs WIP: Splits the 'Download_Unpack' phase
alobbs authored
69
70 def Unpack (self):
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
71 return []
72
73 def Check_PostUnpack (self):
74 return []
c52a392 @alobbs WIP: New download & unpack phase
alobbs authored
75
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
76 def Configure_Cherokee (self):
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
77 return []
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
78
2d16875 @alobbs Adds yet another installation logic stage
alobbs authored
79 def Configure_Cherokee_PostApply (self):
80 return []
81
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
82 #
a6a7fe9 @alobbs A number of fixed that fix the new Wordpress wizard.
alobbs authored
83 # Protected
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
84 #
85 def _Register_Child_Wizard (self, wizard_obj):
86 wizard_obj.params = self.params
87 return wizard_obj
88
89 def _Check_Params_Install_Type (self, allows_dir, allows_vserver):
90 errors = []
91
92 # Type
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
93 if not self.type:
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
94 errors += ["Missing 'type' property. Suitable values are: 'vserver' or 'directory'"]
95 return errors
96
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
97 if not self.type in ['directory', 'vserver']:
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
98 errors += ["Invalid 'type' value. It must be either 'vserver' or 'directory'"]
99 return errors
100
101 # Directory
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
102 if self.type == 'directory':
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
103 vserver_num = self.params.get('vserver_num')
7768a57 @alobbs WIP: Implements internal Virtual Server wizards support.
alobbs authored
104 directory = self.params.get('web_directory')
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
105
106 if not vserver_num:
107 errors += ["Property 'vserver_num' missing"]
108 elif not vserver_num.isdigit():
7768a57 @alobbs WIP: Implements internal Virtual Server wizards support.
alobbs authored
109 errors += ["Invalid value of the 'vserver_num' property: it must be a number"]
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
110
111 if not directory:
7768a57 @alobbs WIP: Implements internal Virtual Server wizards support.
alobbs authored
112 errors += ["Property 'web_directory' missing"]
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
113 elif directory[0] != '/':
7768a57 @alobbs WIP: Implements internal Virtual Server wizards support.
alobbs authored
114 errors += ["Invalid value of the 'web_directory' property: it must be a directory path"]
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
115
116 # Virtual Server
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
117 elif self.type == 'vserver':
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
118 vserver_nick = self.params.get('vserver_nick')
119 vserver_num = self.params.get('vserver_num')
120
121 if not vserver_nick:
122 errors += ["Property 'vserver_nick' missing"]
123
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
124 if vserver_num and CTK.cfg['vserver!%s'%(vserver_num)]:
125 errors += ["Invalid 'vserver_num'. Virtual server ID already in use."]
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
126 else:
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
127 self.params['vserver_num'] = CTK.cfg.get_next_entry_prefix ('vserver').split ('!')[-1]
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
128
129 return errors
130
131 def _Check_Software_Location (self):
132 errors = []
133
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
134 if self.app_fetch:
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
135 return []
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
136
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
137 if not self.app_dir:
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
138 errors += ["The 'app_dir' property must be provided"]
139
140 return errors
141
142 def _Handle_Download (self, tarball=None):
1d8039e @alobbs WIP: Checks if the tarball exists
alobbs authored
143 errors = []
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
144 url = None
145 pkg_path = None
146
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
147 # In case of running from the GUI, the file is downloaded by
148 # now, so the only thing left to do is to update the params.
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
149 if self.app_fetch and self.app_fetch.startswith ("http:"):
150 if CTK.DownloadEntry_Exists (self.app_fetch):
151 down_entry = CTK.DownloadEntry_Factory (self.app_fetch)
152 self.targz_path = down_entry.target_path
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
153 return []
154
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
155 # Auto
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
156 if not self.app_fetch or self.app_fetch == 'auto':
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
157 url = tarball
158
159 # Static file
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
160 elif self.app_fetch[0] == '/':
161 if not os.path.exists (self.app_fetch):
162 errors += [_("File or Directory not found: %(app_path)s") %({'app_path': self.app_fetch})]
1d8039e @alobbs WIP: Checks if the tarball exists
alobbs authored
163 return errors
164
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
165 if os.path.isdir(self.app_fetch):
166 self.targz_path = self.app_dir
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
167 else:
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
168 self.targz_path = self.app_fetch
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
169
170 # Download the software
171 else:
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
172 url = self.app_fetch
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
173
174 if url:
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
175 Install_Log.log ("Downloading: %s" %(url))
176
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
177 self.downloader = CTK.DownloadEntry_Factory (url)
178 self.downloader.start()
179
180 while self.downloader.isAlive():
181 self.downloader.join(1)
182 if self.downloader.size <= 0:
183 Install_Log.log ("Downloaded %d bytes..." %(self.downloader.downloaded))
184 else:
185 Install_Log.log ("Downloaded %d / %d (%d%%)..." %(self.downloader.downloaded, self.downloader.size, (self.downloader.downloaded * 100 / self.downloader.size)))
186
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
187 self.targz_path = self.downloader.target_path
188 Install_Log.log ("Download completed: %s" %(self.targz_path))
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
189
190 return []
191
192 def _Handle_Unpacking (self):
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
193 if not self.targz_path:
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
194 return []
195
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
196 assert self.app_dir
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
197
198 # Create the app directory
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
199 if not os.path.exists(self.app_dir):
200 os.makedirs (self.app_dir)
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
201
202 # Unpack
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
203 command = "gzip -dc '%s' | tar xfv -" %(self.targz_path)
204 Install_Log.log ("(cd: %s): %s" %(self.app_dir, command))
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
205
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
206 ret = popen.popen_sync (command, cd=self.app_dir)
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
207 Install_Log.log (ret['stdout'])
208 Install_Log.log (ret['stderr'])
209
210 return []
211
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
212 def _Update_app_dir (self, re_filter=None):
213 assert self.app_dir
214
215 for f in os.listdir (self.app_dir):
216 fp = os.path.join (self.app_dir, f)
217 if re_filter:
218 if not re.match (re_filter, f):
219 continue
220
221 Install_Log.log ("Updating app_dir: %s to %s" %(self.app_dir, fp))
222 self.app_dir = fp
223 return []
224
225 Install_Log.log ("app_dir was not updated: %s" %(self.app_dir))
226 return []
227
6909a6d @alobbs Implements Log config cloning.
alobbs authored
228 def _Handle_Log_VServer (self):
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
229 vserver_num = self.params.get('vserver_num')
230 cp_vsrv_log = self.params.get('cp_vsrv_log')
231
6909a6d @alobbs Implements Log config cloning.
alobbs authored
232 # For VServers only
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
233 if not self.type == 'vserver':
6909a6d @alobbs Implements Log config cloning.
alobbs authored
234 return []
235
236 # Log config cloning
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
237 if cp_vsrv_log:
6909a6d @alobbs Implements Log config cloning.
alobbs authored
238 vsrv_1st = CTK.cfg.get_lowest_entry ('vserver')
239
240 if CTK.cfg['vserver!%s!logger' %(vsrv_1st)]:
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
241 CTK.cfg.clone ('vserver!%s!logger' %(vsrv_1st), 'vserver!%s!logger' %(vserver_num))
6909a6d @alobbs Implements Log config cloning.
alobbs authored
242
243 if CTK.cfg['vserver!%s!error_writer'%(vsrv_1st)]:
42772bb @alobbs WIP: Internals, mostly related to the download from the GUI.
alobbs authored
244 CTK.cfg.clone ('vserver!%s!error_writer' %(vsrv_1st), 'vserver!%s!error_writer' %(vserver_num))
6909a6d @alobbs Implements Log config cloning.
alobbs authored
245
246 return []
247
248
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
249 #
250 # Checks
251 #
252 def _Check_File_Exists (self, filename):
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
253 assert self.app_dir
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
254 assert self.app_info and self.app_info.has_key('name')
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
255
256 errors = []
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
257 fpath = os.path.join (self.app_dir, filename)
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
258
259 if not os.path.exists (fpath):
260 errors += [_("The '%(app_dir)s' directory does not look like a %(name)s directory: The %(filename)s file is missing.")
c2d77f3 @alobbs WIP: Misc fixes and improvements
alobbs authored
261 %({'app_dir': self.app_dir, 'name': self.app_info['name'], 'filename': filename})]
1a9ad5a @alobbs WIP: Adds a new PostUnpack internal phase
alobbs authored
262
263 return errors
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
264
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
265 _modules = {}
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
266 def Load_Module (path):
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
267 global _modules
268 if not path in _modules:
269 tmp = path.split('/')
270 dsc = tmp[-1].replace('.py','')
f976980 @alobbs Wizards 2.0 - initial import
alobbs authored
271
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
272 php_mod_path = os.path.realpath (__file__ + '/../wizards/' + path)
273 _modules[path] = CTK.load_module_pyc (php_mod_path, dsc)
8ae6319 @alobbs WIP: Adds the first template, and works out the WP wizard prototype.
alobbs authored
274
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
275 return _modules[path]
276
277
278 _templates = {}
8ae6319 @alobbs WIP: Adds the first template, and works out the WP wizard prototype.
alobbs authored
279 def Load_Template (path):
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
280 global _templates
281 if not path in _templates:
282 tmp = path.split('/')
283 dsc = tmp[-1].replace('.py','')
284
285 php_mod_path = os.path.realpath (__file__ + '/../templates/' + path)
286 _templates[path] = CTK.load_module_pyc (php_mod_path, dsc)
8ae6319 @alobbs WIP: Adds the first template, and works out the WP wizard prototype.
alobbs authored
287
099effe @alobbs Some classes where failing to execute its __init__ method because a
alobbs authored
288 return _templates[path]
22c0a2f @alobbs WIP: 1.- Add properties to access the most common 'params'. 2.- Fixes
alobbs authored
289
Something went wrong with that request. Please try again.