mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
Warn if upgrading to next major version
This commit is contained in:
parent
dee9c25b93
commit
d3d873bff9
58
bench/app.py
58
bench/app.py
@ -3,10 +3,20 @@ from .utils import exec_cmd, get_frappe, check_git_for_shallow_clone, get_config
|
||||
|
||||
import logging
|
||||
import requests
|
||||
import semantic_version
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class MajorVersionUpgradeException(Exception):
|
||||
def __init__(self, message, upstream_version, local_version):
|
||||
super(MajorVersionUpgradeException, self).__init__(message)
|
||||
self.upstream_version = upstream_version
|
||||
self.local_version = local_version
|
||||
|
||||
def get_apps(bench='.'):
|
||||
try:
|
||||
with open(os.path.join(bench, 'sites', 'apps.txt')) as f:
|
||||
@ -64,19 +74,65 @@ def install_app(app, bench='.'):
|
||||
find_links=find_links))
|
||||
add_to_appstxt(app, bench=bench)
|
||||
|
||||
def pull_all_apps(bench='.'):
|
||||
def pull_all_apps(bench='.', upgrade=False):
|
||||
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='.'):
|
||||
apps_dir = os.path.join(bench, 'apps')
|
||||
frappe_dir = os.path.join(apps_dir, 'frappe')
|
||||
|
||||
fetch_upstream(frappe_dir)
|
||||
upstream_version = get_upstream_version(frappe_dir)
|
||||
|
||||
if not upstream_version:
|
||||
raise Exception("Current branch not in upstream")
|
||||
|
||||
local_version = get_major_version(get_current_version(frappe_dir))
|
||||
upstream_version = get_major_version(upstream_version)
|
||||
|
||||
if upstream_version - local_version > 0:
|
||||
raise MajorVersionUpgradeException("Major Upgrade", upstream_version, local_version)
|
||||
|
||||
def get_current_branch(repo_dir):
|
||||
return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)
|
||||
|
||||
def fetch_upstream(repo_dir):
|
||||
return exec_cmd("git fetch upstream", cwd=repo_dir)
|
||||
|
||||
def get_current_version(repo_dir):
|
||||
with open(os.path.join(repo_dir, 'setup.py')) as f:
|
||||
return get_version_from_string(f.read())
|
||||
|
||||
def get_upstream_version(repo_dir):
|
||||
try:
|
||||
contents = subprocess.check_output(['git', 'show', 'upstream/{branch}:setup.py'.format(branch=get_current_branch(repo_dir))], cwd=repo_dir, stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError, e:
|
||||
if "Invalid object" in e.output:
|
||||
return None
|
||||
else:
|
||||
raise
|
||||
return get_version_from_string(contents)
|
||||
|
||||
def get_version_from_string(contents):
|
||||
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])(?sm)" % 'version',
|
||||
contents)
|
||||
return match.group(2)
|
||||
|
||||
def get_major_version(version):
|
||||
return semantic_version.Version(version).major
|
||||
|
||||
def install_apps_from_path(path, bench='.'):
|
||||
apps = get_apps_json(path)
|
||||
for app in apps:
|
||||
|
22
bench/cli.py
22
bench/cli.py
@ -16,8 +16,8 @@ from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_frapp
|
||||
fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key)
|
||||
from .app import get_app as _get_app
|
||||
from .app import new_app as _new_app
|
||||
from .app import pull_all_apps
|
||||
from .config import generate_nginx_config, generate_supervisor_config
|
||||
from .app import pull_all_apps, MajorVersionUpgradeException
|
||||
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
|
||||
import os
|
||||
@ -139,8 +139,9 @@ def new_site(site, mariadb_root_password=None, admin_password=None):
|
||||
@click.option('--requirements',flag_value=True, type=bool, help="Update requirements")
|
||||
@click.option('--restart-supervisor',flag_value=True, type=bool, help="restart supervisor processes after update")
|
||||
@click.option('--auto',flag_value=True, type=bool)
|
||||
@click.option('--upgrade',flag_value=True, type=bool)
|
||||
@click.option('--no-backup',flag_value=True, type=bool)
|
||||
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False):
|
||||
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False):
|
||||
"Update bench"
|
||||
|
||||
if not (pull or patch or build or bench or requirements):
|
||||
@ -160,10 +161,16 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
|
||||
'build': build,
|
||||
'requirements': requirements,
|
||||
'no-backup': no_backup,
|
||||
'restart-supervisor': restart_supervisor
|
||||
'restart-supervisor': restart_supervisor,
|
||||
'upgrade': upgrade
|
||||
})
|
||||
if pull:
|
||||
pull_all_apps()
|
||||
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 use --upgrade to confirm."
|
||||
sys.exit(1)
|
||||
if requirements:
|
||||
update_requirements()
|
||||
if patch:
|
||||
@ -299,6 +306,11 @@ def setup_supervisor():
|
||||
"generate config for supervisor"
|
||||
generate_supervisor_config()
|
||||
|
||||
@click.command('redis-cache')
|
||||
def setup_supervisor():
|
||||
"generate config for redis cache"
|
||||
generate_redis_config()
|
||||
|
||||
@click.command('production')
|
||||
@click.argument('user')
|
||||
def setup_production(user):
|
||||
|
Loading…
Reference in New Issue
Block a user