mirror of
https://github.com/frappe/frappe_docker.git
synced 2024-12-23 10:38:58 +00:00
feat: add support to start bench console
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
parent
6677885e78
commit
0910278efd
25
build/frappe-worker/commands/console.py
Normal file
25
build/frappe-worker/commands/console.py
Normal file
@ -0,0 +1,25 @@
|
||||
import sys
|
||||
import frappe
|
||||
import IPython
|
||||
|
||||
from frappe.utils import get_sites
|
||||
|
||||
|
||||
def console(site):
|
||||
"Start ipython console for a site"
|
||||
if site not in get_sites():
|
||||
print("Site {0} does not exist on the current bench".format(site))
|
||||
return
|
||||
|
||||
frappe.init(site=site)
|
||||
frappe.connect()
|
||||
frappe.local.lang = frappe.db.get_default("lang")
|
||||
all_apps = frappe.get_installed_apps()
|
||||
for app in all_apps:
|
||||
locals()[app] = __import__(app)
|
||||
print("Apps in this namespace:\n{}".format(", ".join(all_apps)))
|
||||
IPython.embed(display_banner="", header="")
|
||||
|
||||
|
||||
site = sys.argv[-1]
|
||||
console(site)
|
@ -151,6 +151,23 @@ elif [ "$1" = 'backup' ]; then
|
||||
python /home/frappe/frappe-bench/commands/backup.py
|
||||
fi
|
||||
|
||||
elif [ "$1" = 'console' ]; then
|
||||
|
||||
if [[ -z "$2" ]]; then
|
||||
echo "Need to specify a sitename with the command:"
|
||||
echo "console <sitename>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$RUN_AS_ROOT" ]]; then
|
||||
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
|
||||
&& python /home/frappe/frappe-bench/commands/console.py $2"
|
||||
exit
|
||||
else
|
||||
. /home/frappe/frappe-bench/env/bin/activate
|
||||
python /home/frappe/frappe-bench/commands/console.py "$2"
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
exec su frappe -c "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user