From c24a904ad62d25a60f43dcd17000611cdb5ae97a Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 5 Mar 2015 15:08:39 +0530 Subject: [PATCH] v5 upgrade --- bench/app.py | 10 ++++------ bench/cli.py | 27 +++++++++++++++++++-------- bench/utils.py | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/bench/app.py b/bench/app.py index 36a89d77..42aa5cca 100644 --- a/bench/app.py +++ b/bench/app.py @@ -78,22 +78,19 @@ def install_app(app, bench='.'): find_links=find_links)) add_to_appstxt(app, bench=bench) -def pull_all_apps(bench='.', upgrade=False): +def pull_all_apps(bench='.'): apps_dir = os.path.join(bench, 'apps') apps = [app for app in os.listdir(apps_dir) if os.path.isdir(os.path.join(apps_dir, app))] rebase = '--rebase' if get_config().get('rebase_on_pull') else '' frappe_dir = os.path.join(apps_dir, 'frappe') - if not upgrade: - check_version_upgrade() - for app in apps: app_dir = os.path.join(apps_dir, app) if os.path.exists(os.path.join(app_dir, '.git')): logger.info('pulling {0}'.format(app)) exec_cmd("git pull {rebase} upstream {branch}".format(rebase=rebase, branch=get_current_branch(app_dir)), cwd=app_dir) -def check_version_upgrade(bench='.'): +def is_version_upgrade(bench='.'): apps_dir = os.path.join(bench, 'apps') frappe_dir = os.path.join(apps_dir, 'frappe') @@ -107,7 +104,8 @@ def check_version_upgrade(bench='.'): upstream_version = get_major_version(upstream_version) if upstream_version - local_version > 0: - raise MajorVersionUpgradeException("Major Upgrade", upstream_version, local_version) + return True + return False def get_current_frappe_version(bench='.'): apps_dir = os.path.join(bench, 'apps') diff --git a/bench/cli.py b/bench/cli.py index 4a90ac35..a4ec50ab 100644 --- a/bench/cli.py +++ b/bench/cli.py @@ -13,10 +13,11 @@ from .utils import set_default_site as _set_default_site from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_env_cmd, get_frappe, setup_logging, get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements, backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root, set_mariadb_host, drop_privileges, - fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key, get_cmd_output) + fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key, get_cmd_output, post_upgrade, + pre_upgrade) from .app import get_app as _get_app from .app import new_app as _new_app -from .app import pull_all_apps, get_apps, MajorVersionUpgradeException, get_current_frappe_version +from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade from .config import generate_nginx_config, generate_supervisor_config, generate_redis_config from .production_setup import setup_production as _setup_production from .migrate_to_v5 import migrate_to_v5 @@ -213,13 +214,21 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar 'restart-supervisor': restart_supervisor, 'upgrade': upgrade }) + + + if is_version_upgrade() and not upgrade: + print "This update will cause a major version change in Frappe/ERPNext." + print "This would take significant time to migrate and might break custom apps. Please run `bench update --upgrade` to confirm." + sys.exit(1) + else: + upgrade = False + if pull: - try: - pull_all_apps(upgrade=upgrade) - except MajorVersionUpgradeException, e: - print "This update will cause a major version change in Frappe/ERPNext from v{0} to v{1}.".format(e.local_version, e.upstream_version) - print "This would take significant time to migrate and might break custom apps. Please run `bench update --upgrade` to confirm." - sys.exit(1) + pull_all_apps() + + if upgrade: + pre_upgrade() + if requirements: update_requirements() if patch: @@ -230,6 +239,8 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar build_assets() if restart_supervisor or conf.get('restart_supervisor_on_update'): restart_supervisor_processes() + if upgrade: + post_upgrade() print "_"*80 print "https://frappe.io/buy - Donate to help make better free and open source tools" diff --git a/bench/utils.py b/bench/utils.py index aa5c3189..ef6b69cf 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -417,4 +417,27 @@ def run_frappe_cmd(*args, **kwargs): sites_dir = os.path.join(bench, 'sites') subprocess.check_call((f, '-m', 'frappe.utils.bench_helper', 'frappe') + args, cwd=sites_dir) + +def pre_upgrade(bench='.') + from .migrate_to_v5 import validate_v4, remove_shopping_cart + validate_v4(bench=bench) + for repo in repos: + checkout_v5(repo, bench=bench) + remove_shopping_cart(bench=bench) + +def post_upgrade(bench='.'): + from .app import get_current_frappe_version + from .config import generate_nginx_config, generate_supervisor_config, generate_redis_config + if get_current_frappe_version() == 5: + print "Your bench was upgraded to version 5" + if conf.get('restart_supervisor_on_update'): + generate_redis_config(bench=bench) + generate_supervisor_config(bench=bench) + generate_nginx_config(bench=bench) + print "As you have setup your bench for production, you will have to reload configuration for nginx and supervisor" + print "To complete the migration, please run the following commands" + print + print "sudo service nginx restart" + print "sudo supervisorctl reload" + FRAPPE_VERSION = get_current_frappe_version()