mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 00:37:51 +00:00
Merge pull request #912 from gavindsouza/exec-anywhere
feat: execute bench commands in any sub directories of frappe-bench
This commit is contained in:
commit
50ef73933c
25
bench/cli.py
25
bench/cli.py
@ -1,10 +1,11 @@
|
|||||||
import click
|
import click
|
||||||
import os, sys, logging, json, pwd, subprocess
|
import os, sys, logging, json, pwd, subprocess
|
||||||
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log
|
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_bench_directory
|
||||||
from bench.app import get_apps
|
from bench.app import get_apps
|
||||||
from bench.config.common_site_config import get_config
|
from bench.config.common_site_config import get_config
|
||||||
from bench.commands import bench_command
|
from bench.commands import bench_command
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('bench')
|
logger = logging.getLogger('bench')
|
||||||
from_command_line = False
|
from_command_line = False
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ def cli():
|
|||||||
global from_command_line
|
global from_command_line
|
||||||
from_command_line = True
|
from_command_line = True
|
||||||
|
|
||||||
|
change_working_directory()
|
||||||
check_uid()
|
check_uid()
|
||||||
change_dir()
|
change_dir()
|
||||||
change_uid()
|
change_uid()
|
||||||
@ -114,3 +116,24 @@ def get_frappe_help(bench_path='.'):
|
|||||||
return "Framework commands:\n" + out.split('Commands:')[1]
|
return "Framework commands:\n" + out.split('Commands:')[1]
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def find_parent_bench(path):
|
||||||
|
"""Checks if parent directories are benches"""
|
||||||
|
if is_bench_directory(directory=path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
home_path = os.path.expanduser("~")
|
||||||
|
root_path = os.path.abspath(os.sep)
|
||||||
|
|
||||||
|
if path not in {home_path, root_path}:
|
||||||
|
# NOTE: the os.path.split assumes that given path is absolute
|
||||||
|
parent_dir = os.path.split(path)[0]
|
||||||
|
return find_parent_bench(parent_dir)
|
||||||
|
|
||||||
|
def change_working_directory():
|
||||||
|
"""Allows bench commands to be run from anywhere inside a bench directory"""
|
||||||
|
cur_dir = os.path.abspath(".")
|
||||||
|
bench_path = find_parent_bench(cur_dir)
|
||||||
|
|
||||||
|
if bench_path:
|
||||||
|
os.chdir(bench_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user