* adds new exception to be raised when any improper database configuration is detected * changes behavior of `check_if_ready_for_barracuda` to raise ImproperDBConfigurationError instead of sys.exit` * refactors `drop_site` to use a new exactly identical `_drop_site` function. The reason for this is because the original `drop_site` function is decorated and cannot be undecorated without nasty hacks. Breaking the function this way allows me to make use of the `drop-site` logic easily. * catches the ImproperDBConfigurationError raised from `check_if_ready_for_barracuda` function to drop all the artifacts of the failed new `Site`version-14
@@ -67,6 +67,9 @@ def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=N | |||||
scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled" | scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled" | ||||
print("*** Scheduler is", scheduler_status, "***") | print("*** Scheduler is", scheduler_status, "***") | ||||
except frappe.exceptions.ImproperDBConfigurationError: | |||||
_drop_site(site, mariadb_root_username, mariadb_root_password, force=True) | |||||
finally: | finally: | ||||
if installing and os.path.exists(installing): | if installing and os.path.exists(installing): | ||||
os.remove(installing) | os.remove(installing) | ||||
@@ -326,6 +329,10 @@ def uninstall(context, app, dry_run=False, yes=False): | |||||
@click.option('--archived-sites-path') | @click.option('--archived-sites-path') | ||||
@click.option('--force', help='Force drop-site even if an error is encountered', is_flag=True, default=False) | @click.option('--force', help='Force drop-site even if an error is encountered', is_flag=True, default=False) | ||||
def drop_site(site, root_login='root', root_password=None, archived_sites_path=None, force=False): | def drop_site(site, root_login='root', root_password=None, archived_sites_path=None, force=False): | ||||
_drop_site(site, root_login, root_password, archived_sites_path, force) | |||||
def _drop_site(site, root_login='root', root_password=None, archived_sites_path=None, force=False): | |||||
"Remove site from database and filesystem" | "Remove site from database and filesystem" | ||||
from frappe.installer import get_root_connection | from frappe.installer import get_root_connection | ||||
from frappe.model.db_schema import DbManager | from frappe.model.db_schema import DbManager | ||||
@@ -364,6 +371,7 @@ def drop_site(site, root_login='root', root_password=None, archived_sites_path=N | |||||
move(archived_sites_path, site) | move(archived_sites_path, site) | ||||
def move(dest_dir, site): | def move(dest_dir, site): | ||||
import os | import os | ||||
if not os.path.isdir(dest_dir): | if not os.path.isdir(dest_dir): | ||||
@@ -6,7 +6,8 @@ from __future__ import unicode_literals | |||||
# BEWARE don't put anything in this file except exceptions | # BEWARE don't put anything in this file except exceptions | ||||
from werkzeug.exceptions import NotFound | from werkzeug.exceptions import NotFound | ||||
from MySQLdb import ProgrammingError as SQLError | |||||
from MySQLdb import ProgrammingError as SQLError, Error | |||||
class ValidationError(Exception): | class ValidationError(Exception): | ||||
http_status_code = 417 | http_status_code = 417 | ||||
@@ -41,6 +42,19 @@ class Redirect(Exception): | |||||
class CSRFTokenError(Exception): | class CSRFTokenError(Exception): | ||||
http_status_code = 400 | http_status_code = 400 | ||||
class ImproperDBConfigurationError(Error): | |||||
""" | |||||
Used when frappe detects that database or tables are not properly | |||||
configured | |||||
""" | |||||
def __init__(self, reason, msg=None): | |||||
if not msg: | |||||
msg = "MariaDb is not properly configured" | |||||
super(ImproperDBConfigurationError, self).__init__(msg) | |||||
self.reason = reason | |||||
class DuplicateEntryError(NameError):pass | class DuplicateEntryError(NameError):pass | ||||
class DataError(ValidationError): pass | class DataError(ValidationError): pass | ||||
class UnknownDomainError(Exception): pass | class UnknownDomainError(Exception): pass | ||||
@@ -364,8 +364,9 @@ def check_if_ready_for_barracuda(): | |||||
"").format(x=site, sep2="\n"*2, sep="\n") | "").format(x=site, sep2="\n"*2, sep="\n") | ||||
print_db_config(msg, expected_config_for_barracuda) | print_db_config(msg, expected_config_for_barracuda) | ||||
sys.exit(1) | |||||
# raise Exception, "MariaDB needs to be configured!" | |||||
raise frappe.exceptions.ImproperDBConfigurationError( | |||||
reason="MariaDB default file format is not Barracuda" | |||||
) | |||||
def print_db_config(explanation, config_text): | def print_db_config(explanation, config_text): | ||||