def mysql(site=None): import webnotes import commands, os msq = commands.getoutput('which mysql') webnotes.init(site=site) 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()
def set_admin_password(admin_password, site=None): import webnotes webnotes.connect(site=site) webnotes.conn.sql("""update __Auth set `password`=password(%s) where user='******'""", (admin_password,)) webnotes.conn.commit() webnotes.destroy()
def reset_perms(site=None): webnotes.connect(site=site) 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) webnotes.reset_perms(d) webnotes.destroy()
def request(args): import webnotes.handler webnotes.connect() webnotes.form_dict = webnotes._dict([a.split("=") for a in args.split("&")]) webnotes.handler.execute_cmd(webnotes.form_dict.cmd) print webnotes.response webnotes.destroy()
def patch(patch_module, site=None, force=False): import webnotes.modules.patch_handler webnotes.connect(site=site) webnotes.local.patch_log_list = [] webnotes.modules.patch_handler.run_single(patch_module, force=force) print "\n".join(webnotes.local.patch_log_list) webnotes.destroy()
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)) webnotes.destroy() webnotes.init(site=site)
def mysql(site=None): import webnotes import commands, os msq = commands.getoutput('which mysql') webnotes.init(site=site) 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()
def clear_web(site=None): import webnotes.webutils webnotes.connect(site=site) from website.doctype.website_sitemap_config.website_sitemap_config import build_website_sitemap_config build_website_sitemap_config() webnotes.webutils.clear_cache() webnotes.destroy()
def domain(host_url=None, site=None): webnotes.connect(site=site) if host_url: webnotes.conn.set_value("Website Settings", None, "subdomain", host_url) webnotes.conn.commit() else: print webnotes.conn.get_value("Website Settings", None, "subdomain") webnotes.destroy()
def run_scheduler(): from webnotes.utils.file_lock import create_lock, delete_lock import webnotes.utils.scheduler if create_lock('scheduler'): webnotes.connect() print webnotes.utils.scheduler.execute() delete_lock('scheduler') webnotes.destroy()
def run_scheduler(site=None): from webnotes.utils.file_lock import create_lock, delete_lock import webnotes.utils.scheduler webnotes.init(site=site) if create_lock('scheduler'): webnotes.connect(site=site) print webnotes.utils.scheduler.execute() delete_lock('scheduler') webnotes.destroy()
def install(db_name, root_login="******", root_password=None, source_sql=None, admin_password = '******', verbose=True, force=False, site_config=None, reinstall=False): print db_name, source_sql from webnotes.installer import install_db, install_app, make_site_dirs install_db(root_login=root_login, root_password=root_password, db_name=db_name, source_sql=source_sql, admin_password = admin_password, verbose=verbose, force=force, site_config=site_config, reinstall=reinstall) make_site_dirs() install_app("webnotes", verbose=verbose) webnotes.destroy()
def python(site): import webnotes import commands, os python = commands.getoutput('which python') if site: os.environ["site"] = site os.environ["PYTHONSTARTUP"] = os.path.join(os.path.dirname(webnotes.__file__), "pythonrc.py") os.execv(python, [python]) webnotes.destroy()
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()
def get_remote_and_branch(remote=None, branch=None): if not (remote and branch): if not webnotes.conf.branch: raise Exception("Please specify remote and branch") remote = remote or "origin" branch = branch or webnotes.conf.branch webnotes.destroy() return remote, branch
def backup(site=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) 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 print "database backup taken -", odb.backup_path_db, "- on", now() if with_files: print "files backup taken -", odb.backup_path_files, "- on", now() webnotes.destroy() return odb
def make_demo_app(site=None): webnotes.init(site=site) webnotes.flags.mute_emails = 1 utilities.demo.make_demo.make(reset=True, simulate=False) # setup demo user etc so that the site it up faster, while the data loads make_demo_user() make_demo_login_page() make_demo_on_login_script() utilities.demo.make_demo.make(reset=False, simulate=True) webnotes.destroy()
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") remote = remote or "origin" branch = branch or webnotes.conf.branch webnotes.destroy() return remote, branch
def update_site_config(site_config, verbose=False): import json if isinstance(site_config, basestring): site_config = json.loads(site_config) config = webnotes.get_site_config() config.update(site_config) site_config_path = os.path.join(webnotes.local.site_path, "site_config.json") with open(site_config_path, "w") as f: json.dump(config, f, indent=1, sort_keys=True) webnotes.destroy()
def update_site_config(site_config, site, verbose=False): import json if isinstance(site_config, basestring): site_config = json.loads(site_config) webnotes.init(site=site) webnotes.conf.site_config.update(site_config) site_config_path = webnotes.get_conf_path(webnotes.conf.sites_dir, site) with open(site_config_path, "w") as f: json.dump(webnotes.conf.site_config, f, indent=1, sort_keys=True) webnotes.destroy()
def install(db_name, source_sql=None, site=None, verbose=True, force=False, root_password=None, site_config=None, admin_password='******'): 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) webnotes.destroy()
def get_site_status(site=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, \ get_website_users, get_active_website_users import json webnotes.connect(site=site) ret = { 'last_backup_on': webnotes.local.conf.last_backup_on, 'active_users': get_active_users(), 'total_users': get_total_users(), 'active_website_users': get_active_website_users(), 'website_users': get_website_users(), 'system_managers': "\n".join(get_system_managers()), 'default_company': webnotes.conn.get_default("company"), 'disk_usage': webnotes.utils.get_disk_usage(), 'working_directory': webnotes.utils.get_base_path() } # country, timezone, industry control_panel_details = webnotes.conn.get_value( "Control Panel", "Control Panel", ["country", "time_zone", "industry"], as_dict=True) if control_panel_details: ret.update(control_panel_details) # basic usage/progress analytics for doctype in ("Company", "Customer", "Item", "Quotation", "Sales Invoice", "Journal Voucher", "Stock Ledger Entry"): key = doctype.lower().replace(" ", "_") + "_exists" ret[key] = 1 if webnotes.conn.count(doctype) else 0 webnotes.destroy() if verbose: print json.dumps(ret, indent=1, sort_keys=True) return ret
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" old_path = webnotes.utils.get_site() new_path = os.path.join(dest_dir, site) # check if site dump of same name already exists site_dump_exists = True count = 0 while site_dump_exists: final_new_path = new_path + (count and str(count) or "") site_dump_exists = os.path.exists(final_new_path) count = int(count or 0) + 1 os.rename(old_path, final_new_path) webnotes.destroy() return os.path.basename(final_new_path)
def move(site=None, dest_dir=None): import os if not dest_dir: raise Exception, "--dest_dir is required for --move" dest_dir = dest_dir[0] if not os.path.isdir(dest_dir): raise Exception, "destination is not a directory or does not exist" webnotes.init(site=site) old_path = webnotes.utils.get_site_path() new_path = os.path.join(dest_dir, site) # check if site dump of same name already exists site_dump_exists = True count = 0 while site_dump_exists: final_new_path = new_path + (count and str(count) or "") site_dump_exists = os.path.exists(final_new_path) count = int(count or 0) + 1 os.rename(old_path, final_new_path) webnotes.destroy() return os.path.basename(final_new_path)
def get_site_status(site=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, \ get_website_users, get_active_website_users import json webnotes.connect(site=site) ret = { 'last_backup_on': webnotes.local.conf.last_backup_on, 'active_users': get_active_users(), 'total_users': get_total_users(), 'active_website_users': get_active_website_users(), 'website_users': get_website_users(), 'system_managers': "\n".join(get_system_managers()), 'default_company': webnotes.conn.get_default("company"), 'disk_usage': webnotes.utils.get_disk_usage(), 'working_directory': webnotes.utils.get_base_path() } # country, timezone, industry control_panel_details = webnotes.conn.get_value("Control Panel", "Control Panel", ["country", "time_zone", "industry"], as_dict=True) if control_panel_details: ret.update(control_panel_details) # basic usage/progress analytics for doctype in ("Company", "Customer", "Item", "Quotation", "Sales Invoice", "Journal Voucher", "Stock Ledger Entry"): key = doctype.lower().replace(" ", "_") + "_exists" ret[key] = 1 if webnotes.conn.count(doctype) else 0 webnotes.destroy() if verbose: print json.dumps(ret, indent=1, sort_keys=True) return ret
def export_doc(doctype, docname, site=None): import webnotes.modules webnotes.connect(site=site) webnotes.modules.export_doc(doctype, docname) webnotes.destroy()
def run_scheduler_event(event, site=None): import webnotes.utils.scheduler webnotes.connect(site=site) print webnotes.utils.scheduler.trigger("execute_" + event) webnotes.destroy()
def sync_all(site=None, force=False): import webnotes.model.sync webnotes.connect(site=site) webnotes.model.sync.sync_all(force=force) webnotes.destroy()
def translate(lang, site=None): import webnotes.translate webnotes.connect(site=site) webnotes.translate.translate(lang) webnotes.destroy()
def google_translate(lang, infile, outfile, site=None): import webnotes.translate webnotes.connect(site=site) webnotes.translate.google_translate(lang, infile, outfile) webnotes.destroy()
def build_message_files(site=None): import webnotes.translate webnotes.connect(site=site) webnotes.translate.build_message_files() webnotes.destroy()
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) make_custom_server_script_file(doctype) webnotes.destroy()
def clear_cache(site=None): import webnotes.sessions webnotes.connect(site=site) webnotes.sessions.clear_cache() webnotes.destroy()
def clear_web(site=None): import webnotes.webutils webnotes.connect(site=site) webnotes.webutils.clear_cache() webnotes.destroy()
def run_scheduler(site=None): import webnotes.utils.scheduler webnotes.connect(site=site) print webnotes.utils.scheduler.execute() webnotes.destroy()
def export_csv(doctype, path, site=None): from core.page.data_import_tool import data_import_tool webnotes.connect(site=site) data_import_tool.export_csv(doctype, path) webnotes.destroy()
def import_doclist(path, site=None, force=False): from core.page.data_import_tool import data_import_tool webnotes.connect(site=site) data_import_tool.import_doclist(path, overwrite=force) webnotes.destroy()
def import_messages(lang, infile, site=None): import webnotes.translate webnotes.connect(site=site) webnotes.translate.import_messages(lang, infile) webnotes.destroy()
def rebuild_sitemap(site=None): from website.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config webnotes.connect(site=site) rebuild_website_sitemap_config() webnotes.destroy()
def reload_doc(module, doctype, docname, site=None, force=False): webnotes.connect(site=site) webnotes.reload_doc(module, doctype, docname, force=force) webnotes.destroy()