mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
commit
de13b25f2e
13
bench/app.py
13
bench/app.py
@ -18,8 +18,17 @@ def add_to_appstxt(app, bench='.'):
|
||||
apps = get_apps(bench=bench)
|
||||
if app not in apps:
|
||||
apps.append(app)
|
||||
with open(os.path.join(bench, 'sites', 'apps.txt'), 'w') as f:
|
||||
return f.write('\n'.join(apps))
|
||||
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:
|
||||
return f.write('\n'.join(apps))
|
||||
|
||||
def get_app(app, git_url, branch=None, bench='.'):
|
||||
logger.info('getting app {}'.format(app))
|
||||
|
10
bench/cli.py
10
bench/cli.py
@ -18,6 +18,7 @@ from .app import new_app as _new_app
|
||||
from .app import pull_all_apps
|
||||
from .config import generate_nginx_config, generate_supervisor_config
|
||||
from .production_setup import setup_production as _setup_production
|
||||
from .migrate_to_v5 import migrate_to_v5
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
@ -176,7 +177,6 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
|
||||
|
||||
def restart_update(kwargs):
|
||||
args = ['--'+k for k, v in kwargs.items() if v]
|
||||
print 'restarting '
|
||||
os.execv(sys.argv[0], sys.argv[:2] + args)
|
||||
|
||||
@click.command('restart')
|
||||
@ -198,6 +198,13 @@ def migrate_3to4(path):
|
||||
migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'),
|
||||
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.argument('site')
|
||||
@click.argument('port', type=int)
|
||||
@ -444,3 +451,4 @@ bench.add_command(_prime_wheel_cache)
|
||||
bench.add_command(_release)
|
||||
bench.add_command(patch)
|
||||
bench.add_command(set_url_root)
|
||||
bench.add_command(_migrate_to_v5)
|
||||
|
45
bench/migrate_to_v5.py
Normal file
45
bench/migrate_to_v5.py
Normal 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)
|
||||
|
Loading…
Reference in New Issue
Block a user