def create_wordpress(self): if self.conf.get('wordpress','enabled'): site_path, root_path, log_path, upload_tmp_path = self.generate_dir() wp_tpl_webroot = CONF_MAP('site','wordpress_template_path') + "/webroot" wp_tpl_schema = CONF_MAP('site','wordpress_template_path') + "/schema/wordpress_tpl_schema.sql" wp_webroot_conf = root_path + "/wp-config.php" mysql_user = self.conf.get('mysql','user') mysql_pass = self.conf.get('mysql','pass') mysql_schema = self.conf.get('mysql','schema') site_name = self.conf.get('main','site_name') if inputs.get_input_noyes(t("Do you want deploy the default wordpress template under %s?") % root_path): if files.exists(wp_tpl_webroot): cmd_list = [ "bash -c 'cp -fr %s/* %s/'" % (wp_tpl_webroot, root_path), ] completed, pinfo = core.exec_cmd_list(cmd_list) if not completed: L.error(t("Cannot deploy the template.")) else: L.info(t("There is no template under %s") % wp_tpl_webroot) elif inputs.get_input_yesno(t("Do you want to only deploy default plugins?")): if files.exists(wp_tpl_webroot): cmd_list = [ "bash -c 'mkdir -p %s/wp-content/plugins'" % root_path, "bash -c 'cp -fr %s/wp-content/plugins/* %s/wp-content/plugins/'" % (wp_tpl_webroot, root_path), ] completed, pinfo = core.exec_cmd_list(cmd_list) if not completed: L.error(t("Cannot deploy plugins.")) else: L.info(t("There is no template under %s") % wp_tpl_webroot) if files.exists(wp_webroot_conf): params_dict = { 'DB_NAME': mysql_schema, 'DB_USER': mysql_user, 'DB_PASSWORD': mysql_pass, 'DB_HOST':'localhost', } for key in params_dict: pattern = "define\(\s*?['\"]%s['\"].*;" % key target = "define('%s', '%s');" % (key, params_dict[key]) files.re_replace_in(wp_webroot_conf, pattern, target) else: L.info(t("There is no wp-config.php under %s") % root_path) if files.exists(wp_tpl_schema) and inputs.get_input_noyes(t("Do you want to restore default database?")): L.info(t("Restoring default schema %s.") % mysql_schema) tmp_file = "/tmp/uwsa_wp_schema_%s" % uuid.uuid4() files.cp(wp_tpl_schema, tmp_file) files.re_replace_in(tmp_file,'UWSA_SCHEMA_NAME', mysql_schema) files.replace_in_php_database(tmp_file,'UWSA_SITE_NAME', site_name) cmd_list = [ { 'command': "bash -c 'mysql -u %s -p%s %s < %s'" % (mysql_user, mysql_pass, mysql_schema, tmp_file), 'anonymous': "bash -c 'mysql -u %s -p%s %s < %s'" % (mysql_user, "XXXXX", mysql_schema, tmp_file), }, ] completed, pinfo = core.exec_cmd_list(cmd_list) if not completed: L.error(t("Failed to restore schema %s!") % mysql_schema) os.remove(tmp_file)
def schema_fix_webroot_path(self, filename, old_path_name=None): site_name = self.conf.get("main", "site_name") old_path_name = old_path_name if old_path_name else "/var/www/%s/www" % site_name new_path_name = "/var/www/%s/webroot" % site_name.replace(".", "-") files.replace_in_php_database(filename, old_path_name, new_path_name) return True
def devconv(self, args): filename = "/tmp/dev.sql" pattern = "example.com" target = "dev.example.com" files.replace_in_php_database(filename, pattern, target)
def schema_toprod(self, filename): self.schema_fix_webroot_path(filename) site_name = self.conf.get("main", "site_name") site_dev_name = self.conf.get("main", "site_dev_name") files.replace_in_php_database(filename, site_dev_name, site_name) return True