fix(commands): raise SiteNotSpecifiedError if site not found in context
This commit is contained in:
parent
ce5df30610
commit
a86ae948f7
8 changed files with 83 additions and 13 deletions
|
|
@ -231,9 +231,8 @@ def get_site_config(sites_path=None, site_path=None):
|
|||
if os.path.exists(site_config):
|
||||
config.update(get_file_json(site_config))
|
||||
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)
|
||||
#raise IncorrectSitePath, "{0} does not exist".format(site_config)
|
||||
|
||||
return _dict(config)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ def get_site(context):
|
|||
site = context.sites[0]
|
||||
return site
|
||||
except (IndexError, TypeError):
|
||||
print('Please specify --site sitename')
|
||||
sys.exit(1)
|
||||
|
||||
def popen(command, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import sys
|
|||
import frappe
|
||||
from frappe.utils import cint
|
||||
from frappe.commands import pass_context, get_site
|
||||
from frappe.exceptions import SiteNotSpecifiedError
|
||||
|
||||
def _is_scheduler_enabled():
|
||||
enable_scheduler = False
|
||||
|
|
@ -30,6 +31,8 @@ def trigger_scheduler_event(context, event):
|
|||
frappe.utils.scheduler.trigger(site, event, now=True)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('enable-scheduler')
|
||||
@pass_context
|
||||
|
|
@ -45,6 +48,8 @@ def enable_scheduler(context):
|
|||
print("Enabled for", site)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('disable-scheduler')
|
||||
@pass_context
|
||||
|
|
@ -60,7 +65,8 @@ def disable_scheduler(context):
|
|||
print("Disabled for", site)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('scheduler')
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import frappe
|
|||
from frappe import _
|
||||
from frappe.commands import get_site, pass_context
|
||||
from frappe.commands.scheduler import _is_scheduler_enabled
|
||||
from frappe.exceptions import SiteNotSpecifiedError
|
||||
from frappe.installer import update_site_config
|
||||
from frappe.utils import get_site_path, touch_file
|
||||
|
||||
|
|
@ -192,6 +193,8 @@ def install_app(context, apps):
|
|||
_install_app(app, verbose=context.verbose)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('list-apps')
|
||||
@pass_context
|
||||
|
|
@ -221,7 +224,8 @@ def add_system_manager(context, email, first_name, last_name, send_welcome_email
|
|||
frappe.db.commit()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('disable-user')
|
||||
@click.argument('email')
|
||||
|
|
@ -252,6 +256,8 @@ def migrate(context, rebuild_website=False, skip_failing=False):
|
|||
migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
print("Compiling Python Files...")
|
||||
compileall.compile_dir('../apps', quiet=1, rx=re.compile('.*node_modules.*'))
|
||||
|
|
@ -264,6 +270,8 @@ def migrate_to(context, frappe_provider):
|
|||
from frappe.integrations.frappe_providers import migrate_to
|
||||
for site in context.sites:
|
||||
migrate_to(site, frappe_provider)
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('run-patch')
|
||||
@click.argument('module')
|
||||
|
|
@ -278,6 +286,8 @@ def run_patch(context, module):
|
|||
frappe.modules.patch_handler.run_single(module, force=context.force)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('reload-doc')
|
||||
@click.argument('module')
|
||||
|
|
@ -294,6 +304,8 @@ def reload_doc(context, module, doctype, docname):
|
|||
frappe.db.commit()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('reload-doctype')
|
||||
@click.argument('doctype')
|
||||
|
|
@ -308,6 +320,8 @@ def reload_doctype(context, doctype):
|
|||
frappe.db.commit()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('add-to-hosts')
|
||||
@pass_context
|
||||
|
|
@ -315,6 +329,8 @@ def add_to_hosts(context):
|
|||
"Add site to hosts"
|
||||
for site in context.sites:
|
||||
frappe.commands.popen('echo 127.0.0.1\t{0} | sudo tee -a /etc/hosts'.format(site))
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('use')
|
||||
@click.argument('site')
|
||||
|
|
@ -328,7 +344,7 @@ def use(site, sites_path='.'):
|
|||
sitefile.write(site)
|
||||
print("Current Site set to {}".format(site))
|
||||
else:
|
||||
print("{} does not exist".format(site))
|
||||
print("Site {} does not exist".format(site))
|
||||
|
||||
@click.command('backup')
|
||||
@click.option('--with-files', default=False, is_flag=True, help="Take backup with files")
|
||||
|
|
@ -361,6 +377,9 @@ def backup(context, with_files=False, backup_path_db=None, backup_path_files=Non
|
|||
print("Private files: ", odb.backup_path_private_files)
|
||||
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
@click.command('remove-from-installed-apps')
|
||||
|
|
@ -376,6 +395,8 @@ def remove_from_installed_apps(context, app):
|
|||
remove_from_installed_apps(app)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('uninstall-app')
|
||||
@click.argument('app')
|
||||
|
|
@ -392,6 +413,8 @@ def uninstall(context, app, dry_run=False, yes=False):
|
|||
remove_app(app, dry_run, yes)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('drop-site')
|
||||
|
|
@ -483,6 +506,8 @@ def set_admin_password(context, admin_password, logout_all_sessions=False):
|
|||
admin_password = None
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('set-last-active-for-user')
|
||||
@click.option('--user', help="Setup last active date for user")
|
||||
|
|
@ -528,6 +553,8 @@ def publish_realtime(context, event, message, room, user, doctype, docname, afte
|
|||
frappe.db.commit()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('browse')
|
||||
@click.argument('site', required=False)
|
||||
|
|
@ -555,6 +582,8 @@ def start_recording(context):
|
|||
for site in context.sites:
|
||||
frappe.init(site=site)
|
||||
frappe.recorder.start()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('stop-recording')
|
||||
|
|
@ -563,6 +592,8 @@ def stop_recording(context):
|
|||
for site in context.sites:
|
||||
frappe.init(site=site)
|
||||
frappe.recorder.stop()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
commands = [
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ def build_message_files(context):
|
|||
frappe.translate.rebuild_all_translation_files()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
@click.command('new-language') #, help="Create lang-code.csv for given app")
|
||||
@pass_context
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ def clear_cache(context):
|
|||
frappe.website.render.clear_cache()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('clear-website-cache')
|
||||
|
|
@ -65,6 +67,8 @@ def clear_website_cache(context):
|
|||
frappe.website.render.clear_cache()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('destroy-all-sessions')
|
||||
|
|
@ -81,6 +85,8 @@ def destroy_all_sessions(context, reason=None):
|
|||
frappe.db.commit()
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('show-config')
|
||||
|
|
@ -117,6 +123,8 @@ def reset_perms(context):
|
|||
reset_perms(d)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('execute')
|
||||
|
|
@ -163,6 +171,8 @@ def execute(context, method, args=None, kwargs=None, profile=False):
|
|||
frappe.destroy()
|
||||
if ret:
|
||||
print(json.dumps(ret, default=json_handler))
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('add-to-email-queue')
|
||||
|
|
@ -197,6 +207,8 @@ def export_doc(context, doctype, docname):
|
|||
frappe.modules.export_doc(doctype, docname)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('export-json')
|
||||
|
|
@ -214,6 +226,8 @@ def export_json(context, doctype, path, name=None):
|
|||
data_import.export_json(doctype, path, name=name)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('export-csv')
|
||||
|
|
@ -230,6 +244,8 @@ def export_csv(context, doctype, path):
|
|||
data_import.export_csv(doctype, path)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('export-fixtures')
|
||||
|
|
@ -245,6 +261,8 @@ def export_fixtures(context, app=None):
|
|||
export_fixtures(app=app)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('import-doc')
|
||||
|
|
@ -267,6 +285,8 @@ def import_doc(context, path, force=False):
|
|||
data_import.import_doc(path, overwrite=context.force)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('import-csv')
|
||||
|
|
@ -577,6 +597,8 @@ def request(context, args=None, path=None):
|
|||
print(frappe.response)
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('make-app')
|
||||
|
|
@ -610,6 +632,8 @@ def set_config(context, key, value, global_ = False, as_dict=False):
|
|||
frappe.init(site=site)
|
||||
update_site_config(key, value, validate=False)
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('version')
|
||||
|
|
@ -658,6 +682,8 @@ def rebuild_global_search(context, static_pages=False):
|
|||
|
||||
finally:
|
||||
frappe.destroy()
|
||||
else:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command('auto-deploy')
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ if sys.version_info.major == 2:
|
|||
else:
|
||||
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):
|
||||
http_status_code = 417
|
||||
|
||||
|
|
|
|||
|
|
@ -50,14 +50,16 @@ def app_group(ctx, site=False, force=False, verbose=False, profile=False):
|
|||
ctx.info_name = ''
|
||||
|
||||
def get_sites(site_arg):
|
||||
if site_arg and site_arg == 'all':
|
||||
if site_arg == 'all':
|
||||
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):
|
||||
if os.path.exists(os.path.join('..', 'apps', app, app, 'commands.py'))\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue