step 0: install

This commit is contained in:
Rushabh Mehta 2013-12-11 15:31:32 +05:30
parent 183865950c
commit 7b8b315de8
31 changed files with 299 additions and 488 deletions

View file

@ -18,7 +18,7 @@ setup(
install_requires=install_requires,
entry_points= {
'console_scripts':[
'wnf = webnotes.wnf:main'
'webnotes = webnotes.wnf:main'
]
}
)

View file

@ -11,7 +11,7 @@ from werkzeug.local import Local
from werkzeug.exceptions import NotFound
from MySQLdb import ProgrammingError as SQLError
import os
import os, sys, importlib
import json
import semantic_version
@ -77,23 +77,42 @@ debug_log = local("debug_log")
message_log = local("message_log")
lang = local("lang")
def init(site=None):
def init(site_path=None):
if getattr(local, "initialised", None):
return
local.error_log = []
local.site = site
local.site_path = site_path
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(site)
local.conf = get_conf()
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)
def destroy():
"""closes connection and releases werkzeug local"""
if conn:
@ -197,9 +216,9 @@ def remove_file(path):
if e.args[0]!=2:
raise
def connect(db_name=None, password=None, site=None):
def connect(db_name=None, password=None, site_path=None):
import webnotes.db
init(site=site)
init(site_path=site_path or local.site_path)
local.conn = webnotes.db.Database(user=db_name, password=password)
local.response = _dict()
local.form_dict = _dict()
@ -453,9 +472,9 @@ def reset_perms(doctype):
clear_perms(doctype)
reload_doc(conn.get_value("DocType", doctype, "module"), "DocType", doctype, force=True)
def reload_doc(module, dt=None, dn=None, plugin=None, force=False):
def reload_doc(module, dt=None, dn=None, force=False):
import webnotes.modules
return webnotes.modules.reload_doc(module, dt, dn, plugin=plugin, force=force)
return webnotes.modules.reload_doc(module, dt, dn, force=force)
def rename_doc(doctype, old, new, debug=0, force=False, merge=False):
from webnotes.model.rename_doc import rename_doc
@ -466,9 +485,32 @@ def insert(doclist):
return webnotes.model.insert(doclist)
def get_module(modulename):
__import__(modulename)
import sys
return sys.modules[modulename]
return importlib.import_module(modulename)
def get_module_list(app_name):
return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
def get_app_list():
return get_file_items(os.path.join(local.site_path, "apps.txt"))
def setup_module_map():
_cache = cache()
local.app_modules = _cache.get_value("app_modules")
local.module_app = _cache.get_value("module_app")
if not local.app_modules:
local.module_app, local.app_modules = {}, {}
for app in ["webnotes"] + get_app_list():
for module in get_module_list(app):
local.module_app[module] = app
local.app_modules.setdefault(app, [])
local.app_modules[app].append(module)
_cache.set_value("app_modules", local.app_modules)
_cache.set_value("module_app", local.module_app)
def get_file_items(path):
with open(path, "r") as f: return f.read().split()
def get_method(method_string):
modulename = '.'.join(method_string.split('.')[:-1])
@ -569,65 +611,6 @@ def get_jenv():
def get_template(path):
return get_jenv().get_template(path)
_config = None
def get_config():
global _config
if not _config:
import webnotes.utils, json
_config = _dict()
def update_config(path):
try:
with open(path, "r") as configfile:
this_config = json.loads(configfile.read())
for key, val in this_config.items():
if isinstance(val, dict):
_config.setdefault(key, _dict()).update(val)
else:
_config[key] = val
except IOError:
pass
update_config(webnotes.utils.get_path("lib", "config.json"))
update_config(webnotes.utils.get_path("app", "config.json"))
return _config
def get_conf(site):
# TODO Should be heavily cached!
import conf
site_config = _dict({})
conf = site_config.update(conf.__dict__)
if not conf.get("files_path"):
conf["files_path"] = os.path.join("public", "files")
if not conf.get("plugins_path"):
conf["plugins_path"] = "plugins"
if conf.sites_dir and site:
out = get_site_config(conf.sites_dir, site)
if not out:
raise NotFound()
site_config.update(out)
site_config["site_config"] = out
site_config['site'] = site
return site_config
else:
return conf
def get_site_config(sites_dir, site):
conf_path = get_conf_path(sites_dir, site)
if os.path.exists(conf_path):
with open(conf_path, 'r') as f:
return json.load(f)
def get_conf_path(sites_dir, site):
from webnotes.utils import get_site_base_path
return os.path.join(get_site_base_path(sites_dir=sites_dir,
hostname=site), 'site_config.json')
def validate_versions():
config = get_config()
framework_version = semantic_version.Version(config['framework_version'])

View file

@ -22,6 +22,7 @@ import webnotes.auth
import webnotes.webutils
local_manager = LocalManager([webnotes.local])
site_path = None
def handle_session_stopped():
res = Response("""<html>
@ -41,8 +42,7 @@ def application(request):
webnotes.local.request = request
try:
site = webnotes.utils.get_site_name(request.host)
webnotes.init(site=site)
webnotes.init(site_path=site_path or request.host)
webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
for k, v in (request.form or request.args).iteritems() })
@ -83,6 +83,7 @@ if not os.environ.get('NO_STATICS'):
def serve(port=8000, profile=False):
webnotes.validate_versions()
global application
from werkzeug.serving import run_simple
if profile:

View file

@ -55,7 +55,6 @@ def get_bootinfo():
# add docs
bootinfo['docs'] = doclist
# plugins
try:
import startup.boot
startup.boot.boot_session(bootinfo)

View file

@ -30,7 +30,7 @@ class DocType:
def on_update(self):
# validate field
from core.doctype.doctype.doctype import validate_fields_for_doctype
from webnotes.core.doctype.doctype.doctype import validate_fields_for_doctype
validate_fields_for_doctype(self.doc.dt)

View file

@ -17,27 +17,3 @@ class DocType:
def on_trash(self):
webnotes.clear_cache(doctype=self.doc.dt)
def make_custom_server_script_file(doctype, script=None):
import os
from webnotes.plugins import get_path
file_path = get_path(None, "DocType", doctype)
if os.path.exists(file_path):
raise IOError(file_path + " already exists")
# create folder if not exists
webnotes.create_folder(os.path.dirname(file_path))
# create file
custom_script = """from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, cstr, flt
from webnotes.model.doc import Document
from webnotes.model.code import get_obj
from webnotes import msgprint, _
class CustomDocType(DocType):
{script}""".format(script=script or "\tpass")
with open(file_path, "w") as f:
f.write(custom_script.encode("utf-8"))

View file

@ -129,7 +129,7 @@ class DocType:
"""
if self.doc.doc_type:
from webnotes.model import doc
from core.doctype.doctype.doctype import validate_fields_for_doctype
from webnotes.core.doctype.doctype.doctype import validate_fields_for_doctype
this_doclist = webnotes.doclist([self.doc] + self.doclist)
ref_doclist = self.get_ref_doclist()

View file

@ -34,7 +34,7 @@ class DocType:
it will write out a .html file
"""
from webnotes import conf
from core.doctype.doctype.doctype import make_module_and_roles
from webnotes.core.doctype.doctype.doctype import make_module_and_roles
make_module_and_roles(self.doclist, "Page Role")
if not webnotes.flags.in_import and getattr(conf,'developer_mode', 0) and self.doc.standard=='Yes':

View file

@ -63,7 +63,7 @@ def get_args():
def get_html(doc, doclist):
from jinja2 import Environment
from core.doctype.print_format.print_format import get_print_format
from webnotes.core.doctype.print_format.print_format import get_print_format
template = Environment().from_string(get_print_format(doc.doctype,
webnotes.form_dict.format))

View file

@ -51,7 +51,7 @@ class DocType:
(self.doc.field_name, self.doc.doc_type), as_dict = 1)[0]
def on_update(self):
from core.doctype.doctype.doctype import validate_fields_for_doctype
from webnotes.core.doctype.doctype.doctype import validate_fields_for_doctype
validate_fields_for_doctype(self.doc.doc_type)
def make_property_setter(doctype, fieldname, property, value, property_type, for_doctype = False):

View file

@ -33,8 +33,3 @@ class DocType:
if self.doc.is_standard == 'Yes' and (conf.get('developer_mode') or 0) == 1:
export_to_files(record_list=[['Report', self.doc.name]],
record_module=webnotes.conn.get_value("DocType", self.doc.ref_doctype, "module"))
elif self.doc.is_standard == 'No' and self.doc.report_type == "Script Report":
from webnotes.plugins import get_plugin_name
export_to_files(record_list=[['Report', self.doc.name]],
record_module=webnotes.conn.get_value("DocType", self.doc.ref_doctype, "module"),
plugin=get_plugin_name("Report", self.doc.name), create_init=False)

View file

@ -66,7 +66,7 @@ def update_match(name, doctype, match=""):
webnotes.defaults.clear_cache()
def validate_and_reset(doctype, for_remove=False):
from core.doctype.doctype.doctype import validate_permissions_for_doctype
from webnotes.core.doctype.doctype.doctype import validate_permissions_for_doctype
validate_permissions_for_doctype(doctype, for_remove)
clear_doctype_cache(doctype)

View file

@ -16,9 +16,10 @@ 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=None, site_config=None):
make_conf(db_name, site=site, site_config=site_config)
self.site = site
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
self.make_connection(root_login, root_password)
@ -66,7 +67,7 @@ class Installer:
# close root connection
self.conn.close()
webnotes.connect(db_name=db_name, site=self.site)
webnotes.connect(db_name=db_name, site_path=self.site_path)
self.dbman = DbManager(webnotes.conn)
# import in db_name
@ -74,8 +75,7 @@ class Installer:
# get the path of the sql file to import
if not source_sql:
source_sql = os.path.join(os.path.dirname(webnotes.__file__), "..",
'conf', 'Framework.sql')
source_sql = os.path.join(os.path.dirname(webnotes.__file__), 'data', 'Framework.sql')
self.dbman.restore_database(db_name, source_sql, db_name, webnotes.conf.db_password)
if verbose: print "Imported from database %s" % source_sql
@ -85,22 +85,35 @@ class Installer:
# fresh app
if 'Framework.sql' in source_sql:
if verbose: print "Installing app..."
self.install_app(verbose=verbose)
self.install_app("webnotes", verbose=verbose)
# update admin password
self.update_admin_password(admin_password)
# create public folder
from webnotes.install_lib import setup_public_folder
setup_public_folder.make(site=self.site)
if not self.site:
from webnotes.build import bundle
bundle(False)
# from webnotes.install_lib import setup_public_folder
# setup_public_folder.make(site=self.site)
#
# if not self.site:
# from webnotes.build import bundle
# bundle(False)
#
return db_name
def install_app(self, name, verbose=False):
manage = webnotes.get_module(name + ".manage")
if hasattr(manage, "before_install"):
manage.before_install()
sync_for(name, force=True, sync_everything=True, verbose=verbose)
if hasattr(manage, "after_install"):
manage.after_install()
def install_app_old(self, verbose=False):
def install_app(self, verbose=False):
sync_for("lib", force=True, sync_everything=True, verbose=verbose)
self.import_core_docs()
@ -116,7 +129,7 @@ class Installer:
install_fixtures()
# build website sitemap
from website.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
build_website_sitemap_config()
if verbose: print "Completing App Import..."
@ -179,50 +192,12 @@ class Installer:
`password` VARCHAR(180) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8""")
def make_conf(db_name=None, db_password=None, site=None, site_config=None):
try:
from werkzeug.exceptions import NotFound
import conf
try:
webnotes.init(site=site)
except NotFound:
pass
if not site and webnotes.conf.site:
site = webnotes.conf.site
if site:
# conf exists and site is specified, create site_config.json
make_site_config(site, db_name, db_password, site_config)
elif os.path.exists("conf.py"):
print "conf.py exists"
else:
# pyc file exists but py doesn't
raise ImportError
except ImportError:
if site:
raise Exception("conf.py does not exist")
else:
# create conf.py
with open(os.path.join("lib", "conf", "conf.py"), "r") as confsrc:
with open("conf.py", "w") as conftar:
conftar.write(confsrc.read() % get_conf_params(db_name, db_password))
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)
webnotes.destroy()
webnotes.init(site=site)
def make_site_config(site, db_name=None, db_password=None, site_config=None):
import conf
if not getattr(conf, "sites_dir", None):
raise Exception("sites_dir missing in conf.py")
site_path = os.path.join(conf.sites_dir, site)
if not os.path.exists(site_path):
os.mkdir(site_path)
webnotes.init(site_path=site_path)
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")
if not os.path.exists(site_file):
@ -256,7 +231,7 @@ def install_fixtures():
webnotes.conn.commit()
if f.endswith(".csv"):
from core.page.data_import_tool.data_import_tool import import_file_by_path
from webnotes.core.page.data_import_tool.data_import_tool import import_file_by_path
import_file_by_path(os.path.join(basepath, f), ignore_links = True, overwrite=True)
webnotes.conn.commit()

View file

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

View file

@ -23,5 +23,8 @@ class MClient(memcache.Client):
self.set_value(key, val)
return val
def delete_value(self, key):
self.delete(self.n(key))
def delete_value(self, keys):
if not isinstance(keys, (list, tuple)):
keys = (keys,)
for key in keys:
self.delete(self.n(key))

View file

@ -15,67 +15,12 @@ methods in following modules are imported for backward compatibility
* webnotes.model.doc.*
* webnotes.model.bean.*
"""
def get_server_obj(doc, doclist = [], basedoctype = ''):
# for test
import webnotes
from webnotes.modules import scrub, get_doctype_module
from webnotes.plugins import get_code_and_execute
# get doctype details
module = get_doctype_module(doc.doctype) or "core"
if not module:
return
DocType = get_doctype_class(doc.doctype, module)
if webnotes.flags.in_import:
return DocType(doc, doclist)
# custom?
namespace = {"DocType": DocType}
get_code_and_execute(module, "DocType", doc.doctype, namespace=namespace)
if namespace.get("CustomDocType"):
return namespace["CustomDocType"](doc, doclist)
else:
return DocType(doc, doclist)
def get_doctype_class(doctype, module):
from webnotes.utils import cint
import webnotes
module = load_doctype_module(doctype, module)
if module:
DocType = getattr(module, 'DocType')
else:
if not cint(webnotes.conn.get_value("DocType", doctype, "custom")):
raise ImportError, "Unable to load module for: " + doctype
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
return DocType
def get_module_name(doctype, module, prefix):
from webnotes.modules import scrub
_doctype, _module = scrub(doctype), scrub(module)
return '%s.doctype.%s.%s%s' % (_module, _doctype, prefix, _doctype)
def load_doctype_module(doctype, module=None, prefix=""):
import webnotes
from webnotes.modules import scrub, get_doctype_module
if not module:
module = get_doctype_module(doctype) or "core"
try:
module = __import__(get_module_name(doctype, module, prefix), fromlist=[''])
return module
except ImportError, e:
# webnotes.errprint(webnotes.getTraceback())
return None
import webnotes
from webnotes.modules import get_doctype_module
import webnotes.model.doc
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0):
import webnotes.model.doc
if dt:
if isinstance(dt, list):
return get_server_obj(dt[0], dt)
@ -90,6 +35,23 @@ def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0):
return get_server_obj(doclist[0], doclist)
else:
return get_server_obj(doc, doclist)
def get_server_obj(doc, doclist = [], basedoctype = ''):
# for test
module = get_doctype_module(doc.doctype)
return load_doctype_module(doc.doctype, module).DocType(doc, doclist)
def load_doctype_module(doctype, module=None, prefix=""):
if not module:
module = get_doctype_module(doctype)
return webnotes.get_module(get_module_name(doctype, module, prefix))
def get_module_name(doctype, module, prefix=""):
from webnotes.modules import scrub
return '{app}.{module}.doctype.{doctype}.{prefix}{doctype}'.format(\
app = scrub(webnotes.local.module_app[scrub(module)]),
module = scrub(module), doctype = scrub(doctype), prefix=prefix)
def run_server_obj(server_obj, method_name, arg=None):
"""
@ -101,36 +63,4 @@ def run_server_obj(server_obj, method_name, arg=None):
else:
return getattr(server_obj, method_name)()
else:
raise Exception, 'No method %s' % method_name
def get_code(module, dt, dn, extn, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes
# get module (if required)
if not module:
module = webnotes.conn.get_value(dt, dn, 'module')
# no module, quit
if not module:
return ''
# file names
if dt in ('Page','Doctype'):
dt, dn = scrub(dt), scrub(dn)
# get file name
fname = dn + '.' + extn
# code
code = ''
try:
file = open(os.path.join(get_module_path(scrub(module)), dt, dn, fname), 'r')
code = file.read()
file.close()
except IOError, e:
# no file, try from db
if fieldname:
code = webnotes.conn.get_value(dt, dn, fieldname)
return code
raise Exception, 'No method %s' % method_name

View file

@ -228,11 +228,9 @@ def cache_name(doctype, processed):
return "doctype:" + doctype + suffix
def clear_cache(doctype=None):
import webnotes.plugins
def clear_single(dt):
webnotes.cache().delete_value(cache_name(dt, False))
webnotes.cache().delete_value(cache_name(dt, True))
webnotes.plugins.clear_cache("DocType", dt)
if doctype_cache and doctype in doctype_cache:
del doctype_cache[dt]
@ -246,7 +244,7 @@ def clear_cache(doctype=None):
clear_single(dt[0])
# clear all notifications
from core.doctype.notification_count.notification_count import delete_notification_count_for
from webnotes.core.doctype.notification_count.notification_count import delete_notification_count_for
delete_notification_count_for(doctype)
else:

View file

@ -7,8 +7,8 @@ from __future__ import unicode_literals
perms will get synced only if none exist
"""
import webnotes
import os
from webnotes.modules.import_file import import_file
import os, sys
from webnotes.modules.import_file import import_file_by_path
from webnotes.utils import get_path, cstr
def sync_all(force=0):
@ -16,8 +16,10 @@ def sync_all(force=0):
sync_for("app", force)
webnotes.clear_cache()
def sync_for(folder, force=0, sync_everything = False, verbose=False):
return walk_and_sync(get_path(folder), force, sync_everything, verbose=verbose)
def sync_for(app_name, force=0, sync_everything = False, verbose=False):
for module_name in webnotes.local.app_modules[app_name]:
folder = os.path.dirname(webnotes.get_module(app_name + "." + module_name).__file__)
walk_and_sync(folder, force, sync_everything, verbose=verbose)
def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
"""walk and sync all doctypes and pages"""
@ -28,7 +30,11 @@ def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
for path, folders, files in os.walk(start_path):
# sort folders so that doctypes are synced before pages or reports
if 'locale' in folders: folders.remove('locale')
for dontwalk in (".git", "locale", "public"):
if dontwalk in folders:
folders.remove(dontwalk)
folders.sort()
if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
@ -42,7 +48,7 @@ def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
doctype = path.split(os.sep)[-2]
name = path.split(os.sep)[-1]
if import_file(module_name, doctype, name, force=force) and verbose:
if import_file_by_path(os.path.join(path, f), force=force) and verbose:
print module_name + ' | ' + doctype + ' | ' + name
webnotes.conn.commit()

2
webnotes/modules.txt Normal file
View file

@ -0,0 +1,2 @@
core
website

View file

@ -24,30 +24,23 @@ def scrub_dt_dn(dt, dn):
def get_module_path(module):
"""Returns path of the given module"""
m = scrub(module)
app_path = webnotes.utils.get_base_path()
if m in ('core', 'website'):
return os.path.join(app_path, 'lib', m)
else:
return os.path.join(app_path, 'app', m)
return os.path.dirname(webnotes.get_module(module).__file__)
def get_doc_path(module, doctype, name):
dt, dn = scrub_dt_dn(doctype, name)
return os.path.join(get_module_path(module), dt, dn)
def reload_doc(module, dt=None, dn=None, plugin=None, force=True):
def reload_doc(module, dt=None, dn=None, force=True):
from webnotes.modules.import_file import import_files
return import_files(module, dt, dn, plugin=plugin, force=force)
return import_files(module, dt, dn, force=force)
def export_doc(doctype, name, module=None, plugin=None):
def export_doc(doctype, name, module=None):
"""write out a doc"""
from webnotes.modules.export_file import write_document_file
import webnotes.model.doc
if not module: module = webnotes.conn.get_value(doctype, name, 'module')
write_document_file(webnotes.model.doc.get(doctype, name), module, plugin=plugin)
write_document_file(webnotes.model.doc.get(doctype, name), module)
def get_doctype_module(doctype):
return webnotes.conn.get_value('DocType', doctype, 'module')
return webnotes.conn.get_value('DocType', doctype, 'module') or "core"

View file

@ -6,12 +6,11 @@ from __future__ import unicode_literals
import webnotes, os
import webnotes.model.doc
from webnotes.modules import scrub, get_module_path, lower_case_files_for, scrub_dt_dn
from webnotes.plugins import get_plugin_path
def export_doc(doc):
export_to_files([[doc.doctype, doc.name]])
def export_to_files(record_list=None, record_module=None, verbose=0, plugin=None, create_init=None):
def export_to_files(record_list=None, record_module=None, verbose=0, create_init=None):
"""
Export record_list to files. record_list is a list of lists ([doctype],[docname] ) ,
"""
@ -22,9 +21,9 @@ def export_to_files(record_list=None, record_module=None, verbose=0, plugin=None
if record_list:
for record in record_list:
write_document_file(webnotes.model.doc.get(record[0], record[1]),
record_module, plugin=plugin, create_init=create_init)
record_module, create_init=create_init)
def write_document_file(doclist, record_module=None, plugin=None, create_init=None):
def write_document_file(doclist, record_module=None, create_init=None):
from webnotes.modules.utils import pprint_doclist
doclist = [filter_fields(d.fields) for d in doclist]
@ -34,7 +33,7 @@ def write_document_file(doclist, record_module=None, plugin=None, create_init=No
create_init = doclist[0]['doctype'] in lower_case_files_for
# create folder
folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'], create_init, plugin=plugin)
folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'], create_init)
# write the data file
fname = (doclist[0]['doctype'] in lower_case_files_for and scrub(doclist[0]['name'])) or doclist[0]['name']
@ -73,11 +72,8 @@ def get_module_name(doclist):
return module
def create_folder(module, dt, dn, create_init, plugin=None):
if plugin:
module_path = os.path.join(get_plugin_path(plugin), scrub(module))
else:
module_path = get_module_path(module)
def create_folder(module, dt, dn, create_init):
module_path = get_module_path(module)
dt, dn = scrub_dt_dn(dt, dn)

View file

@ -5,33 +5,28 @@ from __future__ import unicode_literals
import webnotes, os
from webnotes.modules import scrub, get_module_path, scrub_dt_dn
import webnotes.plugins
def import_files(module, dt=None, dn=None, plugin=None, force=False):
def import_files(module, dt=None, dn=None, force=False):
if type(module) is list:
out = []
for m in module:
out.append(import_file(m[0], m[1], m[2], plugin=plugin, force=force))
out.append(import_file(m[0], m[1], m[2], force=force))
return out
else:
return import_file(module, dt, dn, plugin=plugin, force=force)
return import_file(module, dt, dn, force=force)
def import_file(module, dt, dn, plugin=None, force=False):
def import_file(module, dt, dn, force=False):
"""Sync a file from txt if modifed, return false if not updated"""
webnotes.flags.in_import = True
dt, dn = scrub_dt_dn(dt, dn)
if plugin:
path = webnotes.plugins.get_path(module, dt, dn, plugin, extn="txt")
else:
path = os.path.join(get_module_path(module),
os.path.join(dt, dn, dn + '.txt'))
path = os.path.join(get_module_path(module),
os.path.join(dt, dn, dn + '.txt'))
ret = import_file_by_path(path, force)
webnotes.flags.in_import = False
return ret
def import_file_by_path(path, force=False):
webnotes.flags.in_import = True
if os.path.exists(path):
from webnotes.modules.utils import peval_doclist
@ -55,10 +50,12 @@ def import_file_by_path(path, force=False):
(doc['doctype'], '%s', '%s'),
(original_modified, doc['name']))
return True
else:
raise Exception, '%s missing' % path
webnotes.flags.in_import = False
return True
ignore_values = {
"Report": ["disabled"],
}

View file

@ -9,12 +9,10 @@ Session bootstraps info needed by common client side activities including
permission, homepage, control panel variables, system defaults etc
"""
import webnotes
import conf
import json
from webnotes.utils import cint
import webnotes.model.doctype
import webnotes.defaults
import webnotes.plugins
@webnotes.whitelist()
def clear(user=None):
@ -27,10 +25,8 @@ def clear_cache(user=None):
# clear doctype cache
webnotes.model.doctype.clear_cache()
cache.delete_value(("app_modules", "module_apps"))
# clear plugins code cache
webnotes.plugins.clear_cache()
if user:
cache.delete_value("bootinfo:" + user)
if webnotes.session:
@ -57,10 +53,10 @@ def clear_sessions(user=None, keep_current=False):
def get():
"""get session boot info"""
from core.doctype.notification_count.notification_count import get_notification_info_for_boot
from webnotes.core.doctype.notification_count.notification_count import get_notification_info_for_boot
bootinfo = None
if not getattr(conf,'auto_cache_clear',None):
if not getattr(webnotes.conf,'auto_cache_clear',None):
# check if cache exists
bootinfo = webnotes.cache().get_value('bootinfo:' + webnotes.session.user)
if bootinfo:

View file

@ -14,7 +14,7 @@ class DocType:
def on_update(self):
"if profile is set, then update all older blogs"
from website.doctype.blog_post.blog_post import clear_blog_cache
from webnotes.website.doctype.blog_post.blog_post import clear_blog_cache
clear_blog_cache()
if self.doc.profile:

View file

@ -56,7 +56,7 @@ class DocType(DocListController, WebsiteGenerator):
def get_context(self):
if self.doc.slideshow:
from website.doctype.website_slideshow.website_slideshow import get_slideshow
from webnotes.website.doctype.website_slideshow.website_slideshow import get_slideshow
get_slideshow(self)
self.doc.meta_description = self.doc.description

View file

@ -8,7 +8,7 @@ import webnotes
import webnotes.utils
import os, datetime
from website.doctype.website_sitemap.website_sitemap import add_to_sitemap
from webnotes.website.doctype.website_sitemap.website_sitemap import add_to_sitemap
class DocType:
def __init__(self, d, dl):

View file

@ -6,5 +6,5 @@ from __future__ import unicode_literals
no_cache = True
def get_context():
from core.doctype.print_format.print_format import get_args
from webnotes.core.doctype.print_format.print_format import get_args
return get_args()

View file

@ -8,7 +8,7 @@ import json, os, time
from webnotes import _
import webnotes.utils
import mimetypes
from website.doctype.website_sitemap.website_sitemap import add_to_sitemap
from webnotes.website.doctype.website_sitemap.website_sitemap import add_to_sitemap
class PageNotFoundError(Exception): pass

View file

@ -132,6 +132,6 @@ def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE',
}
arg["parenttype"] = "Assignment"
from core.page.messages import messages
from webnotes.core.page.messages import messages
import json
messages.post(json.dumps(arg))

View file

@ -11,7 +11,6 @@ from webnotes import _
from webnotes.modules import scrub, get_module_path
from webnotes.utils import flt, cint
import webnotes.widgets.reportview
import webnotes.plugins
@webnotes.whitelist()
def get_script(report_name):
@ -27,9 +26,6 @@ def get_script(report_name):
with open(script_path, "r") as script:
script = script.read()
if not script and report.is_standard == "No":
script = webnotes.plugins.read_file(module, "Report", report.name, extn="js", cache=True)
if not script and report.javascript:
script = report.javascript
@ -42,18 +38,11 @@ def get_script(report_name):
if os.path.exists(report_folder):
messages = get_lang_data(report_folder, webnotes.lang, 'js')
webnotes.response["__messages"] = messages
else:
# TODO check if language files get exported here
plugins_report_folder = webnotes.plugins.get_path(module, "Report", report.name)
if os.path.exists(plugins_report_folder):
messages = get_lang_data(plugins_report_folder, webnotes.lang, 'js')
webnotes.response["__messages"] = messages
return script
@webnotes.whitelist()
def run(report_name, filters=None):
from webnotes.plugins import get_code_and_execute
report = webnotes.doc("Report", report_name)
@ -79,9 +68,6 @@ def run(report_name, filters=None):
if report.is_standard=="Yes":
method_name = scrub(module) + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
columns, result = webnotes.get_method(method_name)(filters or {})
else:
namespace = get_code_and_execute(module, "Report", report.name)
columns, result = namespace["execute"](filters or {})
result = get_filtered_data(report.ref_doctype, columns, result)

View file

@ -6,18 +6,17 @@
from __future__ import unicode_literals
import sys
if __name__=="__main__":
sys.path = [".", "lib", "app"] + sys.path
import webnotes
def main():
parsed_args = webnotes._dict(vars(setup_parser()))
fn = get_function(parsed_args)
if parsed_args.get("site")=="all":
for site in get_sites():
if not parsed_args.get("sit_path"):
parsed_args["site_path"] = "."
if parsed_args.get("site_path")=="all":
for site_path in get_sites():
args = parsed_args.copy()
args["site"] = site
args["site_path"] = site_path
run(fn, args)
else:
run(fn, parsed_args)
@ -52,9 +51,9 @@ def get_function(args):
def get_sites():
import os
import conf
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))]
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))]
def setup_parser():
import argparse
@ -63,17 +62,14 @@ def setup_parser():
setup_install(parser)
setup_utilities(parser)
setup_translation(parser)
setup_git(parser)
# 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", nargs="?", metavar="SITE-NAME or all",
help="Run for a particular site")
parser.add_argument("--plugin", nargs="?", metavar="PLUGIN-NAME",
help="Run for a particular plugin")
parser.add_argument("--site_path", nargs="?", metavar="site_path-NAME or all",
help="Run for a particular site_path")
return parser.parse_args()
@ -122,39 +118,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 to different directory defined by --dest_dir")
help="Move site_path to different directory defined by --dest_dir")
parser.add_argument("--dest_dir", nargs=1, metavar="DEST-DIR",
help="Move site to different directory")
help="Move site_path 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 Settings")
help="Get or set domain in Website_path 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")
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site_path")
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")
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("--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("--update_site_config", nargs=1,
metavar="SITE-CONFIG-JSON",
help="Update site_config.json for a given --site")
metavar="site_path-CONFIG-JSON",
help="Update site_config.json for a given --site_path")
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 cache")
help="Clear website_path cache")
parser.add_argument("--build_sitemap", default=False, action="store_true",
help="Build Website Sitemap")
help="Build Website_path Sitemap")
parser.add_argument("--rebuild_sitemap", default=False, action="store_true",
help="Rebuild Website Sitemap")
help="Rebuild Website_path 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",
@ -179,24 +175,7 @@ def setup_utilities(parser):
parser.add_argument("--export_csv", nargs=2, metavar=("DOCTYPE", "PATH"),
help="""Dump DocType as csv""")
parser.add_argument("--import_doclist", nargs=1, metavar="PATH",
help="""Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported""")
def setup_git(parser):
parser.add_argument("--pull", nargs="*", metavar=("REMOTE", "BRANCH"),
help="Run git pull for both repositories")
parser.add_argument("-p", "--push", nargs="*", metavar=("REMOTE", "BRANCH"),
help="Run git push for both repositories")
parser.add_argument("--status", default=False, action="store_true",
help="Run git status for both repositories")
parser.add_argument("--commit", nargs=1, metavar="COMMIT-MSG",
help="Run git commit COMMIT-MSG for both repositories")
parser.add_argument("--checkout", nargs=1, metavar="BRANCH",
help="Run git checkout BRANCH for both repositories")
parser.add_argument("--git", nargs="*", metavar="OPTIONS",
help="Run git command for both repositories")
parser.add_argument("--bump", metavar=("REPO", "VERSION-TYPE"), nargs=2,
help="Bump project version")
help="""Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported""")
def setup_translation(parser):
parser.add_argument("--build_message_files", default=False, action="store_true",
@ -218,73 +197,72 @@ def setup_translation(parser):
# install
@cmd
def install(db_name, source_sql=None, site=None, verbose=True, force=False, root_password=None, site_config=None, admin_password='admin'):
def install(db_name, source_sql=None, site_path=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=site, root_password=root_password, site_config=site_config)
inst.install(db_name, source_sql=source_sql, verbose=verbose, force=force, admin_password=admin_password)
inst = Installer('root', db_name=db_name, site_path=site_path, 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=None, verbose=True):
webnotes.init(site=site)
install(webnotes.conf.db_name, site=site, verbose=verbose, force=True)
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)
@cmd
def restore(db_name, source_sql, site=None, verbose=True, force=False):
install(db_name, source_sql, site=site, verbose=verbose, force=force)
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)
@cmd
def install_fixtures(site=None):
webnotes.init(site=site)
def install_fixtures(site_path=None):
webnotes.init(site_path=site_path)
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=None):
webnotes.connect(site=site)
def add_system_manager(email, first_name=None, last_name=None, site_path=None):
webnotes.connect(site_path=site_path)
webnotes.profile.add_system_manager(email, first_name, last_name)
webnotes.conn.commit()
webnotes.destroy()
@cmd
def make_demo(site=None):
def make_demo(site_path=None):
import utilities.demo.make_demo
webnotes.init(site=site)
webnotes.init(site_path=site_path)
utilities.demo.make_demo.make()
webnotes.destroy()
@cmd
def make_demo_fresh(site=None):
def make_demo_fresh(site_path=None):
import utilities.demo.make_demo
webnotes.init(site=site)
webnotes.init(site_path=site_path)
utilities.demo.make_demo.make(reset=True)
webnotes.destroy()
# utilities
@cmd
def update(remote=None, branch=None, site=None, reload_gunicorn=False):
pull(remote=remote, branch=branch, site=site)
def update(remote=None, branch=None, site_path=None, reload_gunicorn=False):
pull(remote=remote, branch=branch, site_path=site_path)
# maybe there are new framework changes, any consequences?
reload(webnotes)
if not site: build()
if not site_path: build()
latest(site=site)
latest(site_path=site_path)
if reload_gunicorn:
import subprocess
subprocess.check_output("killall -HUP gunicorn".split())
@cmd
def latest(site=None, verbose=True):
def latest(site_path=None, verbose=True):
import webnotes.modules.patch_handler
import webnotes.model.sync
import webnotes.plugins
from website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
from webnotes.website_path.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
try:
# run patches
@ -295,11 +273,8 @@ def latest(site=None, verbose=True):
# sync
webnotes.model.sync.sync_all()
# remove __init__.py from plugins
webnotes.plugins.remove_init_files()
# build website config if any changes in templates etc.
# build website_path config if any changes in templates etc.
build_website_sitemap_config()
except webnotes.modules.patch_handler.PatchError, e:
@ -309,16 +284,16 @@ def latest(site=None, verbose=True):
webnotes.destroy()
@cmd
def sync_all(site=None, force=False):
def sync_all(site_path=None, force=False):
import webnotes.model.sync
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.model.sync.sync_all(force=force)
webnotes.destroy()
@cmd
def patch(patch_module, site=None, force=False):
def patch(patch_module, site_path=None, force=False):
import webnotes.modules.patch_handler
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.local.patch_log_list = []
webnotes.modules.patch_handler.run_single(patch_module, force=force)
print "\n".join(webnotes.local.patch_log_list)
@ -332,13 +307,13 @@ def update_all_sites(remote=None, branch=None, verbose=True):
reload(webnotes)
build()
for site in get_sites():
latest(site=site, verbose=verbose)
for site_path in get_sites():
latest(site_path=site_path, verbose=verbose)
@cmd
def reload_doc(module, doctype, docname, plugin=None, site=None, force=False):
webnotes.connect(site=site)
webnotes.reload_doc(module, doctype, docname, plugin=plugin, force=force)
def reload_doc(module, doctype, docname, site_path=None, force=False):
webnotes.connect(site_path=site_path)
webnotes.reload_doc(module, doctype, docname, force=force)
webnotes.conn.commit()
webnotes.destroy()
@ -353,9 +328,9 @@ def watch():
webnotes.build.watch(True)
@cmd
def backup(site=None, with_files=False, verbose=True, backup_path_db=None, backup_path_files=None):
def backup(site_path=None, with_files=False, verbose=True, backup_path_db=None, backup_path_files=None):
from webnotes.utils.backups import scheduled_backup
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
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
@ -366,18 +341,18 @@ def backup(site=None, with_files=False, verbose=True, backup_path_db=None, backu
return odb
@cmd
def move(site=None, dest_dir=None):
def move(site_path=None, 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=site)
webnotes.init(site_path=site_path)
old_path = webnotes.utils.get_site_path()
new_path = os.path.join(dest_dir, site)
new_path = os.path.join(dest_dir, site_path)
# check if site dump of same name already exists
# check if site_path dump of same name already exists
site_dump_exists = True
count = 0
while site_dump_exists:
@ -390,61 +365,61 @@ def move(site=None, dest_dir=None):
return os.path.basename(final_new_path)
@cmd
def domain(host_url=None, site=None):
webnotes.connect(site=site)
def domain(host_url=None, site_path=None):
webnotes.connect(site_path=site_path)
if host_url:
webnotes.conn.set_value("Website Settings", None, "subdomain", host_url)
webnotes.conn.set_value("Website_path Settings", None, "subdomain", host_url)
webnotes.conn.commit()
else:
print webnotes.conn.get_value("Website Settings", None, "subdomain")
print webnotes.conn.get_value("Website_path Settings", None, "subdomain")
webnotes.destroy()
@cmd
def make_conf(db_name=None, db_password=None, site=None, site_config=None):
def make_conf(db_name=None, db_password=None, site_path=None, site_config=None):
from webnotes.install_lib.install import make_conf
make_conf(db_name=db_name, db_password=db_password, site=site, site_config=site_config)
make_conf(db_name=db_name, db_password=db_password, site_path=site_path, site_config=site_config)
@cmd
def make_custom_server_script(doctype, site=None):
from core.doctype.custom_script.custom_script import make_custom_server_script_file
webnotes.connect(site=site)
def make_custom_server_script(doctype, site_path=None):
from webnotes.core.doctype.custom_script.custom_script import make_custom_server_script_file
webnotes.connect(site_path=site_path)
make_custom_server_script_file(doctype)
webnotes.destroy()
# clear
@cmd
def clear_cache(site=None):
def clear_cache(site_path=None):
import webnotes.sessions
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.sessions.clear_cache()
webnotes.destroy()
@cmd
def clear_web(site=None):
def clear_web(site_path=None):
import webnotes.webutils
webnotes.connect(site=site)
from website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect(site_path=site_path)
from webnotes.website_path.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=None):
from website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config
webnotes.connect(site=site)
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)
build_website_sitemap_config()
webnotes.destroy()
@cmd
def rebuild_sitemap(site=None):
from website.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config
webnotes.connect(site=site)
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)
rebuild_website_sitemap_config()
webnotes.destroy()
@cmd
def reset_perms(site=None):
webnotes.connect(site=site)
def reset_perms(site_path=None):
webnotes.connect(site_path=site_path)
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)
@ -453,20 +428,20 @@ def reset_perms(site=None):
# scheduler
@cmd
def run_scheduler(site=None):
def run_scheduler(site_path=None):
from webnotes.utils.file_lock import create_lock, delete_lock
import webnotes.utils.scheduler
webnotes.init(site=site)
webnotes.init(site_path=site_path)
if create_lock('scheduler'):
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
print webnotes.utils.scheduler.execute()
delete_lock('scheduler')
webnotes.destroy()
@cmd
def run_scheduler_event(event, site=None):
def run_scheduler_event(event, site_path=None):
import webnotes.utils.scheduler
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
print webnotes.utils.scheduler.trigger("execute_" + event)
webnotes.destroy()
@ -478,66 +453,66 @@ def replace(search_regex, replacement, extn, force=False):
# import/export
@cmd
def export_doc(doctype, docname, site=None):
def export_doc(doctype, docname, site_path=None):
import webnotes.modules
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.modules.export_doc(doctype, docname)
webnotes.destroy()
@cmd
def export_doclist(doctype, name, path, site=None):
from core.page.data_import_tool import data_import_tool
webnotes.connect(site=site)
def export_doclist(doctype, name, path, site_path=None):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
data_import_tool.export_json(doctype, name, path)
webnotes.destroy()
@cmd
def export_csv(doctype, path, site=None):
from core.page.data_import_tool import data_import_tool
webnotes.connect(site=site)
def export_csv(doctype, path, site_path=None):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
data_import_tool.export_csv(doctype, path)
webnotes.destroy()
@cmd
def import_doclist(path, site=None, force=False):
from core.page.data_import_tool import data_import_tool
webnotes.connect(site=site)
def import_doclist(path, site_path=None, force=False):
from webnotes.core.page.data_import_tool import data_import_tool
webnotes.connect(site_path=site_path)
data_import_tool.import_doclist(path, overwrite=force)
webnotes.destroy()
# translation
@cmd
def build_message_files(site=None):
def build_message_files(site_path=None):
import webnotes.translate
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.translate.build_message_files()
webnotes.destroy()
@cmd
def export_messages(lang, outfile, site=None):
def export_messages(lang, outfile, site_path=None):
import webnotes.translate
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.translate.export_messages(lang, outfile)
webnotes.destroy()
@cmd
def import_messages(lang, infile, site=None):
def import_messages(lang, infile, site_path=None):
import webnotes.translate
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.translate.import_messages(lang, infile)
webnotes.destroy()
@cmd
def google_translate(lang, infile, outfile, site=None):
def google_translate(lang, infile, outfile, site_path=None):
import webnotes.translate
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.translate.google_translate(lang, infile, outfile)
webnotes.destroy()
@cmd
def translate(lang, site=None):
def translate(lang, site_path=None):
import webnotes.translate
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.translate.translate(lang)
webnotes.destroy()
@ -585,39 +560,39 @@ def checkout(branch):
git(("checkout", branch))
@cmd
def set_admin_password(admin_password, site=None):
def set_admin_password(admin_password, site_path=None):
import webnotes
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
webnotes.conn.sql("""update __Auth set `password`=password(%s)
where user='Administrator'""", (admin_password,))
webnotes.conn.commit()
webnotes.destroy()
@cmd
def mysql(site=None):
def mysql(site_path=None):
import webnotes
import commands, os
msq = commands.getoutput('which mysql')
webnotes.init(site=site)
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=None):
def python(site_path=None):
import webnotes
import commands, os
python = commands.getoutput('which python')
webnotes.init(site=site)
if site:
os.environ["site"] = site
webnotes.init(site_path=site_path)
if site_path:
os.environ["site_path"] = site_path
os.environ["PYTHONSTARTUP"] = os.path.join(os.path.dirname(__file__), "pythonrc.py")
os.execv(python, [python])
webnotes.destroy()
@cmd
def ipython(site=None):
def ipython(site_path=None):
import webnotes
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
import IPython
IPython.embed()
@ -679,15 +654,15 @@ def search_replace_with_prompt(fpath, txt1, txt2, force=False):
print colored('Updated', 'green')
@cmd
def get_site_status(site=None, verbose=False):
def get_site_status(site_path=None, verbose=False):
import webnotes
import webnotes.utils
from webnotes.profile import get_system_managers
from core.doctype.profile.profile import get_total_users, get_active_users, \
from webnotes.core.doctype.profile.profile import get_total_users, get_active_users, \
get_website_users, get_active_website_users
import json
webnotes.connect(site=site)
webnotes.connect(site_path=site_path)
ret = {
'last_backup_on': webnotes.local.conf.last_backup_on,
'active_users': get_active_users(),
@ -720,15 +695,15 @@ def get_site_status(site=None, verbose=False):
return ret
@cmd
def update_site_config(site_config, site, verbose=False):
def update_site_config(site_config, site_path, verbose=False):
import json
if isinstance(site_config, basestring):
site_config = json.loads(site_config)
webnotes.init(site=site)
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)
site_config_path = webnotes.get_conf_path(webnotes.conf.sites_dir, site_path)
with open(site_config_path, "w") as f:
json.dump(webnotes.conf.site_config, f, indent=1, sort_keys=True)