Bläddra i källkod

[minor] lib/wnf.py --python command to start python with path and database connection

version-14
Anand Doshi 11 år sedan
förälder
incheckning
27f534f56c
2 ändrade filer med 25 tillägg och 0 borttagningar
  1. +12
    -0
      pythonrc.py
  2. +13
    -0
      wnf.py

+ 12
- 0
pythonrc.py Visa fil

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

+ 13
- 0
wnf.py Visa fil

@@ -139,6 +139,7 @@ def setup_utilities(parser):
parser.add_argument("--serve", action="store_true", help="Run development server") parser.add_argument("--serve", action="store_true", help="Run development server")
parser.add_argument("--smtp", action="store_true", help="Run smtp debug server", parser.add_argument("--smtp", action="store_true", help="Run smtp debug server",
dest="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("--get_site_status", action="store_true", help="Get site details")
parser.add_argument("--update_site_config", nargs=1, parser.add_argument("--update_site_config", nargs=1,
metavar="SITE-CONFIG-JSON", 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"]) 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() 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 @cmd
def smtp_debug_server(): def smtp_debug_server():
import commands, os import commands, os


Laddar…
Avbryt
Spara