def execute(self, dest, server, app): connect_host(dest, server) for dir in [self.AVAILABLE_DIR, self.ENABLED_DIR, self.LOG_DIR, self.DATA_DIR]: ensure_remote_dir(dir, "root", "777") return self.doit(dest, server, app)
def doit(self, dest, server, app): SUB_DIR = "files" real = os.path.join(self.AVAILABLE_DIR, app, SUB_DIR) symb = os.path.join(self.ENABLED_DIR, app, SUB_DIR) run("mkdir -p %s"%(real)) ensure_remote_dir(os.path.dirname(symb)) run("if [ ! -h %s ]; then rm -rf %s; ln -s %s %s; fi"%(symb, symb, real, symb)) file_dir = os.path.join(PROJECT_DIR, app, SUB_DIR) abs_file_path = os.path.join(file_dir, self.options.file) if os.path.isfile(abs_file_path): ensure_remote_file(abs_file_path, os.path.join(real, self.options.file))
def doit(self, dest, server, app): dir_name = self.options.dir_name # dir_name = "source" or "conf" if dir_name not in ["source", "conf"]: safe_exit("Not support dir_name.\n") ensure_remote_dir(os.path.join(self.AVAILABLE_DIR, app, dir_name)) current_version = self._get_current_version_number(app, dir_name) version = self._get_previous_version_number(app, dir_name) if not version: safe_exit("%s %s %s %s version number error.\n"%(dest, server, app, dir_name), 1) available = os.path.join(self.AVAILABLE_DIR, app, dir_name, version) enabled = os.path.join(self.ENABLED_DIR, app) run("rm -f %s"%(os.path.join(enabled, dir_name))) run("ln -s %s %s"%(os.path.join(available, dir_name), os.path.join(enabled, dir_name))) run("rm -r %s"%(os.path.join(self.AVAILABLE_DIR, app, dir_name, current_version)))
def doit(self, dest, server, app): SUB_DIR = "scripts" real = os.path.join(self.AVAILABLE_DIR, app, SUB_DIR) symb = os.path.join(self.ENABLED_DIR, app, SUB_DIR) run("mkdir -p %s"%(real)) ensure_remote_dir(os.path.dirname(symb)) run("if [ ! -h %s ]; then rm -rf %s; ln -s %s %s; fi"%(symb, symb, real, symb)) script_path = self.get_script_path() local_script_path = os.path.join(PROJECT_DIR, app, SUB_DIR, script_path) remote_script_path = os.path.join(real, script_path) ensure_remote_dir(os.path.dirname(remote_script_path)) if self.options.force: put(local_script_path, remote_script_path) else: ensure_remote_file(local_script_path, remote_script_path) run("chmod +x %s; %s"%(remote_script_path, remote_script_path))
def deploy(self, dest, server, app, dir_name): # dir_name is a sub directory of app. eg. source, conf . ensure_remote_dir(os.path.join(self.AVAILABLE_DIR, app, dir_name)) version = self._get_next_version_number(app, dir_name) available = os.path.join(self.AVAILABLE_DIR, app, dir_name, version) enabled = os.path.join(self.ENABLED_DIR, app) ensure_remote_dir(available) ensure_remote_dir(enabled) if dir_name == "source": local("cd %s; tar cvzf /tmp/%s.tar.gz --exclude='.svn' ./%s;"%(os.path.join(PROJECT_DIR, app), dir_name, dir_name)) elif dir_name == "conf": local("cd %s; tar cvzf /tmp/%s.tar.gz --exclude='.svn' ./%s;"% (os.path.join("/tmp/", self.PROJECT_NAME, dest, server, app), dir_name, dir_name)) else: safe_exit("Not support dir_name.\n") put("/tmp/%s.tar.gz"%(dir_name), available) with cd(available): run("tar zvxf %s.tar.gz"%(dir_name)) run("rm -f %s"%(os.path.join(enabled, dir_name))) run("ln -s %s %s"%(os.path.join(available, dir_name), os.path.join(enabled, dir_name)))