@@ -231,9 +231,8 @@ def get_site_config(sites_path=None, site_path=None): | |||||
if os.path.exists(site_config): | if os.path.exists(site_config): | ||||
config.update(get_file_json(site_config)) | config.update(get_file_json(site_config)) | ||||
elif local.site and not local.flags.new_site: | elif local.site and not local.flags.new_site: | ||||
print("{0} does not exist".format(local.site)) | |||||
print("Site {0} does not exist".format(local.site)) | |||||
sys.exit(1) | sys.exit(1) | ||||
#raise IncorrectSitePath, "{0} does not exist".format(site_config) | |||||
return _dict(config) | return _dict(config) | ||||
@@ -22,7 +22,11 @@ def pass_context(f): | |||||
pr = cProfile.Profile() | pr = cProfile.Profile() | ||||
pr.enable() | pr.enable() | ||||
ret = f(frappe._dict(ctx.obj), *args, **kwargs) | |||||
try: | |||||
ret = f(frappe._dict(ctx.obj), *args, **kwargs) | |||||
except frappe.exceptions.SiteNotSpecifiedError as e: | |||||
click.secho(str(e), fg='yellow') | |||||
sys.exit(1) | |||||
if profile: | if profile: | ||||
pr.disable() | pr.disable() | ||||
@@ -44,8 +48,7 @@ def get_site(context): | |||||
site = context.sites[0] | site = context.sites[0] | ||||
return site | return site | ||||
except (IndexError, TypeError): | except (IndexError, TypeError): | ||||
print('Please specify --site sitename') | |||||
sys.exit(1) | |||||
raise frappe.SiteNotSpecifiedError | |||||
def popen(command, *args, **kwargs): | def popen(command, *args, **kwargs): | ||||
output = kwargs.get('output', True) | output = kwargs.get('output', True) | ||||
@@ -4,6 +4,7 @@ import sys | |||||
import frappe | import frappe | ||||
from frappe.utils import cint | from frappe.utils import cint | ||||
from frappe.commands import pass_context, get_site | from frappe.commands import pass_context, get_site | ||||
from frappe.exceptions import SiteNotSpecifiedError | |||||
def _is_scheduler_enabled(): | def _is_scheduler_enabled(): | ||||
enable_scheduler = False | enable_scheduler = False | ||||
@@ -15,6 +15,7 @@ import frappe | |||||
from frappe import _ | from frappe import _ | ||||
from frappe.commands import get_site, pass_context | from frappe.commands import get_site, pass_context | ||||
from frappe.commands.scheduler import _is_scheduler_enabled | from frappe.commands.scheduler import _is_scheduler_enabled | ||||
from frappe.exceptions import SiteNotSpecifiedError | |||||
from frappe.installer import update_site_config | from frappe.installer import update_site_config | ||||
from frappe.utils import get_site_path, touch_file | from frappe.utils import get_site_path, touch_file | ||||
@@ -368,7 +369,7 @@ def use(site, sites_path='.'): | |||||
sitefile.write(site) | sitefile.write(site) | ||||
print("Current Site set to {}".format(site)) | print("Current Site set to {}".format(site)) | ||||
else: | else: | ||||
print("{} does not exist".format(site)) | |||||
print("Site {} does not exist".format(site)) | |||||
@click.command('backup') | @click.command('backup') | ||||
@click.option('--with-files', default=False, is_flag=True, help="Take backup with files") | @click.option('--with-files', default=False, is_flag=True, help="Take backup with files") | ||||
@@ -1,6 +1,7 @@ | |||||
from __future__ import unicode_literals, absolute_import, print_function | from __future__ import unicode_literals, absolute_import, print_function | ||||
import click | import click | ||||
from frappe.commands import pass_context, get_site | from frappe.commands import pass_context, get_site | ||||
from frappe.exceptions import SiteNotSpecifiedError | |||||
# translation | # translation | ||||
@click.command('build-message-files') | @click.command('build-message-files') | ||||
@@ -6,6 +6,7 @@ import json, os, sys, subprocess | |||||
from distutils.spawn import find_executable | from distutils.spawn import find_executable | ||||
import frappe | import frappe | ||||
from frappe.commands import pass_context, get_site | from frappe.commands import pass_context, get_site | ||||
from frappe.exceptions import SiteNotSpecifiedError | |||||
from frappe.utils import update_progress_bar, get_bench_path | from frappe.utils import update_progress_bar, get_bench_path | ||||
from frappe.utils.response import json_handler | from frappe.utils.response import json_handler | ||||
from coverage import Coverage | from coverage import Coverage | ||||
@@ -376,6 +377,8 @@ def mariadb(context): | |||||
import os | import os | ||||
site = get_site(context) | site = get_site(context) | ||||
if not site: | |||||
raise SiteNotSpecifiedError | |||||
frappe.init(site=site) | frappe.init(site=site) | ||||
# This is assuming you're within the bench instance. | # This is assuming you're within the bench instance. | ||||
@@ -13,6 +13,11 @@ if sys.version_info.major == 2: | |||||
else: | else: | ||||
from builtins import FileNotFoundError | from builtins import FileNotFoundError | ||||
class SiteNotSpecifiedError(Exception): | |||||
def __init__(self, *args, **kwargs): | |||||
self.message = "Please specify --site sitename" | |||||
super(Exception, self).__init__(self.message) | |||||
class ValidationError(Exception): | class ValidationError(Exception): | ||||
http_status_code = 417 | http_status_code = 417 | ||||
@@ -50,14 +50,16 @@ def app_group(ctx, site=False, force=False, verbose=False, profile=False): | |||||
ctx.info_name = '' | ctx.info_name = '' | ||||
def get_sites(site_arg): | def get_sites(site_arg): | ||||
if site_arg and site_arg == 'all': | |||||
if site_arg == 'all': | |||||
return frappe.utils.get_sites() | return frappe.utils.get_sites() | ||||
else: | |||||
if site_arg: | |||||
return [site_arg] | |||||
if os.path.exists('currentsite.txt'): | |||||
with open('currentsite.txt') as f: | |||||
return [f.read().strip()] | |||||
elif site_arg: | |||||
return [site_arg] | |||||
elif os.path.exists('currentsite.txt'): | |||||
with open('currentsite.txt') as f: | |||||
site = f.read().strip() | |||||
if site: | |||||
return [site] | |||||
return [] | |||||
def get_app_commands(app): | def get_app_commands(app): | ||||
if os.path.exists(os.path.join('..', 'apps', app, app, 'commands.py'))\ | if os.path.exists(os.path.join('..', 'apps', app, app, 'commands.py'))\ | ||||