diff --git a/bench/app.py b/bench/app.py index 443156f3..f16da999 100755 --- a/bench/app.py +++ b/bench/app.py @@ -63,6 +63,33 @@ def check_url(url, raise_err = True): return True +def get_excluded_apps(bench_path='.'): + try: + with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt')) as f: + return f.read().strip().split('\n') + except IOError: + return [] + +def add_to_excluded_apps_txt(app, bench_path='.'): + if app == 'frappe': + raise ValueError('Frappe app cannot be excludeed from update') + if app not in os.listdir('apps'): + raise ValueError('The app {} does not exist'.format(app)) + apps = get_excluded_apps(bench_path=bench_path) + if app not in apps: + apps.append(app) + return write_excluded_apps_txt(apps, bench_path=bench_path) + +def write_excluded_apps_txt(apps, bench_path='.'): + with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt'), 'w') as f: + return f.write('\n'.join(apps)) + +def remove_from_excluded_apps_txt(app, bench_path='.'): + apps = get_excluded_apps(bench_path=bench_path) + if app in apps: + apps.remove(app) + return write_excluded_apps_txt(apps, bench_path=bench_path) + def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbose=False): # from bench.utils import check_url try: @@ -169,6 +196,10 @@ def pull_all_apps(bench_path='.', reset=False): # chech for local changes if not reset: for app in get_apps(bench_path=bench_path): + excluded_apps = get_excluded_apps() + if app in excluded_apps: + print("Skipping reset for app {}".format(app)) + continue app_dir = get_repo_dir(app, bench_path=bench_path) if os.path.exists(os.path.join(app_dir, '.git')): out = subprocess.check_output(["git", "status"], cwd=app_dir) @@ -188,6 +219,10 @@ Here are your choices: sys.exit(1) for app in get_apps(bench_path=bench_path): + excluded_apps = get_excluded_apps() + if app in excluded_apps: + print("Skipping pull for app {}".format(app)) + continue app_dir = get_repo_dir(app, bench_path=bench_path) if os.path.exists(os.path.join(app_dir, '.git')): remote = get_remote(app) @@ -215,7 +250,7 @@ def is_version_upgrade(app='frappe', bench_path='.', branch=None): local_version = get_major_version(get_current_version(app, bench_path=bench_path)) upstream_version = get_major_version(upstream_version) - + if upstream_version - local_version > 0: return (True, local_version, upstream_version) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index fa4f48ec..b7ac45a3 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -180,4 +180,8 @@ def migrate_env(python, no_backup = False): log.debug('Migration Error') raise -bench_command.add_command(migrate_env) \ No newline at end of file +bench_command.add_command(migrate_env) + +from bench.commands.make import exclude_app_for_update, include_app_for_update +bench_command.add_command(exclude_app_for_update) +bench_command.add_command(include_app_for_update) diff --git a/bench/commands/make.py b/bench/commands/make.py index f838e293..10c3b67a 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -52,3 +52,19 @@ def remove_app(app_name): "completely remove app from bench" from bench.app import remove_app remove_app(app_name) + + +@click.command('exclude-app') +@click.argument('app_name') +def exclude_app_for_update(app_name): + "Exclude app from updating" + from bench.app import add_to_excluded_apps_txt + add_to_excluded_apps_txt(app_name) + + +@click.command('include-app') +@click.argument('app_name') +def include_app_for_update(app_name): + "Include app from updating" + from bench.app import remove_from_excluded_apps_txt + remove_from_excluded_apps_txt(app_name) diff --git a/bench/commands/update.py b/bench/commands/update.py index 5de03cbe..bbc865d8 100755 --- a/bench/commands/update.py +++ b/bench/commands/update.py @@ -6,17 +6,17 @@ from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgra update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, restart_supervisor_processes) from bench import patches -#TODO: Not DRY + @click.command('update') @click.option('--pull', is_flag=True, help="Pull changes in all the apps in bench") -@click.option('--patch',is_flag=True, help="Run migrations for all sites in the bench") -@click.option('--build',is_flag=True, help="Build JS and CSS artifacts for the bench") -@click.option('--bench',is_flag=True, help="Update bench") -@click.option('--requirements',is_flag=True, help="Update requirements") -@click.option('--restart-supervisor',is_flag=True, help="restart supervisor processes after update") -@click.option('--auto',is_flag=True) -@click.option('--no-backup',is_flag=True) -@click.option('--force',is_flag=True) +@click.option('--patch', is_flag=True, help="Run migrations for all sites in the bench") +@click.option('--build', is_flag=True, help="Build JS and CSS artifacts for the bench") +@click.option('--bench', is_flag=True, help="Update bench") +@click.option('--requirements', is_flag=True, help="Update requirements") +@click.option('--restart-supervisor', is_flag=True, help="restart supervisor processes after update") +@click.option('--auto', is_flag=True) +@click.option('--no-backup', is_flag=True) +@click.option('--force', is_flag=True) @click.option('--reset', is_flag=True, help="Hard resets git branch's to their new states overriding any changes and overriding rebase on pull") def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, force=False, reset=False): "Update bench" @@ -39,7 +39,7 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar 'requirements': requirements, 'no-backup': no_backup, 'restart-supervisor': restart_supervisor, - 'reset':reset + 'reset': reset }) if conf.get('release_bench'):