Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
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()
Ejemplo n.º 14
0
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()
Ejemplo n.º 15
0
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()
Ejemplo n.º 16
0
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()
Ejemplo n.º 17
0
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()
Ejemplo n.º 18
0
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()
Ejemplo n.º 19
0
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()
Ejemplo n.º 20
0
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()
Ejemplo n.º 21
0
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()
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
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
Ejemplo n.º 24
0
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()
Ejemplo n.º 25
0
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()
Ejemplo n.º 26
0
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
Ejemplo n.º 27
0
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
Ejemplo n.º 28
0
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()
Ejemplo n.º 29
0
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()
Ejemplo n.º 30
0
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()
Ejemplo n.º 31
0
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()
Ejemplo n.º 32
0
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
Ejemplo n.º 33
0
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)
Ejemplo n.º 34
0
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)
Ejemplo n.º 35
0
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
Ejemplo n.º 36
0
def export_doc(doctype, docname, site=None):
	import webnotes.modules
	webnotes.connect(site=site)
	webnotes.modules.export_doc(doctype, docname)
	webnotes.destroy()
Ejemplo n.º 37
0
def run_scheduler_event(event, site=None):
	import webnotes.utils.scheduler
	webnotes.connect(site=site)
	print webnotes.utils.scheduler.trigger("execute_" + event)
	webnotes.destroy()
Ejemplo n.º 38
0
def sync_all(site=None, force=False):
    import webnotes.model.sync
    webnotes.connect(site=site)
    webnotes.model.sync.sync_all(force=force)
    webnotes.destroy()
Ejemplo n.º 39
0
def translate(lang, site=None):
    import webnotes.translate
    webnotes.connect(site=site)
    webnotes.translate.translate(lang)
    webnotes.destroy()
Ejemplo n.º 40
0
def google_translate(lang, infile, outfile, site=None):
    import webnotes.translate
    webnotes.connect(site=site)
    webnotes.translate.google_translate(lang, infile, outfile)
    webnotes.destroy()
Ejemplo n.º 41
0
def google_translate(lang, infile, outfile, site=None):
	import webnotes.translate
	webnotes.connect(site=site)
	webnotes.translate.google_translate(lang, infile, outfile)
	webnotes.destroy()
Ejemplo n.º 42
0
def build_message_files(site=None):
	import webnotes.translate
	webnotes.connect(site=site)
	webnotes.translate.build_message_files()
	webnotes.destroy()
Ejemplo n.º 43
0
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()
Ejemplo n.º 44
0
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()
Ejemplo n.º 45
0
def clear_cache(site=None):
    import webnotes.sessions
    webnotes.connect(site=site)
    webnotes.sessions.clear_cache()
    webnotes.destroy()
Ejemplo n.º 46
0
def clear_web(site=None):
    import webnotes.webutils
    webnotes.connect(site=site)
    webnotes.webutils.clear_cache()
    webnotes.destroy()
Ejemplo n.º 47
0
def run_scheduler(site=None):
    import webnotes.utils.scheduler
    webnotes.connect(site=site)
    print webnotes.utils.scheduler.execute()
    webnotes.destroy()
Ejemplo n.º 48
0
def run_scheduler_event(event, site=None):
    import webnotes.utils.scheduler
    webnotes.connect(site=site)
    print webnotes.utils.scheduler.trigger("execute_" + event)
    webnotes.destroy()
Ejemplo n.º 49
0
def export_doc(doctype, docname, site=None):
    import webnotes.modules
    webnotes.connect(site=site)
    webnotes.modules.export_doc(doctype, docname)
    webnotes.destroy()
Ejemplo n.º 50
0
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()
Ejemplo n.º 51
0
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()
Ejemplo n.º 52
0
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()
Ejemplo n.º 53
0
def import_messages(lang, infile, site=None):
	import webnotes.translate
	webnotes.connect(site=site)
	webnotes.translate.import_messages(lang, infile)
	webnotes.destroy()
Ejemplo n.º 54
0
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()
Ejemplo n.º 55
0
def translate(lang, site=None):
	import webnotes.translate
	webnotes.connect(site=site)
	webnotes.translate.translate(lang)
	webnotes.destroy()
Ejemplo n.º 56
0
def reload_doc(module, doctype, docname, site=None, force=False):
    webnotes.connect(site=site)
    webnotes.reload_doc(module, doctype, docname, force=force)
    webnotes.destroy()
Ejemplo n.º 57
0
def clear_cache(site=None):
	import webnotes.sessions
	webnotes.connect(site=site)
	webnotes.sessions.clear_cache()
	webnotes.destroy()
Ejemplo n.º 58
0
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()
Ejemplo n.º 59
0
def import_messages(lang, infile, site=None):
    import webnotes.translate
    webnotes.connect(site=site)
    webnotes.translate.import_messages(lang, infile)
    webnotes.destroy()
Ejemplo n.º 60
0
def build_message_files(site=None):
    import webnotes.translate
    webnotes.connect(site=site)
    webnotes.translate.build_message_files()
    webnotes.destroy()