Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP: Internals, mostly related to the download from the GUI.

git-svn-id: svn://cherokee-project.com/wizards2@6804 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
commit 42772bb1f7e8b14093e52f7bbec2a6b1da803231 1 parent 6e68182
Alvaro Lopez Ortega alobbs authored
117 Wizard2.py
View
@@ -29,18 +29,21 @@
class Wizard (object):
+ """
+ self.params
+ -----------
+ type : 'directory' or 'vserver'
+ vserver_num: 10, 20, ..
+ directory: /webdir
+ vserver_nick: example.com
+ app_fetch: /tmp/bat.tgz, http://_/foo.tgz
+ app_dir: /var/www_apps/worpress
+ targz_path: /tmp/foobar.tgz
+ """
+
def __init__ (self, name, params=None):
self.name = name or "Unnamed"
- self.type = None # 'directory' or 'vserver'
- self.vserver_num = None # 10, 20, ..
- self.directory = None # /webapp
- self.vserver_nick = None # example.com
- self.app_fetch = None # /tmp/bar.tgz or http://_/foo.tgz
- self.app_dir = None # /var/www_apps/wordpress
- self.downloader = None # CTK.Downloader object
- self.targz_path = None # /tmp/foobar.tgz
-
# Do not copy the params. We do want a child wizard to
# reference its parent params dict.
#
@@ -90,8 +93,6 @@ def _Check_Params_Install_Type (self, allows_dir, allows_vserver):
errors += ["Invalid 'type' value. It must be either 'vserver' or 'directory'"]
return errors
- self.type = tipe
-
# Directory
if tipe == 'directory':
vserver_num = self.params.get('vserver_num')
@@ -101,15 +102,11 @@ def _Check_Params_Install_Type (self, allows_dir, allows_vserver):
errors += ["Property 'vserver_num' missing"]
elif not vserver_num.isdigit():
errors += ["Invalid value of the 'directory' property: it must be a number"]
- else:
- self.vserver_num = vserver_num
if not directory:
errors += ["Property 'directory' missing"]
elif directory[0] != '/':
errors += ["Invalid value of the 'directory' property: it must be a directory path"]
- else:
- self.directory = directory
# Virtual Server
elif tipe == 'vserver':
@@ -118,26 +115,24 @@ def _Check_Params_Install_Type (self, allows_dir, allows_vserver):
if not vserver_nick:
errors += ["Property 'vserver_nick' missing"]
- else:
- self.vserver_nick = vserver_nick
- if vserver_num:
- errors += ["Property 'vserver_num' shouldn't be provided when creating a new virtual server"]
+ if vserver_num and CTK.cfg['vserver!%s'%(vserver_num)]:
+ errors += ["Invalid 'vserver_num'. Virtual server ID already in use."]
else:
- self.vserver_num = CTK.cfg.get_next_entry_prefix ('vserver').split ('!')[-1]
+ self.params['vserver_num'] = CTK.cfg.get_next_entry_prefix ('vserver').split ('!')[-1]
return errors
def _Check_Software_Location (self):
errors = []
- self.app_dir = self.params.get('app_dir')
- self.app_fetch = self.params.get('app_fetch')
+ app_dir = self.params.get('app_dir')
+ app_fetch = self.params.get('app_fetch')
- if self.app_fetch:
- return errors
+ if app_fetch:
+ return []
- if not self.app_dir:
+ if not app_dir:
errors += ["The 'app_dir' property must be provided"]
return errors
@@ -147,24 +142,36 @@ def _Handle_Download (self, tarball=None):
url = None
pkg_path = None
+ app_dir = self.params.get('app_dir')
+ app_fetch = self.params.get('app_fetch', '')
+ targz_path = self.params.get('targz_path')
+
+ # In case of running from the GUI, the file is downloaded by
+ # now, so the only thing left to do is to update the params.
+ if app_fetch.startswith ("http:"):
+ if CTK.DownloadEntry_Exists (app_fetch):
+ down_entry = CTK.DownloadEntry_Factory (app_fetch)
+ self.params['targz_path'] = down_entry.target_path
+ return []
+
# Auto
- if not self.app_fetch or self.app_fetch == 'auto':
+ if not app_fetch or app_fetch == 'auto':
url = tarball
# Static file
- elif self.app_fetch[0] == '/':
- if not os.path.exists (self.app_fetch):
- errors += [_("File or Directory not found: %(app_path)s") %({'app_path': self.app_fetch})]
+ elif app_fetch[0] == '/':
+ if not os.path.exists (app_fetch):
+ errors += [_("File or Directory not found: %(app_path)s") %({'app_path': app_fetch})]
return errors
- if os.path.isdir(self.app_fetch):
- self.targz_path = self.app_dir
+ if os.path.isdir(app_fetch):
+ self.params['targz_path'] = app_dir
else:
- self.targz_path = self.app_fetch
+ self.params['targz_path'] = app_fetch
# Download the software
else:
- url = self.app_fetch
+ url = self.params['app_fetch']
if url:
self.downloader = CTK.DownloadEntry_Factory (url)
@@ -177,46 +184,52 @@ def _Handle_Download (self, tarball=None):
else:
Install_Log.log ("Downloaded %d / %d (%d%%)..." %(self.downloader.downloaded, self.downloader.size, (self.downloader.downloaded * 100 / self.downloader.size)))
- self.targz_path = self.downloader.target_path
- Install_Log.log ("Download completed: %s" %(self.targz_path))
+ self.params['targz_path'] = self.downloader.target_path
+ Install_Log.log ("Download completed: %s" %(self.params['targz_path']))
return []
def _Handle_Unpacking (self):
- if not self.targz_path:
- return
+ app_dir = self.params.get('app_dir')
+ targz_path = self.params.get('targz_path')
- assert self.app_dir
+ if not targz_path:
+ return []
+
+ assert app_dir
# Create the app directory
- if not os.path.exists(self.app_dir):
- os.makedirs (self.app_dir)
+ if not os.path.exists(app_dir):
+ os.makedirs (app_dir)
# Unpack
- command = "gzip -dc '%s' | tar xfv -" %(self.targz_path)
- Install_Log.log ("(cd: %s): %s" %(self.app_dir, command))
+ command = "gzip -dc '%s' | tar xfv -" %(targz_path)
+ Install_Log.log ("(cd: %s): %s" %(app_dir, command))
- ret = popen.popen_sync (command, cd=self.app_dir)
+ ret = popen.popen_sync (command, cd=app_dir)
Install_Log.log (ret['stdout'])
Install_Log.log (ret['stderr'])
return []
def _Handle_Log_VServer (self):
+ tipe = self.params.get('type')
+ vserver_num = self.params.get('vserver_num')
+ cp_vsrv_log = self.params.get('cp_vsrv_log')
+
# For VServers only
- if not self.type == 'vserver':
+ if not tipe == 'vserver':
return []
# Log config cloning
- cp_vserver_log = self.params.get ('cp_vsrv_log')
- if cp_vserver_log:
+ if cp_vsrv_log:
vsrv_1st = CTK.cfg.get_lowest_entry ('vserver')
if CTK.cfg['vserver!%s!logger' %(vsrv_1st)]:
- CTK.cfg.clone ('vserver!%s!logger' %(vsrv_1st), 'vserver!%s!logger' %(self.vserver_num))
+ CTK.cfg.clone ('vserver!%s!logger' %(vsrv_1st), 'vserver!%s!logger' %(vserver_num))
if CTK.cfg['vserver!%s!error_writer'%(vsrv_1st)]:
- CTK.cfg.clone ('vserver!%s!error_writer' %(vsrv_1st), 'vserver!%s!error_writer' %(self.vserver_num))
+ CTK.cfg.clone ('vserver!%s!error_writer' %(vsrv_1st), 'vserver!%s!error_writer' %(vserver_num))
return []
@@ -225,15 +238,17 @@ def _Handle_Log_VServer (self):
# Checks
#
def _Check_File_Exists (self, filename):
- assert self.app_dir
+ app_dir = self.params.get('app_dir')
+
+ assert app_dir
assert self.name
errors = []
- fpath = os.path.join (self.app_dir, filename)
+ fpath = os.path.join (app_dir, filename)
if not os.path.exists (fpath):
errors += [_("The '%(app_dir)s' directory does not look like a %(name)s directory: The %(filename)s file is missing.")
- %({'app_dir': self.app_dir, 'name': self.name, 'filename': filename})]
+ %({'app_dir': app_dir, 'name': self.name, 'filename': filename})]
return errors
75 Wizard2_GUI.py
View
@@ -194,8 +194,9 @@ def __build_GUI__ (self):
]
class Stage_Install_Type (Phase_PrevNext):
- def __init__ (self):
+ def __init__ (self, default_download_URL):
Phase_PrevNext.__init__ (self, _("Software Retrival Method"))
+ self.default_URL = default_download_URL
def __build_GUI__ (self):
# Refresh
@@ -235,7 +236,7 @@ def __init__ (self, refresh, parent_widget):
method = CTK.cfg.get_val ('%s!install_type'%(CFG_PREFIX), default)
if method == 'download_auto':
- None
+ self += pself.Download_Auto (pself)
elif method == 'download_URL':
self += pself.Download_URL (refresh)
elif method == 'local_directory':
@@ -243,6 +244,18 @@ def __init__ (self, refresh, parent_widget):
else:
self += CTK.RawHTML ('<h1>%s</h1>' %(_("Unknown method")))
+ class Download_Auto (CTK.Box):
+ def __init__ (self, pself):
+ CTK.Box.__init__ (self)
+
+ submit = CTK.Submitter (URL_STAGE_INSTALL_AUTO_APPLY)
+ submit += CTK.Hidden ('%s!app_fetch'%(CFG_PREFIX), pself.default_URL)
+ self += submit
+
+ class Apply:
+ def __call__ (self):
+ return CTK.cfg_apply_post()
+
class Download_URL (CTK.Box):
def __init__ (self, refresh):
CTK.Box.__init__ (self)
@@ -306,10 +319,12 @@ def validation_download_url (value):
]
URL_STAGE_INSTALL_APPLY = "/wizard2/stages/install_type/apply"
+URL_STAGE_INSTALL_AUTO_APPLY = "/wizard2/stages/install_type/auto/apply"
URL_STAGE_INSTALL_URL_APPLY = "/wizard2/stages/install_type/url/apply"
URL_STAGE_INSTALL_LOCAL_APPLY = "/wizard2/stages/install_type/local_dir/apply"
CTK.publish ('^%s'%(URL_STAGE_INSTALL_APPLY), Stage_Install_Type.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
+CTK.publish ('^%s'%(URL_STAGE_INSTALL_AUTO_APPLY), Stage_Install_Type.Download_Auto.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
CTK.publish ('^%s'%(URL_STAGE_INSTALL_URL_APPLY), Stage_Install_Type.Download_URL.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
CTK.publish ('^%s'%(URL_STAGE_INSTALL_LOCAL_APPLY), Stage_Install_Type.Local_Directory.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
@@ -399,9 +414,52 @@ def __init__ (self, refresh):
CTK.publish ('^%s'%(URL_STAGE_INSTALL_DIR_APPLY), Stage_Install_Directory.Apply, validation=VALIDATION_INSTALL_DIR_TYPE, method="POST")
+#
+# Download
+#
+
+class Stage_Download (Phase_Cancel):
+ def __init__ (self):
+ Phase_Cancel.__init__ (self, _("Downloading"))
+
+ def __build_GUI__ (self):
+ app_fetch = CTK.cfg.get_val ('%s!app_fetch'%(CFG_PREFIX))
+ skip = False
+
+ # Special cases
+ if not app_fetch:
+ skip = True
+
+ if not app_fetch.startswith('http'):
+ skip = True
+
+ # (app_fetch != 'auto')):
+
+
+ # Skip the phase?
+ if skip:
+ self += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto_next (self.id))
+ return
+
+ # Report
+ report = CTK.Box()
+ report += CTK.RawHTML (_("Initiating download.."))
+
+ # Download widget
+ down = CTK.Downloader ('package', app_fetch)
+ down.bind ('finished', CTK.DruidContent__JS_to_goto_next (self.id))
+ down.bind ('stopped', "") ## TODO!!
+ down.bind ('error', "") ## TODO!!
+ down.bind ('update', "$('#%s').html('Downloaded: ' + (event.downloaded / 1024).toFixed() + ' Kb');"%(report.id))
+
+ self += CTK.RawHTML ('<p>%s</p>' %(_('The application is being downloaded. Hold on tight!')))
+ self += down
+ self += report
+ self += CTK.RawHTML (js = down.JS_to_start())
+
#
-# Select Install Type
+# Installation
#
def collect_arguments (installer_params):
@@ -546,19 +604,20 @@ def __build_GUI__ (self):
# Helpers
#
-def Register_Standard_VServer_GUI (wizard_name, Install_Class):
+def Register_Standard_VServer_GUI (wizard_name, Install_Class, default_download_URL):
wizard_url_name = wizard_name.lower().replace(' ', '_')
url_srv = '/wizard/vserver/%s' %(wizard_url_name)
CTK.publish ('^%s$' %(url_srv), lambda: Phase_Welcome (wizard_name, 'vserver').Render().toStr())
- CTK.publish ('^%s/2$'%(url_srv), Stage_Install_Type)
+ CTK.publish ('^%s/2$'%(url_srv), lambda: Stage_Install_Type (default_download_URL).Render().toStr())
CTK.publish ('^%s/3$'%(url_srv), Stage_Install_Directory)
CTK.publish ('^%s/4$'%(url_srv), Stage_Enter_VServer)
CTK.publish ('^%s/5$'%(url_srv), Stage_VServer_Logging)
- CTK.publish ('^%s/6$'%(url_srv), lambda: Stage_Do_Install (Install_Class, "%s/7"%(url_srv)).Render().toStr())
- CTK.publish ('^%s/7$'%(url_srv), Stage_Finished)
+ CTK.publish ('^%s/6$'%(url_srv), Stage_Download)
+ CTK.publish ('^%s/7$'%(url_srv), lambda: Stage_Do_Install (Install_Class, "%s/8"%(url_srv)).Render().toStr())
+ CTK.publish ('^%s/8$'%(url_srv), Stage_Finished)
-def Register_Standard_Directory_GUI (wizard_name, Install_Class):
+def Register_Standard_Directory_GUI (wizard_name, Install_Class, default_download_URL):
None
def Register_Standard_GUI (*args, **kw):
20 templates/PHP.py
View
@@ -38,11 +38,10 @@
class Install (Wizard2.Wizard):
- def __init__ (self, app_name, config_vserver, config_directory, tarball_url, params):
+ def __init__ (self, app_name, config_vserver, config_directory, params):
self._app_name = app_name
self._config_vserver = config_vserver
self._config_directory = config_directory
- self._tarball_url = tarball_url
# Base
Wizard2.Wizard.__init__ (self, app_name, params)
@@ -71,24 +70,25 @@ def Check_Prerequisites (self):
return []
def Download (self):
- errors = self._Handle_Download (tarball = self._tarball_url)
- return errors or []
+ app_fetch = self.params.get('app_fetch')
+ return self._Handle_Download (tarball = app_fetch)
def Unpack (self):
- errors = self._Handle_Unpacking ()
- return errors or []
+ return self._Handle_Unpacking ()
def Configure_Cherokee (self):
+ tipe = self.params['type']
+
# PHP
errors = self.php.Configure_Cherokee()
if errors: return errors
# Collect substitutions
self.cfg_replacements = cfg_get_surrounding_repls ('pre_rule', self.php.rule)
- self.cfg_replacements.update (self.__dict__)
+ self.cfg_replacements.update (self.params)
# Wordpress
- if self.type == 'directory':
+ if tipe == 'directory':
# Apply the configuration
config = self._config_directory %(self.cfg_replacements)
CTK.cfg.apply_chunk (config)
@@ -97,7 +97,7 @@ def Configure_Cherokee (self):
errors = self.Configure_Cherokee_PostApply ()
if errors: return errors
- elif self.type == 'vserver':
+ elif tipe == 'vserver':
# Apply the configuration
config = self._config_vserver %(self.cfg_replacements)
CTK.cfg.apply_chunk (config)
@@ -107,7 +107,7 @@ def Configure_Cherokee (self):
if errors: return errors
# Normalize rules
- CTK.cfg.normalize ('vserver!%s!rule'%(self.vserver_num))
+ CTK.cfg.normalize ('vserver!%s!rule'%(self.params['vserver_num']))
# Logging config
errors = self._Handle_Log_VServer()
2  wizards/01-Development Platforms/php-fpm.py
View
@@ -78,7 +78,7 @@ def Check_Prerequisites (self):
return ["Could not locate the php-fpm binary"]
def Configure_Cherokee (self):
- pre = 'vserver!%s' %(self.vserver_num)
+ pre = 'vserver!%s' %(self.params['vserver_num'])
# Gather information
self.source = _find_source()
7 wizards/02-Content Management Systems/wordpress.py
View
@@ -106,7 +106,6 @@ def __init__ (self, params):
app_name = "Wordpress",
config_vserver = CONFIG_VSERVER,
config_directory = CONFIG_DIR,
- tarball_url = TARBALL,
params = params)
def Check_Prerequisites (self):
@@ -119,13 +118,13 @@ def _Handle_Unpacking (self):
if errors: return errors
# Update app_dir, WP is in a subdir
- self.app_dir = os.path.join (self.app_dir, "wordpress")
+ self.params['app_dir'] = os.path.join (self.params['app_dir'], "wordpress")
def Check_PostUnpack (self):
return self._Check_File_Exists ('wp-comments-post.php')
def Configure_Cherokee_PostApply (self):
- if self.type == 'vserver':
+ if self.params['type'] == 'vserver':
vserver.Add_Usual_Static_Files (self.cfg_replacements['pre_rule_plus1'])
@@ -133,4 +132,4 @@ def Configure_Cherokee_PostApply (self):
# GUI
#
-GUI.Register_Standard_GUI ('Wordpress', Install)
+GUI.Register_Standard_GUI ('Wordpress', Install, TARBALL)
Please sign in to comment.
Something went wrong with that request. Please try again.