Ver código fonte

added site as explicit webnotes/wnframwork#351

version-14
Rushabh Mehta 11 anos atrás
pai
commit
0fc8635934
6 arquivos alterados com 256 adições e 353 exclusões
  1. +15
    -30
      webnotes/__init__.py
  2. +0
    -1
      webnotes/app.py
  3. +114
    -155
      webnotes/build.py
  4. +10
    -11
      webnotes/install_lib/install.py
  5. +0
    -32
      webnotes/install_lib/setup_public_folder.py
  6. +117
    -124
      webnotes/wnf.py

+ 15
- 30
webnotes/__init__.py Ver arquivo

@@ -78,43 +78,36 @@ message_log = local("message_log")

lang = local("lang")
def init(site_path=None):
def init(site, sites_path=None):
if getattr(local, "initialised", None):
return

if not site_path:
site_path = '.'
if not sites_path:
sites_path = '.'
local.error_log = []
local.site_path = site_path
local.site = site
local.sites_path = sites_path
local.site_path = os.path.join(sites_path, site)
local.message_log = []
local.debug_log = []
local.response = _dict({})
local.lang = "en"
local.request_method = request.method if request else None
local.conf = get_conf()
local.conf = _dict(get_site_config())
local.initialised = True
local.flags = _dict({})
local.rollback_observers = []

setup_module_map()

def get_conf():
site_config = _dict({})
out = get_site_config()
if not out:
raise NotFound()
site_config.update(out)
site_config["site_config"] = out
return site_config

def get_site_config():
site_filepath = os.path.join(local.site_path, "site_config.json")
if os.path.exists(site_filepath):
with open(site_filepath, 'r') as f:
return json.load(f)
else:
return _dict()

def destroy():
"""closes connection and releases werkzeug local"""
@@ -219,10 +212,11 @@ def remove_file(path):
if e.args[0]!=2:
raise
def connect(db_name=None, password=None, site_path=None):
import webnotes.db
init(site_path=site_path or local.site_path)
local.conn = webnotes.db.Database(user=db_name, password=password)
def connect(db_name=None, password=None, site=None):
from db import Database
if site:
init(site)
local.conn = Database(user=db_name, password=password)
local.response = _dict()
local.form_dict = _dict()
local.session = _dict()
@@ -616,12 +610,3 @@ def get_jenv():

def get_template(path):
return get_jenv().get_template(path)

def validate_versions():
return True
config = get_config()
framework_version = semantic_version.Version(config['framework_version'])
spec = semantic_version.Spec(config['requires_framework_version'])
if not spec.match(framework_version):
raise Exception, "Framework version out of sync"


+ 0
- 1
webnotes/app.py Ver arquivo

@@ -81,7 +81,6 @@ if not os.environ.get('NO_STATICS'):
})

def serve(port=8000, profile=False):
webnotes.validate_versions()
global application
from werkzeug.serving import run_simple


+ 114
- 155
webnotes/build.py Ver arquivo

@@ -11,43 +11,39 @@ Build the `public` folders and setup languages
import os, sys, webnotes, json
from cssmin import cssmin


def bundle(no_compress, cms_make=True, path):
def bundle():
"""concat / minify js files"""
# build js files
webnotes.validate_versions()
check_public()
make_site_public_dirs()
check_lang()
bundle = Bundle()
bundle.no_compress = no_compress
bundle.path = path
bundle.make()

if cms_make:
try:
from startup.event_handlers import on_build
on_build()
except ImportError, e:
pass
# clear_pyc_files()
build()
def watch(no_compress):
"""watch and rebuild if necessary"""
import time
bundle = Bundle()
bundle.no_compress = no_compress
build(no_compress=True)

while True:
if bundle.dirty():
bundle.make()
if files_dirty():
build_js_css_packs()
time.sleep(3)

def check_public():
from webnotes.install_lib.setup_public_folder import make
make()
def make_site_public_dirs():
webnotes.init()
for dirs in ['backups', 'files', 'js', 'css']:
dir_path = os.path.join('public', dirs)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
for app in webnotes.get_app_list():
pymodule = webnotes.get_module(app)
pymodule_public_path = os.path.join(os.path.abspath(os.path.dirname(pymodule.__file__)), 'public')

if not os.path.exists(app) and os.path.exists(pymodule_public_path):
os.symlink(pymodule_public_path, app)
def check_lang():
from webnotes.translate import update_translations
update_translations()
@@ -55,146 +51,109 @@ def check_lang():
def clear_pyc_files():
from webnotes.utils import get_base_path
for path, folders, files in os.walk(get_base_path()):
if 'locale' in folders: folders.remove('locale')
for dontwalk in ('locale', '.git', 'public'):
if dontwalk in folders:
folders.remove(dontwalk)
for f in files:
if f.decode("utf-8").endswith(".pyc"):
os.remove(os.path.join(path, f))

def build(no_compress=False):
build_maps = get_build_maps()

for target in build_maps:
pack(target, build_maps[target], no_compress)

self.reset_app_html()

def get_build_maps():
"""get all build.jsons with absolute paths"""
# framework js and css files
pymodules = [webnotes.get_module(app) for app in webnotes.get_app_list(True)]
app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules]

build_maps = {}
for app_path in app_paths:
path = os.path.join(app_path, 'public', 'build.json')
if os.path.exists(path):
with open(path) as f:
ret = {}
for target, sources in bdata.iteritems():
# update app path
sources = [os.path.join(app_path, source) for source in sources]
build_maps[target] = sources
class Bundle:
"""
Concatenate, compress and mix (if required) js+css files from build.json
"""
no_compress = False
timestamps = {}
path = 'public'
def concat(self, filelist, outfile=None):
"""
Concat css and js files into a bundle
"""
from cStringIO import StringIO
out_type = outfile and outfile.split('.')[-1] or 'js'
outtxt = ''
for f in filelist:
suffix = None
if ':' in f:
f, suffix = f.split(':')
if not os.path.exists(f) or os.path.isdir(f):
continue
self.timestamps[f] = os.path.getmtime(f)
# get datas
try:
with open(f, 'r') as infile:
# get file type
ftype = f.split('.')[-1]
return build_maps

data = unicode(infile.read(), 'utf-8', errors='ignore')
timestamps = {}

def pack(target, sources, no_compress):
from cStringIO import StringIO
outtype, outtxt = target.split(".")[-1], ''
jsm = JavascriptMinify()
for f in sources:
suffix = None
if ':' in f: f, suffix = f.split(':')
if not os.path.exists(f) or os.path.isdir(f): continue
timestamps[f] = os.path.getmtime(f)
try:
with open(f, 'r') as sourcefile:
data = unicode(sourcefile.read(), 'utf-8', errors='ignore')
if outtype=="js" and (not no_compress) and suffix!="concat" and (".min." not in f):
tmpin, tmpout = StringIO(data.encode('utf-8')), StringIO()
jsm.minify(tmpin, tmpout)
outtxt += unicode(tmpout.getvalue() or '', 'utf-8').strip('\n')
else:
outtxt += ('\n/*\n *\t%s\n */' % f)
# append
if suffix=='concat' or out_type != 'js' or self.no_compress or ('.min.' in f):
outtxt += '\n' + data + '\n'
else:
jsm = JavascriptMinify()
tmpin = StringIO(data.encode('utf-8'))
tmpout = StringIO()
jsm.minify(tmpin, tmpout)
tmpmin = unicode(tmpout.getvalue() or '', 'utf-8')
tmpmin.strip('\n')
outtxt += tmpmin
except Exception, e:
print "--Error in:" + f + "--"
print webnotes.getTraceback()

if not self.no_compress and out_type == 'css':
outtxt = cssmin(outtxt)
with open(outfile, 'w') as f:
f.write(outtxt.encode("utf-8"))
print "Wrote %s - %sk" % (outfile, str(int(os.path.getsize(outfile)/1024)))

def dirty(self):
"""check if build files are dirty"""

self.make_build_data()
for builddict in self.bdata:
for f in self.get_infiles(builddict):

if ':' in f:
f, suffix = f.split(':')

if not os.path.exists(f) or os.path.isdir(f):
continue
outtxt += '\n' + data + '\n'
if os.path.getmtime(f) != self.timestamps.get(f):
print f + ' dirty'
return True
else:
return False

def make(self):
"""Build (stitch + compress) the file defined in build.json"""
print "Building js and css files..."
self.make_build_data()
for outfile in self.bdata:
infiles = self.bdata[outfile]
self.concat(infiles, os.path.relpath(os.path.join(self.path, outfile), os.curdir))
except Exception, e:
print "--Error in:" + f + "--"
print webnotes.getTraceback()

if not no_compress and out_type == 'css':
outtxt = cssmin(outtxt)
with open(outfile, 'w') as f:
f.write(outtxt.encode("utf-8"))
self.reset_app_html()
def reset_app_html(self):
import webnotes
print "Wrote %s - %sk" % (outfile, str(int(os.path.getsize(outfile)/1024)))

def files_dirty():
for target, sources in build_maps.iteritems():
for f in sources:
if ':' in f: f, suffix = f.split(':')
if not os.path.exists(f) or os.path.isdir(f): continue
if os.path.getmtime(f) != timestamps.get(f):
print f + ' dirty'
return True
else:
return False

app_html_path = os.path.join(self.path, 'app.html')
if os.path.exists(app_html_path):
os.remove(app_html_path)
# splash_path = os.path.join(self.path, )
# splash = ""
# if os.path.exists("public/app/images/splash.svg"):
# with open("public/app/images/splash.svg") as splash_file:
# splash = splash_file.read()
#
# with open('lib/public/html/app.html', 'r') as app_html:
# data = app_html.read()
# data = data % {
# "_version_number": webnotes.generate_hash(),
# "splash": splash
# }
with open(app_html_path, 'w') as new_app_html:
new_app_html.write(data)
# def reset_app_html(self):
# import webnotes
#
# app_html_path = os.path.join(self.path, 'app.html')
# if os.path.exists(app_html_path):
# os.remove(app_html_path)
#
# # splash_path = os.path.join(self.path, )
# # splash = ""
# # if os.path.exists("public/app/images/splash.svg"):
# # with open("public/app/images/splash.svg") as splash_file:
# # splash = splash_file.read()
# #
# # with open('lib/public/html/app.html', 'r') as app_html:
# # data = app_html.read()
# # data = data % {
# # "_version_number": webnotes.generate_hash(),
# # "splash": splash
# # }
# with open(app_html_path, 'w') as new_app_html:
# new_app_html.write(data)
def make_build_data(self):
"""merge build.json and lib/build.json"""
# framework js and css files

def process_app_build(app_path, bdata):
ret = {}
for outfile, infiles in bdata.iteritems():
infiles = [os.path.join(app_path, infile) for infile in infiles]
ret[outfile] = infiles
return ret

pymodules = [webnotes.get_module(app) for app in webnotes.get_app_list(True)]
app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules]

bdata = {}
for app_path in app_paths:
path = os.path.join(app_path, 'public', 'build.json')
if os.path.exists(path):
with open(path) as f:
bdata.update(process_app_build(app_path, json.load(f)))
self.bdata = bdata


+ 10
- 11
webnotes/install_lib/install.py Ver arquivo

@@ -16,11 +16,9 @@ from webnotes.model.sync import sync_for
from webnotes.utils import cstr

class Installer:
def __init__(self, root_login, root_password=None, db_name=None, site_path=None, site_config=None):
make_conf(db_name, site_path=site_path, site_config=site_config)
self.site_path = site_path
def __init__(self, root_login, root_password=None, db_name=None, site_config=None):
make_conf(db_name, site_config=site_config)
self.make_connection(root_login, root_password)

webnotes.local.conn = self.conn
@@ -67,7 +65,7 @@ class Installer:
# close root connection
self.conn.close()

webnotes.connect(db_name=db_name, site_path=self.site_path)
webnotes.connect(db_name=db_name)
self.dbman = DbManager(webnotes.conn)
# import in db_name
@@ -192,13 +190,14 @@ class Installer:
`password` VARCHAR(180) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8""")
def make_conf(db_name=None, db_password=None, site_path=None, site_config=None):
make_site_config(site_path, db_name, db_password, site_config)
def make_conf(db_name=None, db_password=None, site_config=None):
site = webnotes.local.site
make_site_config(db_name, db_password, site_config)
webnotes.destroy()
webnotes.init(site_path=site_path)
webnotes.init(site)

def make_site_config(site_path, db_name=None, db_password=None, site_config=None):
site_file = os.path.join(site_path, "site_config.json")
def make_site_config(db_name=None, db_password=None, site_config=None):
site_file = os.path.join(webnotes.local.site_path, "site_config.json")
if not os.path.exists(site_file):
if not (site_config and isinstance(site_config, dict)):


+ 0
- 32
webnotes/install_lib/setup_public_folder.py Ver arquivo

@@ -1,32 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

# make public folders

from __future__ import unicode_literals
import os
import webnotes

def make(public_path=None):
"""make public folder symlinks if missing"""
webnotes.init()

if not public_path:
public_path = 'public'
# setup standard folders
for dirs in ['backups', 'files', 'js', 'css']:
dir_path = os.path.join(public_path, dirs)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
symlinks = []
for app in webnotes.get_app_list():
pymodule = webnotes.get_module(app)
pymodule_path = os.path.abspath(os.path.dirname(pymodule.__file__))
symlinks.append([app, os.path.join(pymodule_path, 'public')])

for link in symlinks:
if not os.path.exists(link[0]) and os.path.exists(link[1]):
os.symlink(link[1], link[0])

+ 117
- 124
webnotes/wnf.py Ver arquivo

@@ -11,14 +11,19 @@ import webnotes
def main():
parsed_args = webnotes._dict(vars(setup_parser()))
fn = get_function(parsed_args)
if not parsed_args.get("site_path"):
parsed_args["site_path"] = "."
if parsed_args.get("site_path")=="all":
for site_path in get_sites():
if not parsed_args.get("sites_path"):
parsed_args["sites_path"] = "."
if not parsed_args.get("site"):
print "Site argument required"
return
if parsed_args.get("site")=="all":
for site in get_sites():
args = parsed_args.copy()
args["site_path"] = site_path
args["site"] = site
webnotes.init(site)
run(fn, args)
else:
webnotes.init(parsed_args.get("site"))
run(fn, parsed_args)

def cmd(fn):
@@ -51,9 +56,9 @@ def get_function(args):
def get_sites():
import os
import conf
return [site_path for site_path in os.listdir(conf.sites_dir)
if not os.path.islink(os.path.join(conf.sites_dir, site_path))
and os.path.isdir(os.path.join(conf.sites_dir, site_path))]
return [site for site in os.listdir(conf.sites_dir)
if not os.path.islink(os.path.join(conf.sites_dir, site))
and os.path.isdir(os.path.join(conf.sites_dir, site))]
def setup_parser():
import argparse
@@ -63,13 +68,13 @@ def setup_parser():
setup_utilities(parser)
setup_translation(parser)
parser.add_argument("site")
# common
parser.add_argument("-f", "--force", default=False, action="store_true",
help="Force execution where applicable (look for [-f] in help)")
parser.add_argument("--quiet", default=True, action="store_false", dest="verbose",
help="Don't show verbose output where applicable")
parser.add_argument("--site_path", nargs="?", metavar="site_path-NAME or all",
help="Run for a particular site_path")
return parser.parse_args()
@@ -118,39 +123,39 @@ def setup_utilities(parser):
parser.add_argument("--backup", default=False, action="store_true",
help="Take backup of database in backup folder [--with_files]")
parser.add_argument("--move", default=False, action="store_true",
help="Move site_path to different directory defined by --dest_dir")
help="Move site to different directory defined by --dest_dir")
parser.add_argument("--dest_dir", nargs=1, metavar="DEST-DIR",
help="Move site_path to different directory")
help="Move site to different directory")
parser.add_argument("--with_files", default=False, action="store_true",
help="Also take backup of files")
parser.add_argument("--domain", nargs="*",
help="Get or set domain in Website_path Settings")
help="Get or set domain in Website Settings")
parser.add_argument("--make_conf", nargs="*", metavar=("DB-NAME", "DB-PASSWORD"),
help="Create new conf.py file")
parser.add_argument("--make_custom_server_script", nargs=1, metavar="DOCTYPE",
help="Create new conf.py file")
parser.add_argument("--set_admin_password", metavar='ADMIN-PASSWORD', nargs=1,
help="Set administrator password")
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site_path")
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site")
parser.add_argument("--serve", action="store_true", help="Run development server")
parser.add_argument("--profile", action="store_true", help="enable profiling in 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_path")
parser.add_argument("--ipython", action="store_true", help="get ipython shell for a site_path")
parser.add_argument("--get_site_status", action="store_true", help="Get site_path details")
parser.add_argument("--python", action="store_true", help="get python shell for a site")
parser.add_argument("--ipython", action="store_true", help="get ipython 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_path-CONFIG-JSON",
help="Update site_config.json for a given --site_path")
metavar="site-CONFIG-JSON",
help="Update site_config.json for a given site")
parser.add_argument("--port", default=8000, type=int, help="port for development server")
# clear
parser.add_argument("--clear_web", default=False, action="store_true",
help="Clear website_path cache")
help="Clear website cache")
parser.add_argument("--build_sitemap", default=False, action="store_true",
help="Build Website_path Sitemap")
help="Build Website Sitemap")
parser.add_argument("--rebuild_sitemap", default=False, action="store_true",
help="Rebuild Website_path Sitemap")
help="Rebuild Website Sitemap")
parser.add_argument("--clear_cache", default=False, action="store_true",
help="Clear cache, doctype cache and defaults")
parser.add_argument("--reset_perms", default=False, action="store_true",
@@ -197,72 +202,66 @@ def setup_translation(parser):

# install
@cmd
def install(db_name, source_sql=None, site_path=None, verbose=True, force=False, root_password=None, site_config=None, admin_password='admin'):
def install(db_name, source_sql=None, verbose=True, force=False, root_password=None, site_config=None, admin_password='admin'):
from webnotes.install_lib.install import Installer
inst = Installer('root', db_name=db_name, site_path=site_path, root_password=root_password, site_config=site_config)
inst = Installer('root', db_name=db_name, root_password=root_password, site_config=site_config)
inst.install(db_name, verbose=verbose, force=force, admin_password=admin_password)
webnotes.destroy()

@cmd
def reinstall(site_path=None, verbose=True):
webnotes.init(site_path=site_path)
install(webnotes.conf.db_name, site_path=site_path, verbose=verbose, force=True)
def reinstall(verbose=True):
install(webnotes.conf.db_name, verbose=verbose, force=True)

@cmd
def restore(db_name, source_sql, site_path=None, verbose=True, force=False):
install(db_name, source_sql, site_path=site_path, verbose=verbose, force=force)
def restore(db_name, source_sql, verbose=True, force=False):
install(db_name, source_sql, verbose=verbose, force=force)

@cmd
def install_fixtures(site_path=None):
webnotes.init(site_path=site_path)
def install_fixtures():
from webnotes.install_lib.install import install_fixtures
install_fixtures()
webnotes.destroy()

@cmd
def add_system_manager(email, first_name=None, last_name=None, site_path=None):
webnotes.connect(site_path=site_path)
def add_system_manager(email, first_name=None, last_name=None):
webnotes.connect()
webnotes.profile.add_system_manager(email, first_name, last_name)
webnotes.conn.commit()
webnotes.destroy()

@cmd
def make_demo(site_path=None):
def make_demo():
import utilities.demo.make_demo
webnotes.init(site_path=site_path)
utilities.demo.make_demo.make()
webnotes.destroy()

@cmd
def make_demo_fresh(site_path=None):
def make_demo_fresh():
import utilities.demo.make_demo
webnotes.init(site_path=site_path)
utilities.demo.make_demo.make(reset=True)
webnotes.destroy()
# utilities

@cmd
def update(remote=None, branch=None, site_path=None, reload_gunicorn=False):
pull(remote=remote, branch=branch, site_path=site_path)
def update(remote=None, branch=None, reload_gunicorn=False):
pull(remote=remote, branch=branch)

# maybe there are new framework changes, any consequences?
reload(webnotes)
if not site_path: build()

latest(site_path=site_path)
build()
latest()
if reload_gunicorn:
import subprocess
subprocess.check_output("killall -HUP gunicorn".split())

@cmd
def latest(site_path=None, verbose=True):
def latest(verbose=True):
import webnotes.modules.patch_handler
import webnotes.model.sync
from webnotes.website_path.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect(site_path=site_path)
webnotes.connect()
try:
# run patches
@@ -274,7 +273,7 @@ def latest(site_path=None, verbose=True):
# sync
webnotes.model.sync.sync_all()
# build website_path config if any changes in templates etc.
# build website config if any changes in templates etc.
build_website_sitemap_config()
except webnotes.modules.patch_handler.PatchError, e:
@@ -284,16 +283,16 @@ def latest(site_path=None, verbose=True):
webnotes.destroy()

@cmd
def sync_all(site_path=None, force=False):
def sync_all(force=False):
import webnotes.model.sync
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.model.sync.sync_all(force=force)
webnotes.destroy()

@cmd
def patch(patch_module, site_path=None, force=False):
def patch(patch_module, force=False):
import webnotes.modules.patch_handler
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.local.patch_log_list = []
webnotes.modules.patch_handler.run_single(patch_module, force=force)
print "\n".join(webnotes.local.patch_log_list)
@@ -307,21 +306,21 @@ def update_all_sites(remote=None, branch=None, verbose=True):
reload(webnotes)
build()
for site_path in get_sites():
latest(site_path=site_path, verbose=verbose)
for site in get_sites():
webnotes.init(site)
latest(verbose=verbose)

@cmd
def reload_doc(module, doctype, docname, site_path=None, force=False):
webnotes.connect(site_path=site_path)
def reload_doc(module, doctype, docname, force=False):
webnotes.connect()
webnotes.reload_doc(module, doctype, docname, force=force)
webnotes.conn.commit()
webnotes.destroy()

@cmd
def build(site_path):
def build():
import webnotes.build
import webnotes
webnotes.init(site_path)
webnotes.build.bundle(False)

@cmd
@@ -330,9 +329,9 @@ def watch():
webnotes.build.watch(True)

@cmd
def backup(site_path=None, with_files=False, verbose=True, backup_path_db=None, backup_path_files=None):
def backup(with_files=False, verbose=True, backup_path_db=None, backup_path_files=None):
from webnotes.utils.backups import scheduled_backup
webnotes.connect(site_path=site_path)
webnotes.connect()
odb = scheduled_backup(ignore_files=not with_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files)
if verbose:
from webnotes.utils import now
@@ -343,18 +342,17 @@ def backup(site_path=None, with_files=False, verbose=True, backup_path_db=None,
return odb

@cmd
def move(site_path=None, dest_dir=None):
def move(dest_dir=None):
import os
if not dest_dir:
raise Exception, "--dest_dir is required for --move"
if not os.path.isdir(dest_dir):
raise Exception, "destination is not a directory or does not exist"

webnotes.init(site_path=site_path)
old_path = webnotes.utils.get_site_path()
new_path = os.path.join(dest_dir, site_path)
old_path = webnotes.utils.get_site()
new_path = os.path.join(dest_dir, site)

# check if site_path dump of same name already exists
# check if site dump of same name already exists
site_dump_exists = True
count = 0
while site_dump_exists:
@@ -367,61 +365,61 @@ def move(site_path=None, dest_dir=None):
return os.path.basename(final_new_path)

@cmd
def domain(host_url=None, site_path=None):
webnotes.connect(site_path=site_path)
def domain(host_url=None):
webnotes.connect()
if host_url:
webnotes.conn.set_value("Website_path Settings", None, "subdomain", host_url)
webnotes.conn.set_value("Website Settings", None, "subdomain", host_url)
webnotes.conn.commit()
else:
print webnotes.conn.get_value("Website_path Settings", None, "subdomain")
print webnotes.conn.get_value("Website Settings", None, "subdomain")
webnotes.destroy()

@cmd
def make_conf(db_name=None, db_password=None, site_path=None, site_config=None):
def make_conf(db_name=None, db_password=None, site_config=None):
from webnotes.install_lib.install import make_conf
make_conf(db_name=db_name, db_password=db_password, site_path=site_path, site_config=site_config)
make_conf(db_name=db_name, db_password=db_password, site_config=site_config)
@cmd
def make_custom_server_script(doctype, site_path=None):
def make_custom_server_script(doctype):
from webnotes.core.doctype.custom_script.custom_script import make_custom_server_script_file
webnotes.connect(site_path=site_path)
webnotes.connect()
make_custom_server_script_file(doctype)
webnotes.destroy()

# clear
@cmd
def clear_cache(site_path=None):
def clear_cache():
import webnotes.sessions
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.sessions.clear_cache()
webnotes.destroy()

@cmd
def clear_web(site_path=None):
def clear_web():
import webnotes.webutils
webnotes.connect(site_path=site_path)
from webnotes.website_path.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect()
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
build_website_sitemap_config()
webnotes.webutils.clear_cache()
webnotes.destroy()

@cmd
def build_sitemap(site_path=None):
from webnotes.website_path.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect(site_path=site_path)
def build_sitemap():
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect()
build_website_sitemap_config()
webnotes.destroy()

@cmd
def rebuild_sitemap(site_path=None):
from webnotes.website_path.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config
webnotes.connect(site_path=site_path)
def rebuild_sitemap():
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config
webnotes.connect()
rebuild_website_sitemap_config()
webnotes.destroy()

@cmd
def reset_perms(site_path=None):
webnotes.connect(site_path=site_path)
def reset_perms():
webnotes.connect()
for d in webnotes.conn.sql_list("""select name from `tabDocType`
where ifnull(istable, 0)=0 and ifnull(custom, 0)=0"""):
webnotes.clear_cache(doctype=d)
@@ -430,20 +428,19 @@ def reset_perms(site_path=None):

# scheduler
@cmd
def run_scheduler(site_path=None):
def run_scheduler():
from webnotes.utils.file_lock import create_lock, delete_lock
import webnotes.utils.scheduler
webnotes.init(site_path=site_path)
if create_lock('scheduler'):
webnotes.connect(site_path=site_path)
webnotes.connect()
print webnotes.utils.scheduler.execute()
delete_lock('scheduler')
webnotes.destroy()

@cmd
def run_scheduler_event(event, site_path=None):
def run_scheduler_event(event):
import webnotes.utils.scheduler
webnotes.connect(site_path=site_path)
webnotes.connect()
print webnotes.utils.scheduler.trigger("execute_" + event)
webnotes.destroy()
@@ -455,66 +452,66 @@ def replace(search_regex, replacement, extn, force=False):
# import/export
@cmd
def export_doc(doctype, docname, site_path=None):
def export_doc(doctype, docname):
import webnotes.modules
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.modules.export_doc(doctype, docname)
webnotes.destroy()

@cmd
def export_doclist(doctype, name, path, site_path=None):
def export_doclist(doctype, name, path):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
webnotes.connect()
data_import_tool.export_json(doctype, name, path)
webnotes.destroy()
@cmd
def export_csv(doctype, path, site_path=None):
def export_csv(doctype, path):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
webnotes.connect()
data_import_tool.export_csv(doctype, path)
webnotes.destroy()

@cmd
def import_doclist(path, site_path=None, force=False):
def import_doclist(path, force=False):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
webnotes.connect()
data_import_tool.import_doclist(path, overwrite=force)
webnotes.destroy()
# translation
@cmd
def build_message_files(site_path=None):
def build_message_files():
import webnotes.translate
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.translate.build_message_files()
webnotes.destroy()

@cmd
def export_messages(lang, outfile, site_path=None):
def export_messages(lang, outfile):
import webnotes.translate
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.translate.export_messages(lang, outfile)
webnotes.destroy()

@cmd
def import_messages(lang, infile, site_path=None):
def import_messages(lang, infile):
import webnotes.translate
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.translate.import_messages(lang, infile)
webnotes.destroy()
@cmd
def google_translate(lang, infile, outfile, site_path=None):
def google_translate(lang, infile, outfile):
import webnotes.translate
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.translate.google_translate(lang, infile, outfile)
webnotes.destroy()

@cmd
def translate(lang, site_path=None):
def translate(lang):
import webnotes.translate
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.translate.translate(lang)
webnotes.destroy()

@@ -529,7 +526,6 @@ def git(param):

def get_remote_and_branch(remote=None, branch=None):
if not (remote and branch):
webnotes.init()
if not webnotes.conf.branch:
raise Exception("Please specify remote and branch")
@@ -562,39 +558,37 @@ def checkout(branch):
git(("checkout", branch))

@cmd
def set_admin_password(admin_password, site_path=None):
def set_admin_password(admin_password):
import webnotes
webnotes.connect(site_path=site_path)
webnotes.connect()
webnotes.conn.sql("""update __Auth set `password`=password(%s)
where user='Administrator'""", (admin_password,))
webnotes.conn.commit()
webnotes.destroy()

@cmd
def mysql(site_path=None):
def mysql():
import webnotes
import commands, os
msq = commands.getoutput('which mysql')
webnotes.init(site_path=site_path)
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", "-A"])
webnotes.destroy()

@cmd
def python(site_path=None):
def python():
import webnotes
import commands, os
python = commands.getoutput('which python')
webnotes.init(site_path=site_path)
if site_path:
os.environ["site_path"] = site_path
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 ipython(site_path=None):
def ipython():
import webnotes
webnotes.connect(site_path=site_path)
webnotes.connect()
import IPython
IPython.embed()

@@ -656,7 +650,7 @@ def search_replace_with_prompt(fpath, txt1, txt2, force=False):
print colored('Updated', 'green')

@cmd
def get_site_status(site_path=None, verbose=False):
def get_site_status(verbose=False):
import webnotes
import webnotes.utils
from webnotes.profile import get_system_managers
@@ -664,7 +658,7 @@ def get_site_status(site_path=None, verbose=False):
get_website_users, get_active_website_users
import json
webnotes.connect(site_path=site_path)
webnotes.connect()
ret = {
'last_backup_on': webnotes.local.conf.last_backup_on,
'active_users': get_active_users(),
@@ -697,15 +691,14 @@ def get_site_status(site_path=None, verbose=False):
return ret

@cmd
def update_site_config(site_config, site_path, verbose=False):
def update_site_config(site_config, verbose=False):
import json
if isinstance(site_config, basestring):
site_config = json.loads(site_config)
webnotes.init(site_path=site_path)
webnotes.conf.site_config.update(site_config)
site_config_path = webnotes.get_conf_path(webnotes.conf.sites_dir, site_path)
site_config_path = webnotes.get_conf_path(webnotes.conf.sites_dir)
with open(site_config_path, "w") as f:
json.dump(webnotes.conf.site_config, f, indent=1, sort_keys=True)


Carregando…
Cancelar
Salvar