2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

Merge pull request #78 from frappe/switch-to-5

Switch to 5 fix #75
This commit is contained in:
Pratik Vyas 2014-11-21 18:32:38 +05:30
commit de13b25f2e
3 changed files with 65 additions and 3 deletions

View File

@ -18,6 +18,15 @@ def add_to_appstxt(app, bench='.'):
apps = get_apps(bench=bench) apps = get_apps(bench=bench)
if app not in apps: if app not in apps:
apps.append(app) apps.append(app)
return write_appstxt(apps, bench=bench)
def remove_from_appstxt(app, bench='.'):
apps = get_apps(bench=bench)
if app in apps:
apps.remove(app)
return write_appstxt(apps, bench=bench)
def write_appstxt(apps, bench='.'):
with open(os.path.join(bench, 'sites', 'apps.txt'), 'w') as f: with open(os.path.join(bench, 'sites', 'apps.txt'), 'w') as f:
return f.write('\n'.join(apps)) return f.write('\n'.join(apps))

View File

@ -18,6 +18,7 @@ from .app import new_app as _new_app
from .app import pull_all_apps from .app import pull_all_apps
from .config import generate_nginx_config, generate_supervisor_config from .config import generate_nginx_config, generate_supervisor_config
from .production_setup import setup_production as _setup_production from .production_setup import setup_production as _setup_production
from .migrate_to_v5 import migrate_to_v5
import os import os
import sys import sys
import logging import logging
@ -176,7 +177,6 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
def restart_update(kwargs): def restart_update(kwargs):
args = ['--'+k for k, v in kwargs.items() if v] args = ['--'+k for k, v in kwargs.items() if v]
print 'restarting '
os.execv(sys.argv[0], sys.argv[:2] + args) os.execv(sys.argv[0], sys.argv[:2] + args)
@click.command('restart') @click.command('restart')
@ -198,6 +198,13 @@ def migrate_3to4(path):
migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'), migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'),
site=path)) site=path))
@click.command('migrate-to-v5')
def _migrate_to_v5(bench='.'):
"Migrate to Version 5"
click.echo("This will migrate all sites in the bench to version 5.")
if click.confirm("This is irreversible. Do you want to continue?", abort=True):
migrate_to_v5(bench=bench)
@click.command('set-nginx-port') @click.command('set-nginx-port')
@click.argument('site') @click.argument('site')
@click.argument('port', type=int) @click.argument('port', type=int)
@ -444,3 +451,4 @@ bench.add_command(_prime_wheel_cache)
bench.add_command(_release) bench.add_command(_release)
bench.add_command(patch) bench.add_command(patch)
bench.add_command(set_url_root) bench.add_command(set_url_root)
bench.add_command(_migrate_to_v5)

45
bench/migrate_to_v5.py Normal file
View File

@ -0,0 +1,45 @@
from .utils import exec_cmd, get_frappe
from .release import get_current_version
from .app import remove_from_appstxt
import os
import shutil
import sys
repos = ('frappe', 'erpnext')
def migrate_to_v5(bench='.'):
from .cli import restart_update
validate_v4(bench=bench)
for repo in repos:
checkout_v5(repo, bench=bench)
remove_shopping_cart(bench=bench)
exec_cmd("{bench} update".format(bench=sys.argv[0]))
def remove_shopping_cart(bench='.'):
exec_cmd("{frappe} all --remove_from_installed_apps shopping_cart".format(
frappe=get_frappe(bench=bench)),
cwd=os.path.join(bench, 'sites'))
remove_from_appstxt('shopping_cart', bench=bench)
exec_cmd("{pip} --no-input uninstall -y shopping_cart".format(pip=os.path.join(bench, 'env', 'bin', 'pip')))
archived_apps_dir = os.path.join(bench, 'archived_apps')
shopping_cart_dir = os.path.join(bench, 'apps', 'shopping_cart')
if not os.path.exists(archived_apps_dir):
os.mkdir(archived_apps_dir)
shutil.move(shopping_cart_dir, archived_apps_dir)
def validate_v4(bench='.'):
for repo in repos:
path = os.path.join(bench, 'apps', repo)
if os.path.exists(path):
current_version = get_current_version(path)
if not current_version.startswith('4'):
raise Exception("{} is not on v4.x.x".format(repo))
def checkout_v5(repo, bench='.'):
cwd = os.path.join(bench, 'apps', repo)
if os.path.exists(cwd):
exec_cmd("git fetch upstream", cwd=cwd)
exec_cmd("git checkout v5.0", cwd=cwd)
exec_cmd("git clean -df", cwd=cwd)