2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-09-19 18:49:01 +00:00

feat: add support to start bench console

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai 2020-02-20 12:08:51 +05:30
parent 6677885e78
commit 0910278efd
No known key found for this signature in database
GPG Key ID: 75507BE256F40CED
2 changed files with 42 additions and 0 deletions

View 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)

View File

@ -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 "$@"