def operation(self, target): command = "rm -rf '{0}/'{1}".format( utils.setting('dumps_path', target), "remote-*.sql") self.subtask(base.run_target, target, command) command = "rm -rf '{0}/'{1}".format( utils.setting('dumps_path', target), "local-*.sql") self.subtask(base.run_target, target, command)
def operation(self, target): # replace permalink search_url = utils.setting("url", utils.reverse(target)) replace_url = utils.setting("url", target) command = "search-replace '{0}' '{1}' --precise".format(search_url, replace_url) self.log("Updating URL(s) from {0} to {1}...".format(search_url, replace_url)) output = self.subtask(base.wp, target=target, command=command) # update structure self.log("Updating permalinks structure to {0}...".format(utils.setting("permalinks"))) self.subtask(base.wp, target=target, command="rewrite flush --hard") self.subtask(base.wp, target=target, command="rewrite structure '{0}'".format(utils.setting("permalinks")))
def operation(self, target): origin = utils.reverse(target) media_files = os.path.join(utils.setting("path", origin), "wp-content", "uploads", "*") target_media_path = os.path.join(utils.setting("path", target), "wp-content", "uploads") self.log( "Syncing media files from {0} to {1} (please, be patient, this may take some time)" .format(utils.reverse(self.target), self.target)) self.subtask(base.get_file, target=utils.reverse(origin), origin_path=media_files, target_path=target_media_path)
def operation(self, target, symlink_name): path = os.path.join(utils.setting('path', self.target), self.symlink_directory, symlink_name) self.info("Symlinking {0} to {1}".format(target, path)) command = "ln -s '{0}' '{1}'".format(target, path) with hide('everything'), warn_only(): self.subtask(base.run_target, 'local', command)
def operation(self, target, path): # Create a backup just in case self.subtask( export, target=target, start_message= 'Creating a safety backup of {0} database, juste in case'.format( target)) # download or upload the dump to the target target_dump_path = os.path.join(utils.setting('dumps_path', target), ntpath.basename(path)) self.subtask(base.get_file, target=target, origin_path=path, target_path=target_dump_path, start_message="Downloading backup from {0}".format( utils.reverse(target))) self.log("Importing {0} into {1} database...".format( target_dump_path, target)) self.subtask(base.wp, target=target, command="db import '{0}'".format(target_dump_path)) # remove the backup file locally and remotely self.log("Deleting useless SQL backups...", indentation=1) self.subtask(base.run_target, utils.reverse(target), "rm '{0}'".format(path)) self.subtask(base.run_target, target, "rm '{0}'".format(target_dump_path))
def operation(self, target, path): # Create a backup just in case self.subtask( export, target=target, start_message='Creating a safety backup of {0} database, juste in case'.format(target)) # download or upload the dump to the target target_dump_path = os.path.join(utils.setting('dumps_path', target), ntpath.basename(path)) self.subtask( base.get_file, target=target, origin_path=path, target_path=target_dump_path, start_message="Downloading backup from {0}".format(utils.reverse(target))) self.log("Importing {0} into {1} database...".format(target_dump_path, target)) self.subtask(base.wp,target=target, command="db import '{0}'".format(target_dump_path)) # remove the backup file locally and remotely self.log("Deleting useless SQL backups...", indentation=1) self.subtask(base.run_target, utils.reverse(target), "rm '{0}'".format(path)) self.subtask(base.run_target, target, "rm '{0}'".format(target_dump_path))
def operation(self, target, command): """run a wpcli command on local or remote""" # get wp-cli path on target wp = utils.setting('wp-cli', target, 'wp') full_command = "{0} {1}".format(wp, command) if utils.is_local(target): with lcd(utils.setting("path", target)): r = local(full_command, capture=True) if utils.is_remote(target): with cd(utils.setting("path", target)): r = run(full_command) if self.called_via_fab: self.log(r) return r
def trigger_hooks(self): """User can register hooks in settings. We trigger them here""" task = self.get_task_id() hooks = utils.setting("hooks") hooks_to_trigger = [hook for key, hook in hooks.items() if key == task] for hook in hooks_to_trigger: self.trigger_hook(hook)
def operation(self, target, data=None): origin = utils.reverse(target) if data is None: data = self.subtask(base.collect_data, origin) # create directory if needed self.subtask(base.run_target, target, "mkdir -p '{0}'".format(utils.setting('path', target))) download_command = "core download --locale={0} --path='{1}' --version='{2}'".format( data.get('locales')[0], utils.setting('path', target), data.get('version')) # fix permissions self.log('Changing permissions of {0} to {1}'.format( utils.setting('path', target), utils.setting("default_chmod"))) self.subtask( base.run_target, target, "chmod {0} -R '{1}'".format(utils.setting("default_chmod"), utils.setting('path', target))) with warn_only(): output = self.subtask(base.wp, target, download_command) # install additionnal languages for locale in data.get('locales')[1:]: self.subtask(wp, target, "core language install {0}".format(locale)) # check if wp-config.php exists: wp_config_path = os.path.join(utils.setting("path", target), "wp-config.php") command = """[ -f '{0}' ] && echo '1' 2>&1 || echo '0' 2>&1""".format( wp_config_path) output = self.subtask(base.run_target, target, command) wp_config_exists = int(output) # "${EDITOR:-vi}" edit_command = "{0} {1}".format("nano", wp_config_path) if wp_config_exists: self.log("Existing wp-config.php file found") else: # copy the sample command = "mv '{0}' '{1}'".format( os.path.join(utils.setting("path", target), "wp-config-sample.php"), wp_config_path) self.subtask(base.run_target, target, command) edit = console.confirm( "wp-config.php was copied from sample. Do you want to edit it ?" ) if edit: # edit the wp-config.php sys.exit( 'Edit your file located at {0} then relaunch this command'. format(wp_config_path))
def trigger_hooks(self): """Trigger target specific hooks""" super(TargetTask, self).trigger_hooks() task = self.get_task_id() hooks = utils.setting("hooks", self.target, {}) hooks_to_trigger = [hook for key, hook in hooks.items() if key == task] for hook in hooks_to_trigger: self.trigger_hook(hook)
def operation(self, target): # replace permalink search_url = utils.setting("url", utils.reverse(target)) replace_url = utils.setting("url", target) command = "search-replace '{0}' '{1}' --precise".format( search_url, replace_url) self.log("Updating URL(s) from {0} to {1}...".format( search_url, replace_url)) output = self.subtask(base.wp, target=target, command=command) # update structure self.log("Updating permalinks structure to {0}...".format( utils.setting("permalinks"))) self.subtask(base.wp, target=target, command="rewrite flush --hard") self.subtask(base.wp, target=target, command="rewrite structure '{0}'".format( utils.setting("permalinks")))
def operation(self, target, data=None): origin = utils.reverse(target) if data is None: data = self.subtask(base.collect_data, origin) for plugin in data['plugins']: if plugin in utils.setting('ignored_plugins'): self.info("Skipping plugin {0}; it is listed in ignored_themes".format(plugin)) else: self.info('Installing plugin {0} ({1})...'.format(plugin.get("name"), plugin.get('version'))) command = "plugin install {0} --activate --version={1}".format(plugin.get("name"), plugin.get('version')) self.subtask(base.wp, target, command)
def operation(self, target): backup_name = "{0}-{1}.sql".format( target, datetime.datetime.now().strftime("%Y%m%d%H%M%S")) backup_path = os.path.join(utils.setting("dumps_path", target), backup_name) self.log("Exporting {0} database to {1}...".format( target, backup_path)) self.subtask(base.wp, target=target, command="db export '{0}'".format(backup_path)) return backup_path
def operation(self, target): origin = utils.reverse(target) # create the backup backup_path = self.subtask(export, target=origin) # import it self.subtask(imp, target=target, path=backup_path) # update permalinks self.subtask(permalink_fix, target=target) # clear transients self.log("Clearing transients...".format(utils.setting("permalinks"))) self.subtask(base.wp, target=target, command="transient delete-all")
def operation(self, target, data=None): origin = utils.reverse(target) if data is None: data = self.subtask(base.collect_data, origin) for theme in data['themes']: if theme.get('name') in utils.setting('ignored_themes'): self.info("Skipping theme {0}: it is listed in ignored_themes". format(theme.get('name'))) else: self.info('Installing theme {0} ({1})...'.format( theme.get("name"), theme.get('version'))) command = "theme install {0} --activate --version={1}".format( theme.get("name"), theme.get('version')) self.subtask(base.wp, target, command)
def operation(self, target, data=None): origin = utils.reverse(target) if data is None: data = self.subtask(base.collect_data, origin) # create directory if needed self.subtask(base.run_target, target, "mkdir -p '{0}'".format(utils.setting('path', target))) download_command = "core download --locale={0} --path='{1}' --version='{2}'".format( data.get('locales')[0], utils.setting('path', target), data.get('version')) # fix permissions self.log('Changing permissions of {0} to {1}'.format(utils.setting('path', target), utils.setting("default_chmod"))) self.subtask(base.run_target, target, "chmod {0} -R '{1}'".format(utils.setting("default_chmod"), utils.setting('path', target))) with warn_only(): output = self.subtask(base.wp, target, download_command) # install additionnal languages for locale in data.get('locales')[1:]: self.subtask(wp,target, "core language install {0}".format(locale)) # check if wp-config.php exists: wp_config_path = os.path.join(utils.setting("path", target), "wp-config.php") command = """[ -f '{0}' ] && echo '1' 2>&1 || echo '0' 2>&1""".format(wp_config_path) output = self.subtask(base.run_target, target, command) wp_config_exists = int(output) # "${EDITOR:-vi}" edit_command = "{0} {1}".format("nano", wp_config_path) if wp_config_exists: self.log("Existing wp-config.php file found") else: # copy the sample command = "mv '{0}' '{1}'".format(os.path.join(utils.setting("path", target), "wp-config-sample.php"), wp_config_path) self.subtask(base.run_target, target, command) edit = console.confirm("wp-config.php was copied from sample. Do you want to edit it ?") if edit: # edit the wp-config.php sys.exit('Edit your file located at {0} then relaunch this command'.format(wp_config_path))
def operation(self, target): origin = utils.reverse(target) media_files = os.path.join(utils.setting("path", origin), "wp-content", "uploads", "*") target_media_path = os.path.join(utils.setting("path", target), "wp-content", "uploads") self.log("Syncing media files from {0} to {1} (please, be patient, this may take some time)".format(utils.reverse(self.target), self.target)) self.subtask(base.get_file, target=utils.reverse(origin), origin_path=media_files, target_path=target_media_path)
def operation(self, target): command = 'find {0}/ -name "*" | xargs rm -rf '.format( os.path.join(utils.setting("path", target))) self.subtask(base.run_target, target=target, command=command)
def operation(self, target): command = 'find {0}/ -name "*" | xargs rm -rf '.format(os.path.join(utils.setting("path", target))) self.subtask(base.run_target, target=target, command=command)
def operation(self, target): backup_name = "{0}-{1}.sql".format(target, datetime.datetime.now().strftime("%Y%m%d%H%M%S")) backup_path = os.path.join(utils.setting("dumps_path", target), backup_name) self.log("Exporting {0} database to {1}...".format(target, backup_path)) self.subtask(base.wp, target=target, command="db export '{0}'".format(backup_path)) return backup_path
def operation(self, target): command = "rm -rf '{0}/'{1}".format(utils.setting('dumps_path', target), "remote-*.sql") self.subtask(base.run_target, target, command) command = "rm -rf '{0}/'{1}".format(utils.setting('dumps_path', target), "local-*.sql") self.subtask(base.run_target, target, command)