def __safe_call__ (self): app_id = CTK.cfg.get_val('tmp!market!install!app!application_id') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') info = {'cherokee_version': VERSION, 'system': SystemInfo.get_info()} xmlrpc = XmlRpcServer (OWS_APPS_INSTALL, user=OWS_Login.login_user, password=OWS_Login.login_password) install_info = xmlrpc.get_install_info (app_id, info) Install_Log.log ("Waiting for the payment acknowledge…") box = CTK.Box() if install_info.get('due_payment'): set_timeout_js = "setTimeout (reload_druid, %s);" %(PAYMENT_CHECK_TIMEOUT) box += CTK.RawHTML ("<h2>%s %s</h2>"%(_('Checking out'), app_name)) box += CTK.RawHTML ('<h1>%s</h1>' %(_("Waiting for the payment acknowledge…"))) box += CTK.RawHTML (js="function reload_druid() {%s %s}" %(CTK.DruidContent__JS_to_goto (box.id, URL_INSTALL_PAY_CHECK), set_timeout_js)) box += CTK.RawHTML (js=set_timeout_js) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) box += buttons else: Install_Log.log ("Payment ACK!") # Invalidate 'My Library' cache MyLibrary.Invalidate_Cache() # Move on CTK.cfg['tmp!market!install!download'] = install_info['url'] box += CTK.DruidContent__JS_to_goto (box.id, URL_INSTALL_DOWNLOAD) return box.Render().toStr()
def __safe_call__(self): app_id = CTK.cfg.get_val("tmp!market!install!app!application_id") app_name = CTK.cfg.get_val("tmp!market!install!app!application_name") # URL Package index = Distro.Index() pkg = index.get_package(app_id, "package") repo_url = CTK.cfg.get_val("admin!ows!repository", REPO_MAIN) url_download = os.path.join(repo_url, app_id, pkg["filename"]) CTK.cfg["tmp!market!install!download"] = url_download # Local storage shortcut pkg_filename_full = url_download.split("/")[-1] pkg_filename = pkg_filename_full.split("_")[0] pkg_revision = 0 pkg_repo_fp = os.path.join(CHEROKEE_OWS_DIR, "packages", app_id) if os.access(pkg_repo_fp, os.X_OK): for f in os.listdir(pkg_repo_fp): tmp = re.findall("^%s_(\d+)" % (pkg_filename), f) if tmp: pkg_revision = max(pkg_revision, int(tmp[0])) if pkg_revision > 0: pkg_fullpath = os.path.join( CHEROKEE_OWS_DIR, "packages", app_id, "%s_%d.cpk" % (pkg_filename, pkg_revision) ) CTK.cfg["tmp!market!install!local_package"] = pkg_fullpath Install_Log.log("Using local repository package: %s" % (pkg_fullpath)) box = CTK.Box() box += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto(box.id, URL_INSTALL_SETUP)) return box.Render().toStr() # Instance a Downloader downloader = CTK.Downloader("package", url_download) downloader.bind("stopped", CTK.DruidContent__JS_to_close(downloader.id)) downloader.bind("finished", CTK.DruidContent__JS_to_goto(downloader.id, URL_INSTALL_SETUP)) downloader.bind("error", CTK.DruidContent__JS_to_goto(downloader.id, URL_INSTALL_DOWNLOAD_ERROR)) stop = CTK.Button(_("Cancel")) stop.bind("click", downloader.JS_to_stop()) buttons = CTK.DruidButtonsPanel() buttons += stop Install_Log.log("Downloading %s" % (url_download)) cont = CTK.Container() cont += CTK.RawHTML("<h2>%s %s</h2>" % (_("Installing"), app_name)) cont += CTK.RawHTML("<p>%s</p>" % (_("The application is being downloaded. Hold on tight!"))) cont += downloader cont += buttons cont += CTK.RawHTML(js=downloader.JS_to_start()) return cont.Render().toStr()
def __safe_call__ (self): app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') Install_Log.log ("Set-up Error") box = CTK.Box() box += CKT.RawHTML ("<h2>%s</h2>" %(_("Setting up"), app_name)) box += CKT.RawHTML ("<h1>%s</h1>" %(_("Unpacking application…"))) box += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto (box.id, URL_INSTALL_SETUP)) return box.Render().toStr()
def Render (self): # Add replacement keys to the log for k in self.keys: Install_Log.log (" ${%s} -> '%s'" %(k, self.keys[k])) # Start thread self.thread.start() # Render return CTK.Box.Render (self)
def __safe_call__(self): Install_Log.log("Setup phase") app_name = CTK.cfg.get_val("tmp!market!install!app!application_name") box = CTK.Box() box += CTK.RawHTML("<h2>%s %s</h2>" % (_("Installing"), app_name)) box += CTK.RawHTML("<h1>%s</h1>" % (_("Unpacking application…"))) # Unpack commands = [({"function": _Setup_unpack, "description": _("The applicaction is being unpacked…")})] progress = CommandProgress.CommandProgress(commands, URL_INSTALL_POST_UNPACK, props={"style": "display:none;"}) box += progress return box.Render().toStr()
def __safe_call__ (self): app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') Install_Log.log ("Downloading Error: %s" %(url_download)) cont = CTK.Container() cont += CTK.RawHTML ('<h2>%s %s</h2>' %(_("Installing"), app_name)) cont += CTK.RawHTML (_("There was an error downloading the application. Please contact us if the problem persists.")) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) cont += buttons return cont.Render().toStr()
def _Handle_Download(self, tarball=None): errors = [] url = None pkg_path = None # 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 self.app_fetch and self.app_fetch.startswith("http:"): if CTK.DownloadEntry_Exists(self.app_fetch): down_entry = CTK.DownloadEntry_Factory(self.app_fetch) self.targz_path = down_entry.target_path return [] # Auto if not self.app_fetch or self.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 }) ] return errors if os.path.isdir(self.app_fetch): self.targz_path = self.app_dir else: self.targz_path = self.app_fetch # Download the software else: url = self.app_fetch if url: Install_Log.log("Downloading: %s" % (url)) self.downloader = CTK.DownloadEntry_Factory(url) self.downloader.start() while self.downloader.isAlive(): self.downloader.join(1) if self.downloader.size <= 0: Install_Log.log("Downloaded %d bytes..." % (self.downloader.downloaded)) 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)) return []
def _Update_app_dir(self, re_filter=None): assert self.app_dir for f in os.listdir(self.app_dir): fp = os.path.join(self.app_dir, f) if re_filter: if not re.match(re_filter, f): continue Install_Log.log("Updating app_dir: %s to %s" % (self.app_dir, fp)) self.app_dir = fp return [] Install_Log.log("app_dir was not updated: %s" % (self.app_dir)) return []
def __call__(self): try: return self.__safe_call__() except Exception, e: # Log the exception exception_str = traceback.format_exc() print exception_str Install_Log.log("EXCEPTION!\n" + exception_str) # Reset 'unfinished installations' cache Maintenance.Invalidate_Cache() # Present an alternative response cont = Exception_Handler(exception_str) return cont.Render().toStr()
def __safe_call__ (self): app_id = CTK.cfg.get_val('tmp!market!install!app!application_id') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') url_download = CTK.cfg.get_val('tmp!market!install!download') # Local storage shortcut pkg_filename_full = url_download.split('/')[-1] pkg_filename = pkg_filename_full.split('_')[0] pkg_revision = 0 pkg_repo_fp = os.path.join (CHEROKEE_OWS_DIR, "packages") if os.access (pkg_repo_fp, os.X_OK): for f in os.listdir (pkg_repo_fp): tmp = re.findall('^%s_(\d+)'%(pkg_filename), f) if tmp: pkg_revision = max (pkg_revision, int(tmp[0])) if pkg_revision > 0: pkg_fullpath = os.path.join (CHEROKEE_OWS_DIR, "packages", '%s_%d.pkg' %(pkg_filename, pkg_revision)) CTK.cfg['tmp!market!install!local_package'] = pkg_fullpath Install_Log.log ("Using local repository package: %s" %(pkg_fullpath)) box = CTK.Box() box += CTK.RawHTML (js=CTK.DruidContent__JS_to_goto (box.id, URL_INSTALL_SETUP)) return box.Render().toStr() # Instance a Downloader downloader = CTK.Downloader ('package', url_download) downloader.bind ('stopped', CTK.DruidContent__JS_to_close (downloader.id)) downloader.bind ('finished', CTK.DruidContent__JS_to_goto (downloader.id, URL_INSTALL_SETUP)) downloader.bind ('error', CTK.DruidContent__JS_to_goto (downloader.id, URL_INSTALL_DOWNLOAD_ERROR)) stop = CTK.Button (_('Cancel')) stop.bind ('click', downloader.JS_to_stop()) buttons = CTK.DruidButtonsPanel() buttons += stop Install_Log.log ("Downloading %s" %(url_download)) cont = CTK.Container() cont += CTK.RawHTML ('<h2>%s %s</h2>' %(_("Downloading"), app_name)) cont += CTK.RawHTML ('<p>%s</p>' %(_('The application is being downloaded. Hold on tight!'))) cont += downloader cont += buttons cont += CTK.RawHTML (js = downloader.JS_to_start()) return cont.Render().toStr()
def __safe_call__ (self): app_id = CTK.cfg.get_val('tmp!market!install!app!application_id') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') info = {'cherokee_version': VERSION, 'system': SystemInfo.get_info()} cont = CTK.Box() xmlrpc = XmlRpcServer (OWS_APPS_INSTALL, user=OWS_Login.login_user, password=OWS_Login.login_password) install_info = xmlrpc.get_install_info (app_id, info) if install_info.get('error'): title = install_info['error']['error_title'] errors = install_info['error']['error_strings'] cont += CTK.RawHTML ("<h2>%s</h2>"%(_(title))) for error in errors: cont += CTK.RawHTML ("<p>%s</p>"%(_(error))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Close')) cont += buttons elif install_info['installable']: # Do not change this log line. It is used by the # Maintenance.py file to figure out the app name Install_Log.log ("Checking: %s, ID: %s = Installable, URL=%s" %(app_name, app_id, install_info['url'])) CTK.cfg['tmp!market!install!download'] = install_info['url'] cont += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto (cont.id, URL_INSTALL_DOWNLOAD)) else: Install_Log.log ("Checking: %s, ID: %s = Must check out first" %(app_name, app_id)) cont += CTK.RawHTML ("<h2>%s %s</h2>"%(_('Checking out'), app_name)) cont += CTK.RawHTML ("<p>%s</p>" %(_(NOTE_ALL_READY_TO_BUY_1))) cont += CTK.RawHTML ("<p>%s</p>" %(_(NOTE_ALL_READY_TO_BUY_2))) checkout = CTK.Button (_("Check Out")) checkout.bind ('click', CTK.DruidContent__JS_to_goto (cont.id, URL_INSTALL_PAY_CHECK) + CTK.JS.OpenWindow('%s/order/%s' %(OWS_STATIC, app_id))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) buttons += checkout cont += buttons return cont.Render().toStr()
def __safe_call__(self): app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') Install_Log.log("Downloading Error: %s" % (url_download)) cont = CTK.Container() cont += CTK.RawHTML('<h2>%s %s</h2>' % (_("Installing"), app_name)) cont += CTK.RawHTML( _("There was an error downloading the application. Please contact us if the problem persists." )) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) cont += buttons return cont.Render().toStr()
def __safe_call__(self): Install_Log.log("Setup phase") app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') box = CTK.Box() box += CTK.RawHTML("<h2>%s %s</h2>" % (_("Installing"), app_name)) box += CTK.RawHTML("<h1>%s</h1>" % (_("Unpacking application…"))) # Unpack commands = [({ 'function': _Setup_unpack, 'description': _("The applicaction is being unpacked…") })] progress = CommandProgress.CommandProgress( commands, URL_INSTALL_POST_UNPACK, props={'style': 'display:none;'}) box += progress return box.Render().toStr()
def _run_function (self, command_entry): function = command_entry['function'] params = command_entry.get ('params', {}).copy() Install_Log.log (" Function: %s" %(function.__name__)) if params: Install_Log.log (" (PARAMS) -> %s" %(str(params))) try: ret = function (**params) except: ret = {'retcode': 1, 'stderr': traceback.format_exc()} self.command_progress.last_popen_ret = ret if command_entry.get ('check_ret', True): if ret['retcode'] != 0: self._report_error (function.__name__, params, ret) return True
def __safe_call__(self): Install_Log.log("Post unpack commands") target_path = CTK.cfg.get_val("tmp!market!install!root") app_name = CTK.cfg.get_val("tmp!market!install!app!application_name") # Import the Installation handler if os.path.exists(os.path.join(target_path, "installer.py")): Install_Log.log("Passing control to installer.py") installer_path = os.path.join(target_path, "installer.py") pkg_installer = imp.load_source("installer", installer_path) else: Install_Log.log("Passing control to installer.pyo") installer_path = os.path.join(target_path, "installer.pyo") pkg_installer = imp.load_compiled("installer", installer_path) # GUI box = CTK.Box() commands = pkg_installer.__dict__.get("POST_UNPACK_COMMANDS", []) if not commands: box += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto(box.id, URL_INSTALL_SETUP_EXTERNAL)) return box.Render().toStr() box += CTK.RawHTML("<h2>%s %s</h2>" % (_("Installing"), app_name)) box += CTK.RawHTML("<p>%s</p>" % (_("Setting it up…"))) progress = CommandProgress.CommandProgress(commands, URL_INSTALL_SETUP_EXTERNAL) box += progress return box.Render().toStr()
def __safe_call__(self): Install_Log.log("Post unpack commands") target_path = CTK.cfg.get_val('tmp!market!install!root') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') # Import the Installation handler if os.path.exists(os.path.join(target_path, "installer.py")): Install_Log.log("Passing control to installer.py") installer_path = os.path.join(target_path, "installer.py") pkg_installer = imp.load_source('installer', installer_path) else: Install_Log.log("Passing control to installer.pyo") installer_path = os.path.join(target_path, "installer.pyo") pkg_installer = imp.load_compiled('installer', installer_path) # GUI box = CTK.Box() commands = pkg_installer.__dict__.get('POST_UNPACK_COMMANDS', []) if not commands: box += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto( box.id, URL_INSTALL_SETUP_EXTERNAL)) return box.Render().toStr() box += CTK.RawHTML("<h2>%s %s</h2>" % (_("Installing"), app_name)) box += CTK.RawHTML("<p>%s</p>" % (_("Setting it up…"))) progress = CommandProgress.CommandProgress(commands, URL_INSTALL_SETUP_EXTERNAL) box += progress return box.Render().toStr()
def __safe_call__ (self): root = CTK.cfg.get_val('tmp!market!install!root') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') cfg_changes = CTK.cfg.get_val('tmp!market!install!cfg_previous_changes') box = CTK.Box() # Finished finished_file = os.path.join (root, "finished") Install_Log.log ("Creating %s" %(finished_file)) f = open (finished_file, 'w+') f.close() # Normalize CTK.cfg CTK.cfg.normalize ('vserver') # Clean up CTK.cfg for k in CTK.cfg.keys('tmp!market!install'): if k != 'app': del (CTK.cfg['tmp!market!install!%s'%(k)]) # Save configuration if not int(cfg_changes): CTK.cfg.save() Install_Log.log ("Configuration saved.") Cherokee.server.restart (graceful=True) Install_Log.log ("Server gracefully restarted.") box += CTK.RawHTML (js=SaveButton.ButtonSave__JS_to_deactive()) Install_Log.log ("Finished") # Thank user for the install box += CTK.RawHTML ('<h2>%s %s</h2>' %(app_name, _("has been installed successfully"))) box += CTK.RawHTML ("<p>%s</p>" %(_(NOTE_THANKS_P1))) if int(cfg_changes): box += CTK.RawHTML ("<p>%s</p>" %(_(NOTE_SAVE_RESTART))) box += CTK.RawHTML ("<h1>%s</h1>" %(_(NOTE_THANKS_P2))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Close')) box += buttons return box.Render().toStr()
def _run_command (self, command_entry): command = self._replace (command_entry['command']) cd = command_entry.get('cd') env = command_entry.get('env') su = command_entry.get('su') if cd: cd = self._replace (cd) Install_Log.log (" %s" %(command)) if env: Install_Log.log (" (CD) -> %s" %(cd)) Install_Log.log (" (SU) -> %s" %(su)) Install_Log.log (" (CUSTOM ENV) -> %s" %(str(env))) ret = popen.popen_sync (command, env=env, cd=cd, su=su) self.command_progress.last_popen_ret = ret if command_entry.get ('check_ret', True): if ret['retcode'] != 0: self._report_error (command, env, ret, cd) return True
def _run_command (self, command_entry): command = replacement_cmd (command_entry['command']) cd = command_entry.get('cd') env = command_entry.get('env') su = command_entry.get('su') if cd: cd = replacement_cmd (cd) Install_Log.log (" %s" %(command)) if env: Install_Log.log (" (CD) -> %s" %(cd)) Install_Log.log (" (SU) -> %s" %(su)) Install_Log.log (" (CUSTOM ENV) -> %s" %(str(env))) ret = popen.popen_sync (command, env=env, cd=cd, su=su) self.command_progress.last_popen_ret = ret if command_entry.get ('check_ret', True): if ret['retcode'] != 0: self._report_error (command, env, ret) return True
def _Handle_Unpacking(self): if not self.targz_path: return [] assert self.app_dir # Create the app directory if not os.path.exists(self.app_dir): os.makedirs(self.app_dir) # Unpack command = "gzip -dc '%s' | tar xfv -" % (self.targz_path) Install_Log.log("(cd: %s): %s" % (self.app_dir, command)) ret = popen.popen_sync(command, cd=self.app_dir) Install_Log.log(ret['stdout']) Install_Log.log(ret['stderr']) return []
def __safe_call__(self): root = CTK.cfg.get_val("tmp!market!install!root") app_name = CTK.cfg.get_val("tmp!market!install!app!application_name") cfg_changes = CTK.cfg.get_val("tmp!market!install!cfg_previous_changes") # Finished finished_file = os.path.join(root, "finished") Install_Log.log("Creating %s" % (finished_file)) f = open(finished_file, "w+") f.close() # Normalize CTK.cfg CTK.cfg.normalize("vserver") # Save configuration box = CTK.Box() if not int(cfg_changes): CTK.cfg.save() Install_Log.log("Configuration saved.") Cherokee.server.restart(graceful=True) Install_Log.log("Server gracefully restarted.") box += CTK.RawHTML(js=SaveButton.ButtonSave__JS_to_deactive()) Install_Log.log("Finished") # Thank user for the install box += CTK.RawHTML("<h2>%s %s</h2>" % (app_name, _("has been installed successfully"))) box += CTK.RawHTML("<p>%s</p>" % (_(NOTE_THANKS_P1))) # Save / Visit if int(cfg_changes): box += CTK.Notice("information", CTK.RawHTML(_(NOTE_SAVE_RESTART))) elif Cherokee.server.is_alive(): install_type = CTK.cfg.get_val("tmp!market!install!target") nick = CTK.cfg.get_val("tmp!market!install!target!vserver") vserver_n = CTK.cfg.get_val("tmp!market!install!target!vserver_n") directory = CTK.cfg.get_val("tmp!market!install!target!directory") # Host if vserver_n and not nick: nick = CTK.cfg.get_val("vserver!%s!nick" % (vserver_n)) if not nick or nick.lower() == "default": sys_stats = SystemStats.get_system_stats() nick = sys_stats.hostname # Ports ports = [] for b in CTK.cfg["server!bind"] or []: port = CTK.cfg.get_val("server!bind!%s!port" % (b)) if port: ports.append(port) nick_port = nick if ports and not "80" in ports: nick_port = "%s:%s" % (nick, ports[0]) # URL url = "" if install_type == "vserver" and nick: url = "http://%s/" % (nick_port) elif install_type == "directory" and vserver_n and directory: nick = CTK.cfg.get_val("vserver!%s!nick" % (vserver_n)) url = "http://%s%s/" % (nick_port, directory) if url: box += CTK.RawHTML("<p>%s " % (_("You can now visit"))) box += CTK.LinkWindow(url, CTK.RawHTML(_("your new application"))) box += CTK.RawHTML(" on a new window.</p>") box += CTK.RawHTML("<h1>%s</h1>" % (_(NOTE_THANKS_P2))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_("Close")) box += buttons # Clean up CTK.cfg for k in CTK.cfg.keys("tmp!market!install"): if k != "app": del (CTK.cfg["tmp!market!install!%s" % (k)]) return box.Render().toStr()
def _Setup_unpack(): url_download = CTK.cfg.get_val('tmp!market!install!download') # has it been downloaded? pkg_filename = url_download.split('/')[-1] package_path = CTK.cfg.get_val('tmp!market!install!local_package') if not package_path or not os.path.exists(package_path): down_entry = CTK.DownloadEntry_Factory(url_download) package_path = down_entry.target_path # Create the local directory target_path = os.path.join(CHEROKEE_OWS_ROOT, str(int(time.time() * 100))) os.mkdir(target_path, 0700) CTK.cfg['tmp!market!install!root'] = target_path # Create the log file Install_Log.set_file(os.path.join(target_path, "install.log")) # Uncompress try: if sys.version_info < ( 2, 5 ): # tarfile module prior to 2.5 is useless to us: http://bugs.python.org/issue1509889 raise tarfile.CompressionError Install_Log.log("Unpacking %s with Python" % (package_path)) tar = tarfile.open(package_path, 'r:gz') for tarinfo in tar: Install_Log.log(" %s" % (tarinfo.name)) tar.extract(tarinfo, target_path) ret = {'retcode': 0} except tarfile.CompressionError: command = "gzip -dc '%s' | tar xfv -" % (package_path) Install_Log.log( "Unpacking %(package_path)s with the GZip binary (cd: %(target_path)s): %(command)s" % (locals())) ret = popen.popen_sync(command, cd=target_path) Install_Log.log(ret['stdout']) Install_Log.log(ret['stderr']) # Set default permission Install_Log.log("Setting default permission 755 for directory %s" % (target_path)) os.chmod( target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # Remove the package if package_path.startswith(CHEROKEE_OWS_DIR): Install_Log.log("Skipping removal of: %s" % (package_path)) else: Install_Log.log("Removing %s" % (package_path)) os.unlink(package_path) return ret
def __safe_call__ (self): url_download = CTK.cfg.get_val('tmp!market!install!download') box = CTK.Box() box += CTK.RawHTML ("<h2>%s</h2><br/>" %(_('Setting up application…'))) # has it been downloaded? pkg_filename = url_download.split('/')[-1] package_path = CTK.cfg.get_val ('tmp!market!install!local_package') if not package_path or not os.path.exists (package_path): down_entry = CTK.DownloadEntry_Factory (url_download) package_path = down_entry.target_path # Create the local directory target_path = os.path.join (CHEROKEE_OWS_ROOT, str(int(time.time()*100))) os.mkdir (target_path, 0700) CTK.cfg['tmp!market!install!root'] = target_path # Create the log file Install_Log.log ("Unpacking %s" %(package_path)) Install_Log.set_file (os.path.join (target_path, "install.log")) # Uncompress tar = tarfile.open (package_path, 'r:gz') for tarinfo in tar: Install_Log.log (" %s" %(tarinfo.name)) tar.extract (tarinfo, target_path) # Set default permission Install_Log.log ("Setting default permission 755 for directory %s" %(target_path)) os.chmod (target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH ) # Remove the package if package_path.startswith (CHEROKEE_OWS_DIR): Install_Log.log ("Skipping removal of: %s" %(package_path)) else: Install_Log.log ("Removing %s" %(package_path)) os.unlink (package_path) # Import the Installation handler if os.path.exists (os.path.join (target_path, "installer.py")): Install_Log.log ("Passing control to installer.py") installer_path = os.path.join (target_path, "installer.py") pkg_installer = imp.load_source ('installer', installer_path) else: Install_Log.log ("Passing control to installer.pyo") installer_path = os.path.join (target_path, "installer.pyo") pkg_installer = imp.load_compiled ('installer', installer_path) # Set owner and permissions Install_Log.log ("Post unpack commands") # Execute commands commands = pkg_installer.__dict__.get ('POST_UNPACK_COMMANDS',[]) box += CommandProgress.CommandProgress (commands, URL_INSTALL_SETUP_EXTERNAL) return box.Render().toStr()
def __safe_call__(self): app_id = CTK.cfg.get_val('tmp!market!install!app!application_id') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') # URL Package index = Distro.Index() pkg = index.get_package(app_id, 'package') repo_url = CTK.cfg.get_val('admin!ows!repository', REPO_MAIN) url_download = os.path.join(repo_url, app_id, pkg['filename']) CTK.cfg['tmp!market!install!download'] = url_download # Local storage shortcut pkg_filename_full = url_download.split('/')[-1] pkg_filename = pkg_filename_full.split('_')[0] pkg_revision = 0 pkg_repo_fp = os.path.join(CHEROKEE_OWS_DIR, "packages", app_id) if os.access(pkg_repo_fp, os.X_OK): for f in os.listdir(pkg_repo_fp): tmp = re.findall('^%s_(\d+)' % (pkg_filename), f) if tmp: pkg_revision = max(pkg_revision, int(tmp[0])) if pkg_revision > 0: pkg_fullpath = os.path.join( CHEROKEE_OWS_DIR, "packages", app_id, '%s_%d.cpk' % (pkg_filename, pkg_revision)) CTK.cfg['tmp!market!install!local_package'] = pkg_fullpath Install_Log.log("Using local repository package: %s" % (pkg_fullpath)) box = CTK.Box() box += CTK.RawHTML( js=CTK.DruidContent__JS_to_goto(box.id, URL_INSTALL_SETUP)) return box.Render().toStr() # Instance a Downloader downloader = CTK.Downloader('package', url_download) downloader.bind('stopped', CTK.DruidContent__JS_to_close(downloader.id)) downloader.bind( 'finished', CTK.DruidContent__JS_to_goto(downloader.id, URL_INSTALL_SETUP)) downloader.bind( 'error', CTK.DruidContent__JS_to_goto(downloader.id, URL_INSTALL_DOWNLOAD_ERROR)) stop = CTK.Button(_('Cancel')) stop.bind('click', downloader.JS_to_stop()) buttons = CTK.DruidButtonsPanel() buttons += stop Install_Log.log("Downloading %s" % (url_download)) cont = CTK.Container() cont += CTK.RawHTML('<h2>%s %s</h2>' % (_("Installing"), app_name)) cont += CTK.RawHTML( '<p>%s</p>' % (_('The application is being downloaded. Hold on tight!'))) cont += downloader cont += buttons cont += CTK.RawHTML(js=downloader.JS_to_start()) return cont.Render().toStr()
def __safe_call__(self): # Ensure the current UID has enough priviledges if not InstallUtil.current_UID_is_admin() and 0: box = CTK.Box() box += CTK.RawHTML('<h2>%s</h2>' % (_(NO_ROOT_H1))) box += CTK.RawHTML('<p>%s</p>' % (_(NO_ROOT_P1))) box += CTK.RawHTML('<p>%s</p>' % (_(NO_ROOT_P2))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) box += buttons return box.Render().toStr() # Check the rest of pre-requisites index = Distro.Index() app_id = CTK.cfg.get_val('tmp!market!install!app!application_id') app = index.get_package(app_id, 'software') inst = index.get_package(app_id, 'installation') if 'cherokee_min_ver' in inst: version = inst['cherokee_min_ver'] if version_cmp(VERSION, version) < 0: box = CTK.Box() box += CTK.RawHTML('<h2>%s</h2>' % (_(MIN_VER_H1))) box += CTK.RawHTML('<p>%s</p>' % (_(MIN_VER_P1) % (locals()))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) box += buttons return box.Render().toStr() # Init the log file Install_Log.reset() Install_Log.log(".---------------------------------------------.") Install_Log.log("| PLEASE, DO NOT EDIT OR REMOVE THIS LOG FILE |") Install_Log.log("| |") Install_Log.log("| It contains useful information that |") Install_Log.log("| cherokee-admin might need in the future. |") Install_Log.log(".---------------------------------------------.") Install_Log.log("Retrieving package information...") # Check whether there are CTK.cfg changes to be saved changes = "01"[int(CTK.cfg.has_changed())] CTK.cfg['tmp!market!install!cfg_previous_changes'] = changes # Render a welcome message box = CTK.Box() box += CTK.RawHTML( js=CTK.DruidContent__JS_to_goto(box.id, URL_INSTALL_DOWNLOAD)) return box.Render().toStr()
def __safe_call__(self): # Ensure the current UID has enough priviledges if not InstallUtil.current_UID_is_admin() and 0: box = CTK.Box() box += CTK.RawHTML("<h2>%s</h2>" % (_(NO_ROOT_H1))) box += CTK.RawHTML("<p>%s</p>" % (_(NO_ROOT_P1))) box += CTK.RawHTML("<p>%s</p>" % (_(NO_ROOT_P2))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_("Cancel")) box += buttons return box.Render().toStr() # Check the rest of pre-requisites index = Distro.Index() app_id = CTK.cfg.get_val("tmp!market!install!app!application_id") app = index.get_package(app_id, "software") inst = index.get_package(app_id, "installation") if "cherokee_min_ver" in inst: version = inst["cherokee_min_ver"] if version_cmp(VERSION, version) < 0: box = CTK.Box() box += CTK.RawHTML("<h2>%s</h2>" % (_(MIN_VER_H1))) box += CTK.RawHTML("<p>%s</p>" % (_(MIN_VER_P1) % (locals()))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_("Cancel")) box += buttons return box.Render().toStr() # Init the log file Install_Log.reset() Install_Log.log(".---------------------------------------------.") Install_Log.log("| PLEASE, DO NOT EDIT OR REMOVE THIS LOG FILE |") Install_Log.log("| |") Install_Log.log("| It contains useful information that |") Install_Log.log("| cherokee-admin might need in the future. |") Install_Log.log(".---------------------------------------------.") Install_Log.log("Retrieving package information...") # Check whether there are CTK.cfg changes to be saved changes = "01"[int(CTK.cfg.has_changed())] CTK.cfg["tmp!market!install!cfg_previous_changes"] = changes # Render a welcome message box = CTK.Box() box += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto(box.id, URL_INSTALL_DOWNLOAD)) return box.Render().toStr()
def _Setup_unpack(): url_download = CTK.cfg.get_val("tmp!market!install!download") # has it been downloaded? pkg_filename = url_download.split("/")[-1] package_path = CTK.cfg.get_val("tmp!market!install!local_package") if not package_path or not os.path.exists(package_path): down_entry = CTK.DownloadEntry_Factory(url_download) package_path = down_entry.target_path # Create the local directory target_path = os.path.join(CHEROKEE_OWS_ROOT, str(int(time.time() * 100))) os.mkdir(target_path, 0700) CTK.cfg["tmp!market!install!root"] = target_path # Create the log file Install_Log.set_file(os.path.join(target_path, "install.log")) # Uncompress try: if sys.version_info < ( 2, 5, ): # tarfile module prior to 2.5 is useless to us: http://bugs.python.org/issue1509889 raise tarfile.CompressionError Install_Log.log("Unpacking %s with Python" % (package_path)) tar = tarfile.open(package_path, "r:gz") for tarinfo in tar: Install_Log.log(" %s" % (tarinfo.name)) tar.extract(tarinfo, target_path) ret = {"retcode": 0} except tarfile.CompressionError: command = "gzip -dc '%s' | tar xfv -" % (package_path) Install_Log.log( "Unpacking %(package_path)s with the GZip binary (cd: %(target_path)s): %(command)s" % (locals()) ) ret = popen.popen_sync(command, cd=target_path) Install_Log.log(ret["stdout"]) Install_Log.log(ret["stderr"]) # Set default permission Install_Log.log("Setting default permission 755 for directory %s" % (target_path)) os.chmod( target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH, ) # Remove the package if package_path.startswith(CHEROKEE_OWS_DIR): Install_Log.log("Skipping removal of: %s" % (package_path)) else: Install_Log.log("Removing %s" % (package_path)) os.unlink(package_path) return ret
def __safe_call__(self): root = CTK.cfg.get_val('tmp!market!install!root') app_name = CTK.cfg.get_val('tmp!market!install!app!application_name') cfg_changes = CTK.cfg.get_val( 'tmp!market!install!cfg_previous_changes') # Finished finished_file = os.path.join(root, "finished") Install_Log.log("Creating %s" % (finished_file)) f = open(finished_file, 'w+') f.close() # Normalize CTK.cfg CTK.cfg.normalize('vserver') # Save configuration box = CTK.Box() if not int(cfg_changes): CTK.cfg.save() Install_Log.log("Configuration saved.") Cherokee.server.restart(graceful=True) Install_Log.log("Server gracefully restarted.") box += CTK.RawHTML(js=SaveButton.ButtonSave__JS_to_deactive()) Install_Log.log("Finished") # Thank user for the install box += CTK.RawHTML('<h2>%s %s</h2>' % (app_name, _("has been installed successfully"))) box += CTK.RawHTML("<p>%s</p>" % (_(NOTE_THANKS_P1))) # Save / Visit if int(cfg_changes): box += CTK.Notice('information', CTK.RawHTML(_(NOTE_SAVE_RESTART))) elif Cherokee.server.is_alive(): install_type = CTK.cfg.get_val('tmp!market!install!target') nick = CTK.cfg.get_val('tmp!market!install!target!vserver') vserver_n = CTK.cfg.get_val('tmp!market!install!target!vserver_n') directory = CTK.cfg.get_val('tmp!market!install!target!directory') # Host if vserver_n and not nick: nick = CTK.cfg.get_val("vserver!%s!nick" % (vserver_n)) if not nick or nick.lower() == "default": sys_stats = SystemStats.get_system_stats() nick = sys_stats.hostname # Ports ports = [] for b in CTK.cfg['server!bind'] or []: port = CTK.cfg.get_val('server!bind!%s!port' % (b)) if port: ports.append(port) nick_port = nick if ports and not '80' in ports: nick_port = '%s:%s' % (nick, ports[0]) # URL url = '' if install_type == 'vserver' and nick: url = 'http://%s/' % (nick_port) elif install_type == 'directory' and vserver_n and directory: nick = CTK.cfg.get_val('vserver!%s!nick' % (vserver_n)) url = 'http://%s%s/' % (nick_port, directory) if url: box += CTK.RawHTML('<p>%s ' % (_("You can now visit"))) box += CTK.LinkWindow(url, CTK.RawHTML(_('your new application'))) box += CTK.RawHTML(' on a new window.</p>') box += CTK.RawHTML("<h1>%s</h1>" % (_(NOTE_THANKS_P2))) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Close')) box += buttons # Clean up CTK.cfg for k in CTK.cfg.keys('tmp!market!install'): if k != 'app': del (CTK.cfg['tmp!market!install!%s' % (k)]) return box.Render().toStr()
def __safe_call__ (self): Install_Log.reset() Install_Log.log (".---------------------------------------------.") Install_Log.log ("| PLEASE, DO NOT EDIT OR REMOVE THIS LOG FILE |") Install_Log.log ("| |") Install_Log.log ("| It contains useful information that |") Install_Log.log ("| cherokee-admin might need in the future. |") Install_Log.log (".---------------------------------------------.") Install_Log.log ("Retrieving package information...") # Check whether there are CTK.cfg changes to be saved changes = "01"[int(CTK.cfg.has_changed())] CTK.cfg['tmp!market!install!cfg_previous_changes'] = changes # Render a welcome message box = CTK.Box() box += CTK.RawHTML ('<h2>%s</h2>' %(_('Connecting to Cherokee Market'))) box += CTK.RawHTML ('<h1>%s</h1>' %(_('Retrieving package information…'))) box += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto (box.id, URL_INSTALL_INIT_CHECK)) # Dialog buttons buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) box += buttons return box.Render().toStr()