2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-09 08:30:39 +00:00

fix(cli): give warn that commands are not executed in a bench folder

This commit is contained in:
Gavin D'souza 2020-01-10 14:45:13 +05:30
parent bb7310f218
commit ef1a624556

View File

@ -1,6 +1,6 @@
import click
import os, sys, logging, json, pwd, subprocess
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log
from bench.app import get_apps
from bench.config.common_site_config import get_config
from bench.commands import bench_command
@ -43,7 +43,7 @@ def cli():
def check_uid():
if cmd_requires_root() and not is_root():
print('superuser privileges required for this command')
log('superuser privileges required for this command', level=3)
sys.exit(1)
def cmd_requires_root():
@ -71,7 +71,7 @@ def change_uid():
drop_privileges(uid_name=frappe_user, gid_name=frappe_user)
os.environ['HOME'] = pwd.getpwnam(frappe_user).pw_dir
else:
print('You should not run this command as root')
log('You should not run this command as root', level=3)
sys.exit(1)
def old_frappe_cli(bench_path='.'):
@ -93,6 +93,7 @@ def get_frappe_commands(bench_path='.'):
python = get_env_cmd('python', bench_path=bench_path)
sites_path = os.path.join(bench_path, 'sites')
if not os.path.exists(sites_path):
log("WARN: Command not being executed in bench directory", level=3)
return []
try:
output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)