Esempio n. 1
0
def install_app(context, apps):
    "Install a new app to site, supports multiple apps"
    from frappe.installer import install_app as _install_app

    exit_code = 0

    if not context.sites:
        raise SiteNotSpecifiedError

    for site in context.sites:
        frappe.init(site=site)
        frappe.connect()

        for app in apps:
            try:
                _install_app(app, verbose=context.verbose)
            except frappe.IncompatibleApp as err:
                err_msg = ":\n{}".format(err) if str(err) else ""
                print("App {} is Incompatible with Site {}{}".format(
                    app, site, err_msg))
                exit_code = 1
            except Exception as err:
                err_msg = ": {}\n{}".format(str(err), frappe.get_traceback())
                print("An error occurred while installing {}{}".format(
                    app, err_msg))
                exit_code = 1

        frappe.destroy()

    sys.exit(exit_code)
Esempio n. 2
0
def _new_site(db_name,
              site,
              mariadb_root_username=None,
              mariadb_root_password=None,
              admin_password=None,
              verbose=False,
              install_apps=None,
              source_sql=None,
              force=False,
              reinstall=False):
    """Install a new Frappe site"""

    if not db_name:
        db_name = hashlib.sha1(site).hexdigest()[:16]

    from frappe.installer import install_db, make_site_dirs
    from frappe.installer import install_app as _install_app
    import frappe.utils.scheduler

    frappe.init(site=site)

    try:
        # enable scheduler post install?
        enable_scheduler = _is_scheduler_enabled()
    except:
        enable_scheduler = False

    make_site_dirs()

    try:
        installing = touch_file(get_site_path('locks', 'installing.lock'))

        install_db(root_login=mariadb_root_username,
                   root_password=mariadb_root_password,
                   db_name=db_name,
                   admin_password=admin_password,
                   verbose=verbose,
                   source_sql=source_sql,
                   force=force,
                   reinstall=reinstall)

        apps_to_install = ['frappe'] + (frappe.conf.get("install_apps")
                                        or []) + (list(install_apps) or [])
        for app in apps_to_install:
            _install_app(app, verbose=verbose, set_as_patched=not source_sql)

        frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
        frappe.db.commit()

        scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled(
        ) else "enabled"
        print "*** Scheduler is", scheduler_status, "***"

    finally:
        if os.path.exists(installing):
            os.remove(installing)

        frappe.destroy()
Esempio n. 3
0
def install_app(context, app):
	"Install a new app to site"
	from frappe.installer import install_app as _install_app
	for site in context.sites:
		frappe.init(site=site)
		frappe.connect()
		try:
			_install_app(app, verbose=context.verbose)
		finally:
			frappe.destroy()
Esempio n. 4
0
def install_app(context, app):
    "Install a new app to site"
    from frappe.installer import install_app as _install_app
    for site in context.sites:
        frappe.init(site=site)
        frappe.connect()
        try:
            _install_app(app, verbose=context.verbose)
        finally:
            frappe.destroy()
Esempio n. 5
0
def install_app(context, apps):
    "Install a new app to site, supports multiple apps"
    from frappe.installer import install_app as _install_app
    for site in context.sites:
        frappe.init(site=site)
        frappe.connect()
        try:
            for app in apps:
                _install_app(app, verbose=context.verbose)
        finally:
            frappe.destroy()
    if not context.sites:
        raise SiteNotSpecifiedError
Esempio n. 6
0
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None,
	verbose=False, install_apps=None, source_sql=None,force=False, source_db=False, reinstall=False,
			  db_user_allowed_host=None):
	"""Install a new Frappe site"""

	if not db_name:
		db_name = hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	if source_db:
		source_sql = create_existing_db_backup(source_db, mariadb_root_password, mariadb_root_username)

	installing = None
	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall, db_user_allowed_host=db_user_allowed_host)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print("*** Scheduler is", scheduler_status, "***")

	except frappe.exceptions.ImproperDBConfigurationError:
		_drop_site(site, mariadb_root_username, mariadb_root_password, force=True)

	finally:
		if installing and os.path.exists(installing):
			os.remove(installing)

		frappe.destroy()
Esempio n. 7
0
def install_app(context, apps):
    "Install a new app to site, supports multiple apps"
    from frappe.installer import install_app as _install_app
    # Ensure that we're referencing a Python List, not a String.
    sites_list = context.sites
    if isinstance(sites_list, str):
        sites_list = [context.sites]

    for site in sites_list:
        frappe.init(site=site)
        frappe.connect()
        try:
            for app in apps:
                _install_app(app, verbose=context.verbose)
        finally:
            frappe.destroy()
Esempio n. 8
0
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None,
			  admin_password=None, verbose=False, install_apps=None, source_sql=None, force=False,
			  no_mariadb_socket=False, reinstall=False,  db_password=None, db_type=None, db_host=None,
			  db_port=None, new_site=False):
	"""Install a new Frappe site"""

	if not force and os.path.exists(site):
		print('Site {0} already exists'.format(site))
		sys.exit(1)

	if no_mariadb_socket and not db_type == "mariadb":
		print('--no-mariadb-socket requires db_type to be set to mariadb.')
		sys.exit(1)

	if not db_name:
		db_name = '_' + hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	installing = touch_file(get_site_path('locks', 'installing.lock'))

	install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
		admin_password=admin_password, verbose=verbose, source_sql=source_sql, force=force, reinstall=reinstall,
		db_password=db_password, db_type=db_type, db_host=db_host, db_port=db_port, no_mariadb_socket=no_mariadb_socket)
	apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
	for app in apps_to_install:
		_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	os.remove(installing)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	frappe.db.commit()

	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print("*** Scheduler is", scheduler_status, "***")
Esempio n. 9
0
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None,
	verbose=False, install_apps=None, source_sql=None,force=False, reinstall=False):
	"""Install a new Frappe site"""

	if not db_name:
		db_name = hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	installing = None
	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print("*** Scheduler is", scheduler_status, "***")

	except frappe.exceptions.ImproperDBConfigurationError:
		_drop_site(site, mariadb_root_username, mariadb_root_password, force=True)

	finally:
		if installing and os.path.exists(installing):
			os.remove(installing)

		frappe.destroy()
def _new_site(db_name,
              site,
              mariadb_root_username=None,
              mariadb_root_password=None,
              admin_password=None,
              verbose=False,
              install_apps=None,
              source_sql=None,
              force=False,
              reinstall=False):
    "Install a new Frappe site"
    from frappe.installer import install_db, make_site_dirs
    from frappe.installer import install_app as _install_app
    import frappe.utils.scheduler

    frappe.init(site=site)
    # enable scheduler post install?
    enable_scheduler = _is_scheduler_enabled()

    install_db(root_login=mariadb_root_username,
               root_password=mariadb_root_password,
               db_name=db_name,
               admin_password=admin_password,
               verbose=verbose,
               source_sql=source_sql,
               force=force,
               reinstall=reinstall)
    make_site_dirs()
    _install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

    if frappe.conf.get("install_apps"):
        for app in frappe.conf.install_apps:
            install_app(app, verbose=verbose, set_as_patched=not source_sql)

    if install_apps:
        for app in install_apps:
            _install_app(app, verbose=verbose, set_as_patched=not source_sql)

    frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
    scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled(
    ) else "enabled"
    print "*** Scheduler is", scheduler_status, "***"
    frappe.destroy()
def execute(**kwargs):
    """
    Use this to install apps; it checks for apps that are already installed.
    bench --site [site_name] execute [module_name].install_apps.execute
        --kwargs "{'apps': ['rebrandly_integration', 'printnode_integration']}"
    """
    apps_installed = frappe.db.sql(
        """SELECT DISTINCT app_name FROM `tabModule Def`""", as_dict=True)
    apps_installed = [v.app_name for v in apps_installed]

    for app in kwargs['apps']:
        if app not in apps_installed:
            print 'Installing app {0}'.format(app)

            frappe.init(site=kwargs['site'])
            frappe.connect()

            try:
                _install_app(app, verbose=False)
            finally:
                frappe.destroy()
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None, verbose=False, install_apps=None, source_sql=None,force=False, reinstall=False):
	"Install a new Frappe site"
	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except:
		enable_scheduler = False

	install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
	make_site_dirs()
	_install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	if install_apps:
		for app in install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print "*** Scheduler is", scheduler_status, "***"
	frappe.destroy()
Esempio n. 13
0
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None,
	verbose=False, install_apps=None, source_sql=None,force=False, reinstall=False):
	"""Install a new Frappe site"""

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except:
		enable_scheduler = False

	make_site_dirs()

	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print "*** Scheduler is", scheduler_status, "***"

	finally:
		os.remove(installing)
		frappe.destroy()