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): 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, origin_path, target_path): self.log("Downloading from {0}:{1} to {2}:{3}...".format(utils.reverse(target), origin_path, target, target_path)) if utils.is_local(target): operations.get(remote_path=origin_path, local_path=target_path) if utils.is_remote(target): operations.put(remote_path=target_path, local_path=origin_path)
def operation(self, target, origin_path, target_path): self.log("Downloading from {0}:{1} to {2}:{3}...".format( utils.reverse(target), origin_path, target, target_path)) if utils.is_local(target): operations.get(remote_path=origin_path, local_path=target_path) if utils.is_remote(target): operations.put(remote_path=target_path, local_path=origin_path)
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) # get informations about installation we need to mirror, such as wp version, locale, themes, plugins... data = self.subtask(base.collect_data, origin) # download wordpress files self.subtask(download, target, data=data) # sync self.subtask(sync, target, data=data)
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): # 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) # 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, sync_media=True, data=None): origin = utils.reverse(target) if data is None: data = self.subtask(base.collect_data, origin) # import the database self.subtask(db.sync, target) # download plugins and themes self.subtask(theme.sync, target, data) self.subtask(plugin.sync, target, data) if base.strtobool(sync_media): # download media files self.subtask(med.sync, target)
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) # 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 get_start_message(self): return "Syncing databases (from {0} to {1})".format(utils.reverse(self.target), self.target)
def get_start_message(self): return "Syncing databases (from {0} to {1})".format( utils.reverse(self.target), self.target)