Esempio 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", "-A"])
	webnotes.destroy()
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
def make(site=None):
    """make public folder symlinks if missing"""
    from webnotes.utils import get_site_base_path, get_base_path, get_path

    webnotes.init(site=site)

    site_path = get_site_base_path() if site else get_base_path()

    # setup standard folders
    for param in (("public_path", "public"), ("backup_path", "public/backups"),
                  ("files_path", "public/files")):
        path = os.path.join(site_path, webnotes.conf.get(param[0], param[1]))
        if not os.path.exists(path):
            os.mkdir(path)

    # setup js and css folders
    if not site:
        for folder in ("js", "css"):
            path = get_path(webnotes.conf.get("public_path", "public"), folder)
            if not os.path.exists(path):
                os.mkdir(path)

        os.chdir(webnotes.conf.get("public_path", "public"))
        symlinks = [
            ["app", "../app/public"],
            ["lib", "../lib/public"],
        ]

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

        os.chdir("..")
Esempio n. 5
0
def main():
	parsed_args = webnotes._dict(vars(setup_parser()))
	fn = get_function(parsed_args)
	if not parsed_args.get("sites_path"):
		parsed_args["sites_path"] = "."
	
	if not parsed_args.get("make_app"):
			
		if parsed_args.get("site")=="all":
			for site in get_sites(parsed_args["sites_path"]):
				args = parsed_args.copy()
				args["site"] = site
				webnotes.init(site)
				run(fn, args)
		else:
			if not fn in site_arg_optional:
				if not parsed_args.get("site") and os.path.exists("currentsite.txt"):
					with open("currentsite.txt", "r") as sitefile:
						site = sitefile.read()
				else:
					site = parsed_args.get("site")

				if not site:
					print "Site argument required"
					exit(1)

				if fn != 'install' and not os.path.exists(site):
					print "Did not find folder '{}'. Are you in sites folder?".format(parsed_args.get("site"))
					exit(1)
					
				webnotes.init(site)
			run(fn, parsed_args)
	else:
		run(fn, parsed_args)
Esempio n. 6
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()
Esempio n. 7
0
def application(request):
	webnotes.local.request = request
	
	try:
		site = _site or get_site_name(request.host)
		webnotes.init(site=site)
		
		if not webnotes.local.conf:
			# site does not exist
			raise NotFound
		
		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() })
				
		webnotes.local._response = Response()
		webnotes.http_request = webnotes.auth.HTTPRequest()

		if webnotes.local.form_dict.cmd:
			webnotes.handler.handle()
		elif webnotes.request.path.startswith("/api/"):
			webnotes.api.handle()
		elif webnotes.local.request.method in ('GET', 'HEAD'):
			webnotes.webutils.render(webnotes.request.path[1:])
		else:
			raise NotFound

	except HTTPException, e:
		return e
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 10
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()
Esempio n. 11
0
def update_all_sites(remote=None, branch=None, verbose=True):
	pull(remote, branch)
	
	# maybe there are new framework changes, any consequences?
	reload(webnotes)
	
	build()
	for site in get_sites():
		webnotes.init(site)
		latest(verbose=verbose)
Esempio n. 12
0
def make_demo_app(site=None):
	webnotes.mute_emails = 1
	webnotes.init(site=site)

	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)
Esempio n. 13
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()
Esempio n. 14
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
Esempio n. 15
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
Esempio n. 16
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()
Esempio n. 17
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()
Esempio n. 18
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()
Esempio n. 19
0
def application(request):
    webnotes.local.request = request

    try:
        site = webnotes.utils.get_site_name(request.host)
        webnotes.init(site=site)

        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() })

        webnotes.local._response = Response()

        try:
            webnotes.http_request = webnotes.auth.HTTPRequest()
        except webnotes.AuthenticationError, e:
            pass

        if webnotes.form_dict.cmd:
            webnotes.handler.handle()
        else:
            webnotes.webutils.render(webnotes.request.path[1:])
Esempio n. 20
0
def application(request):
	webnotes.local.request = request
	
	try:
		site = webnotes.utils.get_site_name(request.host)
		webnotes.init(site=site)
		
		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() })
				
		webnotes.local._response = Response()

		try:
			webnotes.http_request = webnotes.auth.HTTPRequest()
		except webnotes.AuthenticationError, e:
			pass
		
		if webnotes.form_dict.cmd:
			webnotes.handler.handle()
		else:
			webnotes.webutils.render(webnotes.request.path[1:])
Esempio n. 21
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)
Esempio n. 22
0
def move(site=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)
	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)
Esempio n. 23
0
                        "word": name
                    }).insert()

    for d in webnotes.conn.sql("select name from tabWord where `count`< 100"):
        webnotes.delete_doc('Word', d[0])

    webnotes.conn.commit()


def make_word_count():
    for ds in webnotes.conn.sql(
            """select name, raw_filename from `tabData Set`""", as_dict=1):
        from webnotes.utils import get_path

        if ds.raw_filename:
            headers, data = utils.get_file_data(
                get_path("app", "downloads", "data.gov.in", ds.raw_filename))

            webnotes.conn.set_value("Data Set", ds.name, "row_count",
                                    len(data))

    webnotes.conn.commit()


if __name__ == "__main__":
    webnotes.connect()
    webnotes.init()
    import_data()
    make_word_map()
    make_word_count()
Esempio n. 24
0
def reinstall(site=None, verbose=True):
    webnotes.init(site=site)
    install(webnotes.conf.db_name, site=site, verbose=verbose, force=True)
Esempio n. 25
0
def install_fixtures(site=None):
    webnotes.init(site=site)
    from webnotes.install_lib.install import install_fixtures
    install_fixtures()
    webnotes.destroy()
Esempio n. 26
0
def make_demo(site=None):
    import utilities.demo.make_demo
    webnotes.init(site=site)
    utilities.demo.make_demo.make()
    webnotes.destroy()
Esempio n. 27
0
def make_demo_fresh(site=None):
    import utilities.demo.make_demo
    webnotes.init(site=site)
    utilities.demo.make_demo.make(reset=True)
    webnotes.destroy()
Esempio n. 28
0
def reinstall(site=None, verbose=True):
	webnotes.init(site=site)
	install(webnotes.conf.db_name, site=site, verbose=verbose, force=True)
Esempio n. 29
0
def make_demo_fresh(site=None):
	import utilities.demo.make_demo
	webnotes.init(site=site)
	utilities.demo.make_demo.make(reset=True)
	webnotes.destroy()
Esempio n. 30
0
def make_demo(site=None):
	import utilities.demo.make_demo
	webnotes.init(site=site)
	utilities.demo.make_demo.make()
	webnotes.destroy()
Esempio n. 31
0
def install_fixtures(site=None):
	webnotes.init(site=site)
	from webnotes.install_lib.install import install_fixtures
	install_fixtures()
	webnotes.destroy()