def _drop_site(site, root_login='******', root_password=None, archived_sites_path=None, force=False): "Remove site from database and filesystem" from frappe.database import drop_user_and_database from frappe.utils.backups import scheduled_backup frappe.init(site=site) frappe.connect() try: scheduled_backup(ignore_files=False, force=True) except Exception as err: if force: pass else: click.echo("="*80) click.echo("Error: The operation has stopped because backup of {s}'s database failed.".format(s=site)) click.echo("Reason: {reason}{sep}".format(reason=err[1], sep="\n")) click.echo("Fix the issue and try again.") click.echo( "Hint: Use 'bench drop-site {s} --force' to force the removal of {s}".format(sep="\n", tab="\t", s=site) ) sys.exit(1) drop_user_and_database(frappe.conf.db_name, root_login, root_password) if not archived_sites_path: archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived_sites') if not os.path.exists(archived_sites_path): os.mkdir(archived_sites_path) move(archived_sites_path, site)
def _drop_site(site, root_login='******', root_password=None, archived_sites_path=None, force=False, no_backup=False): "Remove site from database and filesystem" from frappe.database import drop_user_and_database from frappe.utils.backups import scheduled_backup frappe.init(site=site) frappe.connect() try: if not no_backup: scheduled_backup(ignore_files=False, force=True) except Exception as err: if force: pass else: messages = [ "=" * 80, "Error: The operation has stopped because backup of {0}'s database failed.".format(site), "Reason: {0}\n".format(str(err)), "Fix the issue and try again.", "Hint: Use 'bench drop-site {0} --force' to force the removal of {0}".format(site) ] click.echo("\n".join(messages)) sys.exit(1) drop_user_and_database(frappe.conf.db_name, root_login, root_password) if not archived_sites_path: archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived_sites') if not os.path.exists(archived_sites_path): os.mkdir(archived_sites_path) move(archived_sites_path, site)