From 27f534f56c397b8219687034241f37cd11bd321f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 12 Nov 2013 17:33:11 +0530 Subject: [PATCH] [minor] lib/wnf.py --python command to start python with path and database connection --- pythonrc.py | 12 ++++++++++++ wnf.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 pythonrc.py diff --git a/pythonrc.py b/pythonrc.py new file mode 100755 index 0000000000..727482a57f --- /dev/null +++ b/pythonrc.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python2.7 + +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# MIT License. See license.txt + +from __future__ import unicode_literals + +import os, sys +sys.path = [".", "lib", "app"] + sys.path + +import webnotes +webnotes.connect(site=os.environ.get("site")) diff --git a/wnf.py b/wnf.py index 3201888e3a..31a9520b38 100755 --- a/wnf.py +++ b/wnf.py @@ -139,6 +139,7 @@ def setup_utilities(parser): parser.add_argument("--serve", action="store_true", help="Run development server") parser.add_argument("--smtp", action="store_true", help="Run smtp debug server", dest="smtp_debug_server") + parser.add_argument("--python", action="store_true", help="get python shell for a site") parser.add_argument("--get_site_status", action="store_true", help="Get site details") parser.add_argument("--update_site_config", nargs=1, metavar="SITE-CONFIG-JSON", @@ -573,6 +574,18 @@ def mysql(site=None): os.execv(msq, [msq, '-u', webnotes.conf.db_name, '-p'+webnotes.conf.db_password, webnotes.conf.db_name, '-h', webnotes.conf.db_host or "localhost"]) webnotes.destroy() +@cmd +def python(site=None): + import webnotes + import commands, os + python = commands.getoutput('which python') + webnotes.init(site=site) + if site: + os.environ["site"] = site + os.environ["PYTHONSTARTUP"] = os.path.join(os.path.dirname(__file__), "pythonrc.py") + os.execv(python, [python]) + webnotes.destroy() + @cmd def smtp_debug_server(): import commands, os