def make_master():
	"""
		restore the master in a tmp database, run patches and export it
	"""
	# restore the master
	print "Importing master..."

	from webnotes.install_lib.install import Installer
	import webnotes

	# unzip master
	os.system("gunzip %s" % os.path.join(erpnext_path, 'master.sql.gz'))

	installer = Installer('root', root_password)
	installer.import_from_db('_tmpmaster', os.path.join(erpnext_path,'master.sql'))

	# run patches
	run_patches()

	# export db
	print "Taking fresh dump..."
	mysql_dump()

	# drop db
	print "Cleaning up..."
	webnotes.conn.sql("drop database _tmpmaster")
	os.remove(os.path.join(erpnext_path, 'master.sql'))
Beispiel #2
0
def setup_db(install_path, root_password, db_name):
	from webnotes.install_lib.install import Installer
	inst = Installer("root", root_password)
	inst.import_from_db(db_name, verbose=1)

	# run patches and sync
	exec_in_shell("./lib/wnf.py --patch_sync_build")
Beispiel #3
0
def setup_db(install_path, root_password, db_name):
    from webnotes.install_lib.install import Installer
    inst = Installer("root", root_password)
    inst.import_from_db(db_name, verbose=1)

    # run patches and sync
    exec_in_shell("./lib/wnf.py --patch_sync_build")
Beispiel #4
0
def setup_db(path, root_pwd, db_name):
	source = os.path.join(path, 'app', "master.sql")
	execute_in_shell("gunzip -c %s.gz > %s" % (source, source), verbose=1)

	from webnotes.install_lib.install import Installer
	inst = Installer('root', root_pwd)
	inst.import_from_db(db_name, source_path=source, verbose = 1)
	execute_in_shell("rm %s" % source)
def setup_db(install_path, root_password, db_name):
	master_sql = os.path.join(install_path, "app", "master.sql")
	exec_in_shell("gunzip -c %s.gz > %s" % (master_sql, master_sql))
	
	from webnotes.install_lib.install import Installer
	inst = Installer("root", root_password)
	inst.import_from_db(db_name, source_path=master_sql, verbose=1)

	exec_in_shell("rm -f %s" % (master_sql,))
	
	# run patches and sync
	exec_in_shell("./lib/wnf.py -b --no_cms")
	exec_in_shell("./lib/wnf.py --patch_sync_build")
Beispiel #6
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()
def restore_db():
    """
		import the database
	"""
    sys.path.append(os.path.join("wnframework", "cgi-bin"))

    import webnotes
    from webnotes.db import Database
    from webnotes.install_lib.install import Installer

    global db_name

    root_password = raw_input("Root password for mysql (for db and user creation):")

    inst = Installer("root", root_password)

    # gunzip
    os.system("gunzip -c %s > master.sql" % os.path.join("erpnext", "master.sql.gz"))

    # import
    print "Importing database..."
    inst.import_from_db(db_name, "master.sql")

    # cleanup
    webnotes.conn = Database("localhost", "root", root_password)
    webnotes.conn.use(db_name)
    webnotes.conn.begin()
    webnotes.conn.set_value(
        "Control Panel",
        None,
        "company_name",
        raw_input("[ERPNext setup] Enter the name of the full name of your company:"),
    )
    webnotes.conn.sql("delete from tabSingles where field='sync_with_gateway'")
    webnotes.conn.commit()
    os.remove("master.sql")

    # copy icons
    if not os.path.exists(os.path.join("wnframework", "images", "user")):
        os.mkdir(os.path.join("wnframework", "images", "user"))
    os.system("cp %s %s" % (os.path.join("erpnext", "module-icons.png"), os.path.join("wnframework", "images", "user")))
Beispiel #8
0
def execute():
    webnotes.conn.commit()

    from webnotes.install_lib.install import Installer
    Installer(None, None).create_auth_table()

    webnotes.conn.begin()

    for user, password in webnotes.conn.sql(
            """select name, password from tabProfile"""):
        if password:
            webnotes.conn.sql(
                """insert into __Auth (user, `password`) values (%s, %s)""",
                (user, password))
def restore_db():
	"""
		import the database
	"""
	sys.path.append(os.path.join('wnframework','cgi-bin'))

	import webnotes
	from webnotes.db import Database
	from webnotes.install_lib.install import Installer

	global db_name

	root_password = raw_input('Root password for mysql (for db and user creation):')

	inst = Installer('root', root_password)

	# gunzip
	os.system("gunzip -c %s > master.sql" % os.path.join('erpnext', 'master.sql.gz'))

	# import
	print "Importing database..."
	inst.import_from_db(db_name, 'master.sql')

	# cleanup
	webnotes.conn = Database('localhost','root',root_password)
	webnotes.conn.use(db_name)
	webnotes.conn.begin()
	webnotes.conn.set_value('Control Panel',None,'company_name',raw_input('[ERPNext setup] Enter the name of the full name of your company:'))
	webnotes.conn.sql("delete from tabSingles where field='sync_with_gateway'")
	webnotes.conn.commit()
	os.remove('master.sql')

	# copy icons
	if not os.path.exists(os.path.join('wnframework','images','user')):
		os.mkdir(os.path.join('wnframework','images','user'))
	os.system("cp %s %s" % (os.path.join('erpnext','module-icons.png'),os.path.join('wnframework','images','user')))
		os.path.join(erpnext_path, 'logs', 'error_log.txt'), content)
		
	
	# write conf file
	with open(os.path.join(erpnext_path, 'conf.py'), 'w') as new_conf:
		new_conf.write(content)	

# install db
import sys
sys.path.append(erpnext_path)
sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
import conf
sys.path.append(conf.modules_path)

from webnotes.install_lib.install import Installer
inst = Installer('root', root_pwd)
inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, 'data', 'master.sql'), verbose = 1)

# apply patches
os.chdir(erpnext_path)
os.system("lib/wnf.py --update origin master")

# set filemode false
os.system("git config core.filemode false")
os.chdir(os.path.join(erpnext_path, 'lib'))
os.system("git config core.filemode false")

steps_remaining = """
Notes:
------
Beispiel #11
0
def run():
	sys.path.append('.')
	sys.path.append('lib/py')
	import webnotes
	import conf
	sys.path.append(conf.modules_path)

	(options, args) = setup_options()


	from webnotes.db import Database
	import webnotes.modules.patch_handler

	# connect
	if options.db_name is not None:
		if options.password:
			webnotes.connect(options.db_name, options.password)
		else:
			webnotes.connect(options.db_name)
	elif not any([options.install, options.pull]):
		webnotes.connect(conf.db_name)

	# build
	if options.build:
		import build.project
		build.project.build()	

	# code replace
	elif options.replace:
		print options.replace
		replace_code('.', options.replace[0], options.replace[1], options.replace[2])
	
	# git
	elif options.status:
		os.system('git status')
		os.chdir('lib')
		os.system('git status')
	
	elif options.pull:
		pull(options.pull[0], options.pull[1])

	elif options.push:
		os.system('git commit -a -m "%s"' % options.push[2])
		os.system('git push %s %s' % (options.push[0], options.push[1]))
		os.chdir('lib')
		os.system('git commit -a -m "%s"' % options.push[2])
		os.system('git push %s %s' % (options.push[0], options.push[1]))
		
	elif options.checkout:
		os.system('git checkout %s' % options.checkout)
		os.chdir('lib')
		os.system('git checkout %s' % options.checkout)
			
	# patch
	elif options.patch_list:
		# clear log
		webnotes.modules.patch_handler.log_list = []
		
		# run individual patches
		for patch in options.patch_list:
			webnotes.modules.patch_handler.run_single(\
				patchmodule = patch, force = options.force)
		
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
		# reload
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		apply_latest_patches()
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install[0], source_path=options.install[1], \
			password='******', verbose = 1)
	
	elif options.diff_ref_file is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_file()

	elif options.diff_ref_db is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_db()
	
	elif options.run_scheduler:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.execute()
	
	elif options.run_scheduler_event is not None:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event)
		
	elif options.sync_all is not None:
		sync_all(options.force or 0)

	elif options.sync is not None:
		import webnotes.model.sync
		webnotes.model.sync.sync(options.sync[0], options.sync[1], options.force or 0)
	
	elif options.update:
		update_erpnext(options.update[0], options.update[1])

	elif options.cleanup_data:
		from utilities import cleanup_data
		cleanup_data.run()
		
	elif options.domain:
		webnotes.conn.set_value('Website Settings', None, 'subdomain', options.domain)
		webnotes.conn.commit()
		print "Domain set to", options.domain
		
	elif options.build_web_cache:
		import website.web_cache
		website.web_cache.refresh_cache(True)

	# print messages
	if webnotes.message_log:
		print '\n'.join(webnotes.message_log)
Beispiel #12
0
def run():
    sys.path.append('.')
    sys.path.append('lib')
    sys.path.append('app')

    (options, args) = setup_options()

    # build
    if options.build:
        from webnotes.utils import bundlejs
        if options.no_cms:
            cms_make = False
        else:
            cms_make = True
        bundlejs.bundle(options.no_compress, cms_make)
        return

    elif options.watch:
        from webnotes.utils import bundlejs
        bundlejs.watch(True)
        return

    # code replace
    elif options.replace:
        print options.replace
        replace_code('.',
                     options.replace[0],
                     options.replace[1],
                     options.replace[2],
                     force=options.force)
        return

    # git
    elif options.status:
        os.chdir('lib')
        os.system('git status')
        os.chdir('../app')
        os.system('git status')
        return

    elif options.git:
        os.chdir('lib')
        os.system('git %s' % options.git)
        os.chdir('../app')
        os.system('git %s' % options.git)
        return

    import webnotes
    import conf
    from webnotes.db import Database
    import webnotes.modules.patch_handler

    # connect
    if options.db_name is not None:
        if options.password:
            webnotes.connect(options.db_name, options.password)
        else:
            webnotes.connect(options.db_name)
    elif not any([options.install, options.pull]):
        webnotes.connect(conf.db_name)

    if options.pull:
        pull(options.pull[0], options.pull[1], build=True)

    elif options.push:
        os.chdir('lib')
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))
        os.chdir('../app')
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))

    elif options.checkout:
        os.chdir('lib')
        os.system('git checkout %s' % options.checkout)
        os.chdir('../app')
        os.system('git checkout %s' % options.checkout)

    # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(\
             patchmodule = patch, force = options.force)

        print '\n'.join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(\
         {"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc
        export_doc(options.export_doc[0], options.export_doc[1])

    # run all pending
    elif options.run_latest:
        apply_latest_patches()

    elif options.install:
        from webnotes.install_lib.install import Installer
        inst = Installer('root')
        inst.import_from_db(options.install[0], source_path=options.install[1], \
         password='******', verbose = 1)

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.trigger('execute_' +
                                               options.run_scheduler_event)

    elif options.sync_all is not None:
        sync_all(options.force or 0)

    elif options.sync is not None:
        import webnotes.model.sync
        webnotes.model.sync.sync(options.sync[0], options.sync[1],
                                 options.force or 0)

    elif options.update:
        update_erpnext(options.update[0], options.update[1])

    elif options.patch_sync_build:
        patch_sync_build()

    elif options.patch_sync:
        patch_sync()

    elif options.cleanup_data:
        from utilities import cleanup_data
        cleanup_data.run()

    elif options.domain:
        webnotes.conn.set_value('Website Settings', None, 'subdomain',
                                options.domain)
        webnotes.conn.commit()
        print "Domain set to", options.domain

    elif options.build_web_cache:
        # build wn-web.js and wn-web.css
        import webnotes.cms.make
        webnotes.cms.make.make()

        import website.web_cache
        website.web_cache.refresh_cache(['Blog'])

    elif options.append_future_import:
        append_future_import()

    elif options.backup:
        from webnotes.utils.backups import scheduled_backup
        scheduled_backup()

    # print messages
    if webnotes.message_log:
        print '\n'.join(webnotes.message_log)

    if options.test is not None:
        module_name = options.test
        import unittest

        del sys.argv[1:]
        # is there a better way?
        exec('from %s import *' % module_name) in globals()
        unittest.main()
Beispiel #13
0
    # write conf file
    with open(os.path.join(erpnext_path, "conf.py"), "w") as new_conf:
        new_conf.write(content)

# install db
import sys

sys.path.append(erpnext_path)
sys.path.append(os.path.join(erpnext_path, "lib", "py"))
import conf

sys.path.append(conf.modules_path)

from webnotes.install_lib.install import Installer

inst = Installer("root", root_pwd)
inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, "data", "master.sql"), verbose=1)

# apply patches
os.chdir(erpnext_path)
os.system("lib/wnf.py --update origin master")

# set filemode false
os.system("git config core.filemode false")
os.chdir(os.path.join(erpnext_path, "lib"))
os.system("git config core.filemode false")

steps_remaining = """
Notes:
------
Beispiel #14
0
def run():
	sys.path.append('lib')
	sys.path.append('lib/py')
	import webnotes
	import webnotes.defs
	sys.path.append(webnotes.defs.modules_path)

	(options, args) = setup_options()


	from webnotes.db import Database
	import webnotes.modules.patch_handler

	# connect
	if options.db_name is not None:
		webnotes.connect(options.db_name)

	# build
	if options.build:
		import build.project
		build.project.build()		

	elif options.clear:
		from build.project import increment_version
		print "Version:" + str(increment_version())
	
	# code replace
	elif options.replace:
		replace_code('.', options.replace[0], options.replace[1], options.replace[2])
	
	# git
	elif options.status:
		os.system('git status')
		os.chdir('lib')
		os.system('git status')
	
	elif options.pull:
		os.system('git pull %s %s' % (options.pull[0], options.pull[1]))
		os.chdir('lib')
		os.system('git pull %s %s' % (options.pull[0], options.pull[1]))

	elif options.push:
		os.system('git commit -a -m "%s"' % options.push[2])
		os.system('git push %s %s' % (options.push[0], options.push[1]))
		os.chdir('lib')
		os.system('git commit -a -m "%s"' % options.push[2])
		os.system('git push %s %s' % (options.push[0], options.push[1]))
	
	# patch
	elif options.patch_list:
		# clear log
		webnotes.modules.patch_handler.log_list = []
		
		# run individual patches
		for patch in options.patch_list:
			webnotes.modules.patch_handler.run_single(\
				patchmodule = patch, force = options.force)
		
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
		# reload
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		webnotes.modules.patch_handler.run_all()
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root', options.install[0])
		inst.import_from_db(options.install[1], source_path=options.install[2], \
			password='******', verbose = 1)
	
	elif options.sync_with_gateway:
		if int(options.sync_with_gateway[0]) in [0, 1]:
			webnotes.conn.begin()
			webnotes.conn.sql("""\
				UPDATE `tabSingles` SET value=%s
				WHERE field='sync_with_gateway' AND doctype='Control Panel'""", int(options.sync_with_gateway[0]))
			webnotes.conn.commit()
			webnotes.message_log.append("sync_with_gateway set to %s" % options.sync_with_gateway[0])
		else:
			webnotes.message_log.append("ERROR: sync_with_gateway can be either 0 or 1")
	
	elif options.diff_ref_file is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_file()

	elif options.diff_ref_db is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_db()
	
	elif options.run_scheduler:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.execute()
	
	elif options.run_scheduler_event is not None:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event)
	
	elif options.cci is not None:
		if options.cci=='all':
			webnotes.conn.sql("DELETE FROM __CacheItem")
		else:
			from webnotes.utils.cache import CacheItem
			CacheItem(options.cci).clear()

	# print messages
	if webnotes.message_log:
		print '\n'.join(webnotes.message_log)
Beispiel #15
0
def run():
	sys.path.append('.')
	sys.path.append('lib')
	sys.path.append('app')

	(options, args) = setup_options()
	
	# build
	if options.build:
		from webnotes.utils import bundlejs
		if options.no_cms:
			cms_make = False
		else:
			cms_make = True
		bundlejs.bundle(options.no_compress, cms_make)
		return
		
	elif options.watch:
		from webnotes.utils import bundlejs
		bundlejs.watch(True)
		return

	# code replace
	elif options.replace:
		print options.replace
		replace_code('.', options.replace[0], options.replace[1], options.replace[2], force=options.force)
		return
	
	# git
	elif options.status:
		os.chdir('lib')
		os.system('git status')
		os.chdir('../app')
		os.system('git status')
		return

	elif options.git:
		os.chdir('lib')
		os.system('git %s' % options.git)
		os.chdir('../app')
		os.system('git %s' % options.git)
		return
		
	import webnotes
	import conf
	from webnotes.db import Database
	import webnotes.modules.patch_handler

	# connect
	if options.db_name is not None:
		if options.password:
			webnotes.connect(options.db_name, options.password)
		else:
			webnotes.connect(options.db_name)
	elif not any([options.install, options.pull]):
		webnotes.connect(conf.db_name)

	if options.pull:
		pull(options.pull[0], options.pull[1], build=True)

	elif options.commit:
		os.chdir('lib')
		os.system('git commit -a -m "%s"' % (options.commit))
		os.chdir('../app')
		os.system('git commit -a -m "%s"' % (options.commit))

	elif options.push:
		os.chdir('lib')
		os.system('git push %s %s' % (options.push[0], options.push[1]))
		os.chdir('../app')
		os.system('git push %s %s' % (options.push[0], options.push[1]))
				
	elif options.checkout:
		os.chdir('lib')
		os.system('git checkout %s' % options.checkout)
		os.chdir('../app')
		os.system('git checkout %s' % options.checkout)
			
	# patch
	elif options.patch_list:
		# clear log
		webnotes.modules.patch_handler.log_list = []
		
		# run individual patches
		for patch in options.patch_list:
			webnotes.modules.patch_handler.run_single(\
				patchmodule = patch, force = options.force)
		
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
		# reload
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		apply_latest_patches()
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install[0], source_path=options.install[1], \
			password='******', verbose = 1)
	
	elif options.diff_ref_file is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_file()

	elif options.diff_ref_db is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_db()
	
	elif options.run_scheduler:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.execute()
	
	elif options.run_scheduler_event is not None:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event)
		
	elif options.sync_all is not None:
		sync_all(options.force or 0)

	elif options.sync is not None:
		import webnotes.model.sync
		webnotes.model.sync.sync(options.sync[0], options.sync[1], options.force or 0)
	
	elif options.update:
		update_erpnext(options.update[0], options.update[1])
	
	elif options.patch_sync_build:
		patch_sync_build()
	
	elif options.patch_sync:
		patch_sync()

	elif options.cleanup_data:
		from utilities import cleanup_data
		cleanup_data.run()
		
	elif options.domain:
		webnotes.conn.set_value('Website Settings', None, 'subdomain', options.domain)
		webnotes.conn.commit()
		print "Domain set to", options.domain
		
	elif options.clear_web:
		# build wn-web.js and wn-web.css
		from website.helpers.make_web_include_files import make
		make()
	
		import website.utils
		website.utils.clear_cache()
		
	elif options.clear_cache:
		clear_cache()
		
	elif options.append_future_import:
		append_future_import()

	elif options.backup:
		from webnotes.utils.backups import scheduled_backup
		scheduled_backup()
		
	# print messages
	if webnotes.message_log:
		print '\n'.join(webnotes.message_log)
		
	if options.test is not None:
		module_name = options.test
		import unittest

		del sys.argv[1:]
		# is there a better way?
		exec ('from %s import *' % module_name) in globals()		
		unittest.main()
Beispiel #16
0
def install():
    print "Creating Fresh Database..."
    from webnotes.install_lib.install import Installer
    from webnotes import conf
    inst = Installer('root')
    inst.install(conf.demo_db_name, verbose=1, force=1)
Beispiel #17
0
def install():
	print "Creating Fresh Database..."
	from webnotes.install_lib.install import Installer
	import conf
	inst = Installer('root')
	inst.import_from_db(conf.demo_db_name, verbose = 1)
Beispiel #18
0
def run():
    sys.path.append(".")
    sys.path.append("lib")
    sys.path.append("app")

    (options, args) = setup_options()

    # build
    if options.build:
        from webnotes.utils import bundlejs

        if options.no_cms:
            cms_make = False
        else:
            cms_make = True
        bundlejs.bundle(False, cms_make)
        return

    elif options.watch:
        from webnotes.utils import bundlejs

        bundlejs.watch(True)
        return

        # code replace
    elif options.replace:
        print options.replace
        replace_code(".", options.replace[0], options.replace[1], options.replace[2], force=options.force)
        return

        # git
    elif options.status:
        os.chdir("lib")
        os.system("git status")
        os.chdir("../app")
        os.system("git status")
        return

    elif options.git:
        os.chdir("lib")
        os.system("git %s" % options.git)
        os.chdir("../app")
        os.system("git %s" % options.git)
        return

    import webnotes
    import conf
    from webnotes.db import Database
    import webnotes.modules.patch_handler

    # connect
    if options.db_name is not None:
        if options.password:
            webnotes.connect(options.db_name, options.password)
        else:
            webnotes.connect(options.db_name)
    elif not any([options.install, options.pull]):
        webnotes.connect(conf.db_name)

    if options.pull:
        pull(options.pull[0], options.pull[1], build=True)

    elif options.commit:
        os.chdir("lib")
        os.system('git commit -a -m "%s"' % (options.commit))
        os.chdir("../app")
        os.system('git commit -a -m "%s"' % (options.commit))

    elif options.push:
        os.chdir("lib")
        os.system("git push %s %s" % (options.push[0], options.push[1]))
        os.chdir("../app")
        os.system("git push %s %s" % (options.push[0], options.push[1]))

    elif options.checkout:
        os.chdir("lib")
        os.system("git checkout %s" % options.checkout)
        os.chdir("../app")
        os.system("git checkout %s" % options.checkout)

        # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(patchmodule=patch, force=options.force)

        print "\n".join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(
            {"module": options.reload_doc[0], "dt": options.reload_doc[1], "dn": options.reload_doc[2]}
        )
        print "\n".join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc

        export_doc(options.export_doc[0], options.export_doc[1])

        # run all pending
    elif options.run_latest:
        apply_latest_patches()

    elif options.install:
        from webnotes.install_lib.install import Installer

        inst = Installer("root")
        inst.import_from_db(options.install[0], source_path=options.install[1], password="******", verbose=1)

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff

        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff

        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler

        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler

        print webnotes.utils.scheduler.trigger("execute_" + options.run_scheduler_event)

    elif options.sync_all is not None:
        sync_all(options.force or 0)

    elif options.sync is not None:
        import webnotes.model.sync

        webnotes.model.sync.sync(options.sync[0], options.sync[1], options.force or 0)

    elif options.update:
        update_erpnext(options.update[0], options.update[1])

    elif options.patch_sync_build:
        patch_sync_build()

    elif options.patch_sync:
        patch_sync()

    elif options.cleanup_data:
        from utilities import cleanup_data

        cleanup_data.run()

    elif options.domain:
        webnotes.conn.set_value("Website Settings", None, "subdomain", options.domain)
        webnotes.conn.commit()
        print "Domain set to", options.domain

    elif options.clear_web:
        # build wn-web.js and wn-web.css
        from website.helpers.make_web_include_files import make

        make()

        import website.utils

        website.utils.clear_cache()

    elif options.clear_cache:
        clear_cache()

    elif options.append_future_import:
        append_future_import()

    elif options.backup:
        from webnotes.utils.backups import scheduled_backup

        scheduled_backup()

        # print messages
    if webnotes.message_log:
        print "\n".join(webnotes.message_log)

    if options.test is not None:
        module_name = options.test
        import unittest

        del sys.argv[1:]
        # is there a better way?
        exec ("from %s import *" % module_name) in globals()
        unittest.main()

    elif options.build_message_files:
        import webnotes.translate

        webnotes.translate.build_message_files()

    elif options.export_messages:
        import webnotes.translate

        webnotes.translate.export_messages(*options.export_messages)

    elif options.import_messages:
        import webnotes.translate

        webnotes.translate.import_messages(*options.import_messages)

    elif options.google_translate:
        from webnotes.translate import google_translate

        google_translate(*options.google_translate)

    elif options.translate:
        from webnotes.translate import build_message_files, export_messages, google_translate, import_messages

        print "Extracting messages..."
        build_message_files()
        print "Compiling messages in one file..."
        export_messages(options.translate, "_lang_tmp.csv")
        print "Translating via Google Translate..."
        google_translate(options.translate, "_lang_tmp.csv", "_lang_tmp1.csv")
        print "Updating language files..."
        import_messages(options.translate, "_lang_tmp1.csv")
        print "Deleting temp files..."
        os.remove("_lang_tmp.csv")
        os.remove("_lang_tmp1.csv")
Beispiel #19
0
def run():
    sys.path.append('lib')
    sys.path.append('lib/py')
    import webnotes
    import webnotes.defs
    sys.path.append(webnotes.defs.modules_path)

    (options, args) = setup_options()

    from webnotes.db import Database
    import webnotes.modules.patch_handler

    # connect
    if options.db_name is not None:
        webnotes.connect(options.db_name)

    # build
    if options.build:
        import build.project
        build.project.build()

    elif options.clear:
        from build.project import increment_version
        print "Version:" + str(increment_version())

    # code replace
    elif options.replace:
        replace_code('.', options.replace[0], options.replace[1],
                     options.replace[2])

    # git
    elif options.status:
        os.system('git status')
        os.chdir('lib')
        os.system('git status')

    elif options.pull:
        os.system('git pull %s %s' % (options.pull[0], options.pull[1]))
        os.chdir('lib')
        os.system('git pull %s %s' % (options.pull[0], options.pull[1]))

    elif options.push:
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))
        os.chdir('lib')
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))

    # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(\
             patchmodule = patch, force = options.force)

        print '\n'.join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(\
         {"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc
        export_doc(options.export_doc[0], options.export_doc[1])

    # run all pending
    elif options.run_latest:
        webnotes.modules.patch_handler.run_all()
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.install:
        from webnotes.install_lib.install import Installer
        inst = Installer('root', options.install[0])
        inst.import_from_db(options.install[1], source_path=options.install[2], \
         password='******', verbose = 1)

    elif options.sync_with_gateway:
        if int(options.sync_with_gateway[0]) in [0, 1]:
            webnotes.conn.begin()
            webnotes.conn.sql(
                """\
				UPDATE `tabSingles` SET value=%s
				WHERE field='sync_with_gateway' AND doctype='Control Panel'""",
                int(options.sync_with_gateway[0]))
            webnotes.conn.commit()
            webnotes.message_log.append("sync_with_gateway set to %s" %
                                        options.sync_with_gateway[0])
        else:
            webnotes.message_log.append(
                "ERROR: sync_with_gateway can be either 0 or 1")

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.trigger('execute_' +
                                               options.run_scheduler_event)

    elif options.cci is not None:
        if options.cci == 'all':
            webnotes.conn.sql("DELETE FROM __CacheItem")
        else:
            from webnotes.utils.cache import CacheItem
            CacheItem(options.cci).clear()

    # print messages
    if webnotes.message_log:
        print '\n'.join(webnotes.message_log)
Beispiel #20
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()
Beispiel #21
0
def run():
	sys.path.append('.')
	sys.path.append('lib')
	sys.path.append('app')

	(options, args) = setup_options()
	
	# build
	if options.build:
		from webnotes import build
		if options.no_cms:
			cms_make = False
		else:
			cms_make = True
		build.bundle(False, cms_make)
		return
		
	elif options.watch:
		from webnotes import build
		build.watch(True)
		return

	# code replace
	elif options.replace:
		print options.replace
		replace_code('.', options.replace[0], options.replace[1], options.replace[2], force=options.force)
		return
	
	# git
	elif options.status:
		os.chdir('lib')
		os.system('git status')
		os.chdir('../app')
		os.system('git status')
		return

	elif options.git:
		os.chdir('lib')
		os.system('git %s' % options.git)
		os.chdir('../app')
		os.system('git %s' % options.git)
		return
		
	import webnotes
	import conf
	from webnotes.db import Database
	import webnotes.modules.patch_handler
	webnotes.print_messages = True
	
	# connect
	if options.db_name is not None:
		if options.password:
			webnotes.connect(options.db_name, options.password)
		else:
			webnotes.connect(options.db_name)
	elif not any([options.install, options.pull, options.install_fresh]):
		webnotes.connect(conf.db_name)

	if options.pull:
		pull(options.pull[0], options.pull[1], build=True)

	elif options.commit:
		os.chdir('lib')
		os.system('git commit -a -m "%s"' % (options.commit))
		os.chdir('../app')
		os.system('git commit -a -m "%s"' % (options.commit))

	elif options.push:
		if not args:
			args = ["origin", conf.branch]
		
		os.chdir('lib')
		os.system('git push %s %s' % (args[0], args[1]))
		os.chdir('../app')
		os.system('git push %s %s' % (args[0], args[1]))
				
	elif options.checkout:
		os.chdir('lib')
		os.system('git checkout %s' % options.checkout)
		os.chdir('../app')
		os.system('git checkout %s' % options.checkout)
			
	# patch
	elif options.patch_list:
		# clear log
		webnotes.modules.patch_handler.log_list = []
		
		# run individual patches
		for patch in options.patch_list:
			webnotes.modules.patch_handler.run_single(\
				patchmodule = patch, force = options.force)
		
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
		# reload
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		apply_latest_patches()
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install[0], source_path=options.install[1],
			verbose = 1)

	elif options.install_fresh:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install_fresh, verbose = 1)

	elif options.make_demo:
		import utilities.make_demo
		utilities.make_demo.make()

	elif options.make_demo_fresh:
		import utilities.make_demo
		utilities.make_demo.make(True)

	elif options.diff_ref_file is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_file()

	elif options.diff_ref_db is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_db()
	
	elif options.run_scheduler:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.execute()
	
	elif options.run_scheduler_event is not None:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event)
		
	elif options.sync_all is not None:
		sync_all(options.force or 0)

	elif options.sync is not None:
		webnotes.reload_doc(options.sync[0], "doctype", options.sync[1])
	
	elif options.update:
		if not args:
			args = ["origin", conf.branch]
			
		update_erpnext(args[0], args[1])
		
	elif options.patch_sync_build:
		patch_sync_build()
	
	elif options.patch_sync:
		patch_sync()

	elif options.cleanup_data:
		from utilities import cleanup_data
		cleanup_data.run()
		
	elif options.domain:
		webnotes.conn.set_value('Website Settings', None, 'subdomain', options.domain)
		webnotes.conn.commit()
		print "Domain set to", options.domain
		
	elif options.clear_web:
		# build wn-web.js and wn-web.css
		from website.helpers.make_web_include_files import make
		make()
	
		import webnotes.webutils
		webnotes.webutils.clear_cache()
		
	elif options.clear_cache:
		clear_cache()
		
	elif options.clear_defaults:
		import webnotes.defaults
		webnotes.defaults.clear_cache()
		webnotes.clear_cache()
		
	elif options.append_future_import:
		append_future_import()

	elif options.backup:
		from webnotes.utils.backups import scheduled_backup
		scheduled_backup(ignore_files = True)
		
	# print messages
	if webnotes.message_log:
		print '\n'.join(webnotes.message_log)
		
	elif options.build_message_files:
		import webnotes.translate
		webnotes.translate.build_message_files()
		
	elif options.export_messages:
		import webnotes.translate
		webnotes.translate.export_messages(*options.export_messages)

	elif options.import_messages:
		import webnotes.translate
		webnotes.translate.import_messages(*options.import_messages)
	
	elif options.google_translate:
		from webnotes.translate import google_translate
		google_translate(*options.google_translate)
	
	elif options.translate:
		from webnotes.translate import translate
		translate(options.translate)
		
	elif options.docs:
		from core.doctype.documentation_tool.documentation_tool import write_static
		write_static()

	elif options.reset_perms:
		for d in webnotes.conn.sql_list("""select name from `tabDocType`
			where ifnull(istable, 0)=0 and ifnull(custom, 0)=0"""):
				try:
					webnotes.clear_cache(doctype=d)
					webnotes.reset_perms(d)
				except:
					pass
Beispiel #22
0
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		apply_latest_patches()
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root', options.root_password)
		inst.import_from_db(options.install[0], source_path=options.install[1],
			verbose = 1)

	elif options.install_fresh:
		from webnotes.install_lib.install import Installer
		inst = Installer('root', options.root_password)
		inst.import_from_db(options.install_fresh, verbose = 1)

	elif options.reinstall:
		from webnotes.install_lib.install import Installer
		inst = Installer('root', options.root_password)
		import conf
		inst.import_from_db(conf.db_name, verbose = 1)

	elif options.make_demo:
Beispiel #23
0
def install():
	print "Creating Fresh Database..."
	from webnotes.install_lib.install import Installer
	inst = Installer('root')
	inst.import_from_db("demo", verbose = 1)
Beispiel #24
0
def run():
	sys.path.append('.')
	sys.path.append('lib')
	sys.path.append('app')

	(options, args) = setup_options()
	
	# build
	if options.build:
		from webnotes.utils import bundlejs
		if options.no_cms:
			cms_make = False
		else:
			cms_make = True
		bundlejs.bundle(False, cms_make)
		return
		
	elif options.watch:
		from webnotes.utils import bundlejs
		bundlejs.watch(True)
		return

	# code replace
	elif options.replace:
		print options.replace
		replace_code('.', options.replace[0], options.replace[1], options.replace[2], force=options.force)
		return
	
	# git
	elif options.status:
		os.chdir('lib')
		os.system('git status')
		os.chdir('../app')
		os.system('git status')
		return

	elif options.git:
		os.chdir('lib')
		os.system('git %s' % options.git)
		os.chdir('../app')
		os.system('git %s' % options.git)
		return
		
	import webnotes
	import conf
	from webnotes.db import Database
	import webnotes.modules.patch_handler

	# connect
	if options.db_name is not None:
		if options.password:
			webnotes.connect(options.db_name, options.password)
		else:
			webnotes.connect(options.db_name)
	elif not any([options.install, options.pull, options.install_fresh]):
		webnotes.connect(conf.db_name)

	if options.pull:
		pull(options.pull[0], options.pull[1], build=True)

	elif options.commit:
		os.chdir('lib')
		os.system('git commit -a -m "%s"' % (options.commit))
		os.chdir('../app')
		os.system('git commit -a -m "%s"' % (options.commit))

	elif options.push:
		os.chdir('lib')
		os.system('git push %s %s' % (options.push[0], options.push[1]))
		os.chdir('../app')
		os.system('git push %s %s' % (options.push[0], options.push[1]))
				
	elif options.checkout:
		os.chdir('lib')
		os.system('git checkout %s' % options.checkout)
		os.chdir('../app')
		os.system('git checkout %s' % options.checkout)
			
	# patch
	elif options.patch_list:
		# clear log
		webnotes.modules.patch_handler.log_list = []
		
		# run individual patches
		for patch in options.patch_list:
			webnotes.modules.patch_handler.run_single(\
				patchmodule = patch, force = options.force)
		
		print '\n'.join(webnotes.modules.patch_handler.log_list)
	
		# reload
	elif options.reload_doc:
		webnotes.modules.patch_handler.reload_doc(\
			{"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})		
		print '\n'.join(webnotes.modules.patch_handler.log_list)

	elif options.export_doc:
		from webnotes.modules import export_doc
		export_doc(options.export_doc[0], options.export_doc[1])

	# run all pending
	elif options.run_latest:
		apply_latest_patches()
	
	elif options.install:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install[0], source_path=options.install[1],
			verbose = 1)

	elif options.install_fresh:
		from webnotes.install_lib.install import Installer
		inst = Installer('root')
		inst.import_from_db(options.install_fresh, source_path="lib/conf/Framework.sql",
			verbose = 1)

	elif options.diff_ref_file is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_file()

	elif options.diff_ref_db is not None:
		import webnotes.modules.diff
		webnotes.modules.diff.diff_ref_db()
	
	elif options.run_scheduler:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.execute()
	
	elif options.run_scheduler_event is not None:
		import webnotes.utils.scheduler
		print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event)
		
	elif options.sync_all is not None:
		sync_all(options.force or 0)

	elif options.sync is not None:
		import webnotes.model.sync
		webnotes.model.sync.sync(options.sync[0], options.sync[1], options.force or 0)
	
	elif options.update:
		update_erpnext(options.update[0], options.update[1])
	
	elif options.patch_sync_build:
		patch_sync_build()
	
	elif options.patch_sync:
		patch_sync()

	elif options.cleanup_data:
		from utilities import cleanup_data
		cleanup_data.run()
		
	elif options.domain:
		webnotes.conn.set_value('Website Settings', None, 'subdomain', options.domain)
		webnotes.conn.commit()
		print "Domain set to", options.domain
		
	elif options.clear_web:
		# build wn-web.js and wn-web.css
		from website.helpers.make_web_include_files import make
		make()
	
		import website.utils
		website.utils.clear_cache()
		
	elif options.clear_cache:
		clear_cache()
		
	elif options.append_future_import:
		append_future_import()

	elif options.backup:
		from webnotes.utils.backups import scheduled_backup
		scheduled_backup()
		
	# print messages
	if webnotes.message_log:
		print '\n'.join(webnotes.message_log)
		
	if options.test is not None:
		module_name = options.test
		import unittest

		del sys.argv[1:]
		# is there a better way?
		exec ('from %s import *' % module_name) in globals()		
		unittest.main()

	elif options.build_message_files:
		import webnotes.translate
		webnotes.translate.build_message_files()
		
	elif options.export_messages:
		import webnotes.translate
		webnotes.translate.export_messages(*options.export_messages)

	elif options.import_messages:
		import webnotes.translate
		webnotes.translate.import_messages(*options.import_messages)
	
	elif options.google_translate:
		from webnotes.translate import google_translate
		google_translate(*options.google_translate)
	
	elif options.translate:
		from webnotes.translate import build_message_files, \
			export_messages, google_translate, import_messages
			
		languages = [options.translate]
		if options.translate=="all":
			from startup import lang_list
			languages = lang_list
			
		print "Extracting messages..."
		build_message_files()
		for lang in languages:
			if lang != "en":
				filename = 'app/translations/'+lang+'.csv'
				print "For " + lang + ":"
				print "Compiling messages in one file..."
				export_messages(lang, '_lang_tmp.csv')
				print "Translating via Google Translate..."
				google_translate(lang, '_lang_tmp.csv', filename)
				print "Updating language files..."
				import_messages(lang, filename)
				print "Deleting temp files..."
				os.remove('_lang_tmp.csv')
Beispiel #25
0
		os.path.join(erpnext_path, 'logs', 'error_log.txt'), content)
		
	
	# write conf file
	with open(os.path.join(erpnext_path, 'conf.py'), 'w') as new_conf:
		new_conf.write(content)	

# install db
import sys
sys.path.append(erpnext_path)
sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
import conf
sys.path.append(conf.modules_path)

from webnotes.install_lib.install import Installer
inst = Installer('root', root_pwd)
inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, 'data', 'master.sql'), verbose = 1)

# apply patches
os.chdir(erpnext_path)
os.system("lib/wnf.py --update origin master")

# set filemode false
os.system("git config core.filemode false")
os.chdir(os.path.join(erpnext_path, 'lib'))
os.system("git config core.filemode false")

steps_remaining = """
Notes:
------
Beispiel #26
0
def run():
    sys.path.append('.')
    sys.path.append('lib')
    sys.path.append('app')

    (options, args) = setup_options()

    # build
    if options.build:
        from webnotes.utils import bundlejs
        if options.no_cms:
            cms_make = False
        else:
            cms_make = True
        bundlejs.bundle(False, cms_make)
        return

    elif options.watch:
        from webnotes.utils import bundlejs
        bundlejs.watch(True)
        return

    # code replace
    elif options.replace:
        print options.replace
        replace_code('.',
                     options.replace[0],
                     options.replace[1],
                     options.replace[2],
                     force=options.force)
        return

    # git
    elif options.status:
        os.chdir('lib')
        os.system('git status')
        os.chdir('../app')
        os.system('git status')
        return

    elif options.git:
        os.chdir('lib')
        os.system('git %s' % options.git)
        os.chdir('../app')
        os.system('git %s' % options.git)
        return

    import webnotes
    import conf
    from webnotes.db import Database
    import webnotes.modules.patch_handler

    # connect
    if options.db_name is not None:
        if options.password:
            webnotes.connect(options.db_name, options.password)
        else:
            webnotes.connect(options.db_name)
    elif not any([options.install, options.pull, options.install_fresh]):
        webnotes.connect(conf.db_name)

    if options.pull:
        pull(options.pull[0], options.pull[1], build=True)

    elif options.commit:
        os.chdir('lib')
        os.system('git commit -a -m "%s"' % (options.commit))
        os.chdir('../app')
        os.system('git commit -a -m "%s"' % (options.commit))

    elif options.push:
        os.chdir('lib')
        os.system('git push %s %s' % (options.push[0], options.push[1]))
        os.chdir('../app')
        os.system('git push %s %s' % (options.push[0], options.push[1]))

    elif options.checkout:
        os.chdir('lib')
        os.system('git checkout %s' % options.checkout)
        os.chdir('../app')
        os.system('git checkout %s' % options.checkout)

    # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(\
             patchmodule = patch, force = options.force)

        print '\n'.join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(\
         {"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc
        export_doc(options.export_doc[0], options.export_doc[1])

    # run all pending
    elif options.run_latest:
        apply_latest_patches()

    elif options.install:
        from webnotes.install_lib.install import Installer
        inst = Installer('root')
        inst.import_from_db(options.install[0],
                            source_path=options.install[1],
                            verbose=1)

    elif options.install_fresh:
        from webnotes.install_lib.install import Installer
        inst = Installer('root')
        inst.import_from_db(options.install_fresh,
                            source_path="lib/conf/Framework.sql",
                            verbose=1)

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.trigger('execute_' +
                                               options.run_scheduler_event)

    elif options.sync_all is not None:
        sync_all(options.force or 0)

    elif options.sync is not None:
        webnotes.reload_doc(options.sync[0], "doctype", options.sync[1])

    elif options.update:
        update_erpnext(options.update[0], options.update[1])

    elif options.patch_sync_build:
        patch_sync_build()

    elif options.patch_sync:
        patch_sync()

    elif options.cleanup_data:
        from utilities import cleanup_data
        cleanup_data.run()

    elif options.domain:
        webnotes.conn.set_value('Website Settings', None, 'subdomain',
                                options.domain)
        webnotes.conn.commit()
        print "Domain set to", options.domain

    elif options.clear_web:
        # build wn-web.js and wn-web.css
        from website.helpers.make_web_include_files import make
        make()

        import webnotes.webutils
        webnotes.webutils.clear_cache()

    elif options.clear_cache:
        clear_cache()

    elif options.append_future_import:
        append_future_import()

    elif options.backup:
        from webnotes.utils.backups import scheduled_backup
        scheduled_backup(ignore_files=True)

    # print messages
    if webnotes.message_log:
        print '\n'.join(webnotes.message_log)

    if options.test is not None:
        module_name = options.test
        import unittest

        del sys.argv[1:]
        # is there a better way?
        exec('from %s import *' % module_name) in globals()
        unittest.main()

    elif options.build_message_files:
        import webnotes.translate
        webnotes.translate.build_message_files()

    elif options.export_messages:
        import webnotes.translate
        webnotes.translate.export_messages(*options.export_messages)

    elif options.import_messages:
        import webnotes.translate
        webnotes.translate.import_messages(*options.import_messages)

    elif options.google_translate:
        from webnotes.translate import google_translate
        google_translate(*options.google_translate)

    elif options.translate:
        from webnotes.translate import build_message_files, \
         export_messages, google_translate, import_messages

        languages = [options.translate]
        if options.translate == "all":
            from startup import lang_list
            languages = lang_list

        print "Extracting messages..."
        build_message_files()
        for lang in languages:
            if lang != "en":
                filename = 'app/translations/' + lang + '.csv'
                print "For " + lang + ":"
                print "Compiling messages in one file..."
                export_messages(lang, '_lang_tmp.csv')
                print "Translating via Google Translate..."
                google_translate(lang, '_lang_tmp.csv', filename)
                print "Updating language files..."
                import_messages(lang, filename)
                print "Deleting temp files..."
                os.remove('_lang_tmp.csv')
Beispiel #27
0
def run():
    sys.path.append('.')
    sys.path.append('lib')
    sys.path.append('app')

    (options, args) = setup_options()

    # build
    if options.build:
        from webnotes import build
        if options.no_cms:
            cms_make = False
        else:
            cms_make = True
        build.bundle(False, cms_make)
        return

    elif options.watch:
        from webnotes import build
        build.watch(True)
        return

    # code replace
    elif options.replace:
        print options.replace
        replace_code('.',
                     options.replace[0],
                     options.replace[1],
                     options.replace[2],
                     force=options.force)
        return

    # git
    elif options.status:
        os.chdir('lib')
        os.system('git status')
        os.chdir('../app')
        os.system('git status')
        return

    elif options.git:
        os.chdir('lib')
        os.system('git %s' % options.git)
        os.chdir('../app')
        os.system('git %s' % options.git)
        return

    import webnotes
    import conf
    from webnotes.db import Database
    import webnotes.modules.patch_handler
    webnotes.print_messages = True

    # connect
    if options.db_name is not None:
        if options.password:
            webnotes.connect(options.db_name, options.password)
        else:
            webnotes.connect(options.db_name)
    elif not any([options.install, options.pull, options.install_fresh]):
        webnotes.connect(conf.db_name)

    if options.pull:
        pull(options.pull[0], options.pull[1], build=True)

    elif options.commit:
        os.chdir('lib')
        os.system('git commit -a -m "%s"' % (options.commit))
        os.chdir('../app')
        os.system('git commit -a -m "%s"' % (options.commit))

    elif options.push:
        if not args:
            args = ["origin", conf.branch]

        os.chdir('lib')
        os.system('git push %s %s' % (args[0], args[1]))
        os.chdir('../app')
        os.system('git push %s %s' % (args[0], args[1]))

    elif options.checkout:
        os.chdir('lib')
        os.system('git checkout %s' % options.checkout)
        os.chdir('../app')
        os.system('git checkout %s' % options.checkout)

    # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(\
             patchmodule = patch, force = options.force)

        print '\n'.join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(\
         {"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc
        export_doc(options.export_doc[0], options.export_doc[1])

    # run all pending
    elif options.run_latest:
        apply_latest_patches()

    elif options.install:
        from webnotes.install_lib.install import Installer
        inst = Installer('root')
        inst.import_from_db(options.install[0],
                            source_path=options.install[1],
                            verbose=1)

    elif options.install_fresh:
        from webnotes.install_lib.install import Installer
        inst = Installer('root')
        inst.import_from_db(options.install_fresh, verbose=1)

    elif options.make_demo:
        import utilities.make_demo
        utilities.make_demo.make()

    elif options.make_demo_fresh:
        import utilities.make_demo
        utilities.make_demo.make(True)

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.trigger('execute_' +
                                               options.run_scheduler_event)

    elif options.sync_all is not None:
        sync_all(options.force or 0)

    elif options.sync is not None:
        webnotes.reload_doc(options.sync[0], "doctype", options.sync[1])

    elif options.update:
        if not args:
            args = ["origin", conf.branch]

        update_erpnext(args[0], args[1])

    elif options.patch_sync_build:
        patch_sync_build()

    elif options.patch_sync:
        patch_sync()

    elif options.cleanup_data:
        from utilities import cleanup_data
        cleanup_data.run()

    elif options.domain:
        webnotes.conn.set_value('Website Settings', None, 'subdomain',
                                options.domain)
        webnotes.conn.commit()
        print "Domain set to", options.domain

    elif options.clear_web:
        # build wn-web.js and wn-web.css
        from website.helpers.make_web_include_files import make
        make()

        import webnotes.webutils
        webnotes.webutils.clear_cache()

    elif options.clear_cache:
        clear_cache()

    elif options.clear_defaults:
        import webnotes.defaults
        webnotes.defaults.clear_cache()
        webnotes.clear_cache()

    elif options.append_future_import:
        append_future_import()

    elif options.backup:
        from webnotes.utils.backups import scheduled_backup
        scheduled_backup(ignore_files=True)

    # print messages
    if webnotes.message_log:
        print '\n'.join(webnotes.message_log)

    elif options.build_message_files:
        import webnotes.translate
        webnotes.translate.build_message_files()

    elif options.export_messages:
        import webnotes.translate
        webnotes.translate.export_messages(*options.export_messages)

    elif options.import_messages:
        import webnotes.translate
        webnotes.translate.import_messages(*options.import_messages)

    elif options.google_translate:
        from webnotes.translate import google_translate
        google_translate(*options.google_translate)

    elif options.translate:
        from webnotes.translate import translate
        translate(options.translate)

    elif options.docs:
        from core.doctype.documentation_tool.documentation_tool import write_static
        write_static()

    elif options.reset_perms:
        for d in webnotes.conn.sql_list("""select name from `tabDocType`
			where ifnull(istable, 0)=0 and ifnull(custom, 0)=0"""):
            try:
                webnotes.clear_cache(doctype=d)
                webnotes.reset_perms(d)
            except:
                pass