def create_backup_file(self, backup): # Create temporary working directory tmp_dir = tempfile.mkdtemp() self.temp_dir = tmp_dir # Create tar file saved_path = os.getcwd() os.chdir(tmp_dir) tar = tarfile.open('archive.tar.gz', 'w:gz') # Loop over databases for database in backup.get('databases'): db_filename = database + '.sql' # Dump db stdio.ppexec('mysqldump -u {user} -p\'{password}\' {database} | gzip > {file_path}'.format( user=backup.get('database_user'), password=backup.get('database_password').replace("'", "\\'"), database=database, file_path=db_filename )) tar.add(os.path.basename(os.path.normpath(db_filename))) tar.close() os.chdir(saved_path) return os.path.join(tmp_dir, 'archive.tar.gz')
def create_backup_file(self, backup): # Create temporary working directory tmp_dir = tempfile.mkdtemp() self.temp_dir = tmp_dir # Create tar file saved_path = os.getcwd() os.chdir(tmp_dir) tar = tarfile.open('archive.tar.gz', 'w:gz') # Loop over databases for database in backup.get('databases'): db_filename = database + '.sql' # Dump db stdio.ppexec('pg_dump {database} -U {user} -h localhost -f {file_path} --no-password'.format( database=database, user=backup.get('database_user', database), file_path=db_filename )) tar.add(os.path.basename(os.path.normpath(db_filename))) tar.close() os.chdir(saved_path) return os.path.join(tmp_dir, 'archive.tar.gz')
def composer_pass(self): if os.path.isfile("composer.phar"): composercmd = "php composer.phar" else: composercmd = "composer" stdio.ppexec(composercmd + " -n install --optimize-autoloader")
def scss_pass(self): # Let's find SCSS files inside this project for root, dirs, files in os.walk(os.getcwd()): for file in files: if file.endswith(".scss") and not file.startswith("_"): # Exclude SCSS part files (_part.scss) abs_path = os.path.join(root, file) stdio.ppexec("sass " + abs_path + " " + abs_path.replace(".scss", ".css") + " --style compressed")
def release(project_path): # Parse conf conf = parse_conf(os.path.join(project_path, CONFIG_FILE_NAME)) # Read conf project_type = conf.get("projectType", "generic") branch = conf.get("branch", "release") # Check the project type types = get_supported_project_types() if project_type not in types: print("Unknown project type \"{}\".".format(project_type)) return # Let's go! os.chdir(project_path) os.system("git checkout " + branch) os.system("git pull") # get an updated version of the conf, if the config file has changed after the pull conf = parse_conf(os.path.join(project_path, CONFIG_FILE_NAME)) # Determine plugin-specific passes forced_passes = conf.get("passes", "").split() plugin = types[project_type]() deploy_passes = [] for pass_name in plugin.register_passes(): # Check if optional task is enabled if pass_name[0] == "?": pass_name = pass_name[1:] if "+"+pass_name not in forced_passes: continue # Check if pass is enabled if "-"+pass_name in forced_passes: continue deploy_passes.append(pass_name) print(CBOLD+LGREEN, "\n==> Deployment starting with passes: {}".format(", ".join(deploy_passes)), CRESET) # Start env-specific passes npasses = len(deploy_passes) for i, pass_name in enumerate(deploy_passes): print(CBOLD, "\n==> Pass {} of {} [{}]".format(i+1, npasses, pass_name), CRESET) getattr(plugin, pass_name + "_pass")() # Execute custom commands commands = conf.get("commands", []) if len(commands) > 0: print(CBOLD + LGREEN, "\nExecuting custom commands", CRESET) for command in commands: stdio.ppexec(command) # The End print(CBOLD+LGREEN, "\n==> {} successfully deployed. Have an A1 day!\n".format(project_path), CRESET)
def create_backup_file(self, backup): # Create temporary file tmp_filepath = stdio.simple_exec('mktemp') # Dump db stdio.ppexec('pg_dump {database} -U {user} -h localhost -f {file_path} --no-password'.format( database=backup.get('database'), user=backup.get('database_user', backup.get('database')), file_path=tmp_filepath )) return tmp_filepath
def do_backup(backup): backup_profile = backup.get('profile') # Check backup profile profiles = get_supported_backup_profiles() if backup_profile not in profiles: print("Unknown project type \"{}\".".format(backup_profile)) sys.exit(1) # JUST DO IT print(CBOLD+LGREEN, "\n==> Creating backup file", CRESET) plugin = profiles[backup_profile]() backup_filepath = plugin.create_backup_file(backup) backup['file_extension'] = plugin.file_extension # Send it to the moon send_file(backup, backup_filepath) # Delete the file stdio.ppexec('rm {}'.format(backup_filepath)) return
def update_database_schema_pass(self): stdio.ppexec(self.app_console + " doctrine:schema:update --force")
def liip_imagine_cache_pass(self): stdio.ppexec(self.app_console + " liip:imagine:cache:remove")
def cache_pass(self): stdio.ppexec(self.app_console + " cache:clear")
def assets_pass(self): stdio.ppexec(self.app_console + " assets:install") stdio.ppexec(self.app_console + " assetic:dump")
def checkout_dash_dash_site_pass(self): stdio.ppexec("git checkout -- site")
def build_pass(self): stdio.ppexec("mkdocs build --clean")