2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 09:02:10 +00:00

New command to exclude apps when bench update

command bench exclude-app <app-name>
command bench update --exclude-apps
This commit is contained in:
shridhar 2017-12-12 16:46:31 +05:30 committed by Shridhar
parent 2799a12b2c
commit 872460bb2f
5 changed files with 71 additions and 26 deletions

View File

@ -63,6 +63,23 @@ def check_url(url, raise_err = True):
return 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_appstxt(app, bench_path='.'):
apps = get_excluded_apps(bench_path=bench_path)
if app not in apps:
apps.append(app)
return write_excluded_appstxt(apps, bench_path=bench_path)
def write_excluded_appstxt(apps, bench_path='.'):
with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt'), 'w') as f:
return f.write('\n'.join(apps))
def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbose=False): def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbose=False):
# from bench.utils import check_url # from bench.utils import check_url
try: try:
@ -162,16 +179,16 @@ def remove_app(app, bench_path='.'):
restart_supervisor_processes(bench_path=bench_path) restart_supervisor_processes(bench_path=bench_path)
def pull_all_apps(bench_path='.', reset=False, exclude=[]): def pull_all_apps(bench_path='.', reset=False, exclude=True):
'''Check all apps if there no local changes, pull''' '''Check all apps if there no local changes, pull'''
rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else '' rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else ''
print("Pull all apps {}".format(exclude))
# chech for local changes # chech for local changes
if not reset: if not reset:
for app in get_apps(bench_path=bench_path): for app in get_apps(bench_path=bench_path):
if app in exclude: excluded_apps = get_excluded_apps()
print("Here") if app in excluded_apps and exclude:
print("Skipping pull for app {}".format(app)) print("Skipping reset for app {}".format(app))
continue continue
app_dir = get_repo_dir(app, bench_path=bench_path) app_dir = get_repo_dir(app, bench_path=bench_path)
if os.path.exists(os.path.join(app_dir, '.git')): if os.path.exists(os.path.join(app_dir, '.git')):
@ -192,6 +209,10 @@ Here are your choices:
sys.exit(1) sys.exit(1)
for app in get_apps(bench_path=bench_path): for app in get_apps(bench_path=bench_path):
excluded_apps = get_excluded_apps()
if app in excluded_apps and exclude:
print("Skipping pull for app {}".format(app))
continue
app_dir = get_repo_dir(app, bench_path=bench_path) app_dir = get_repo_dir(app, bench_path=bench_path)
if os.path.exists(os.path.join(app_dir, '.git')): if os.path.exists(os.path.join(app_dir, '.git')):
remote = get_remote(app) remote = get_remote(app)

View File

@ -182,3 +182,6 @@ def migrate_env(python, no_backup = False):
raise raise
bench_command.add_command(migrate_env) bench_command.add_command(migrate_env)
from bench.commands.exclude_update import exclude_update
bench_command.add_command(exclude_update)

View File

@ -0,0 +1,21 @@
#!/bin/env python
"""
Bench command to exclude app while update
bench exclude-app <app-name>
"""
import click
from bench.app import add_to_excluded_appstxt
# TODO: Not DRY
@click.command('exclude-app')
@click.argument('app_name')
def exclude_update(app_name):
"""Update bench"""
add_to_excluded_appstxt(app_name)
return

View File

@ -1,6 +1,5 @@
import click import click
import sys, os import sys, os
import ast
from bench.config.common_site_config import get_config from bench.config.common_site_config import get_config
from bench.app import pull_all_apps, is_version_upgrade from bench.app import pull_all_apps, is_version_upgrade
from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update, from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update,
@ -8,8 +7,10 @@ from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgra
from bench import patches from bench import patches
# TODO: Not DRY # TODO: Not DRY
@click.command('update') @click.command('update')
@click.option('--exclude', default=[], required=False, help="Exclude pull for the apps") @click.option('--exclude-apps', is_flag=True, help="Exclude pull for the apps")
@click.option('--pull', is_flag=True, help="Pull changes in all the apps in bench") @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('--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('--build', is_flag=True, help="Build JS and CSS artifacts for the bench")
@ -20,12 +21,10 @@ from bench import patches
@click.option('--no-backup', is_flag=True) @click.option('--no-backup', is_flag=True)
@click.option('--force', 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") @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(exclude=[], pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, force=False, reset=False): def update(exclude=False, pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, force=False, reset=False):
"Update bench" """Update bench"""
print("Exclude {}".format(exclude))
if not (pull or patch or build or bench or requirements): if not (pull or patch or build or bench or requirements):
pull, patch, build, bench, requirements = True, True, True, True, True pull, patch, build, bench, requirements = True, True, True, True, True
exclude = ast.literal_eval(exclude)
if auto: if auto:
sys.exit(1) sys.exit(1)
@ -35,6 +34,7 @@ def update(exclude=[], pull=False, patch=False, build=False, bench=False, auto=F
if bench and conf.get('update_bench_on_update'): if bench and conf.get('update_bench_on_update'):
update_bench() update_bench()
restart_update({ restart_update({
'exclude': exclude,
'pull': pull, 'pull': pull,
'patch': patch, 'patch': patch,
'build': build, 'build': build,
@ -57,9 +57,9 @@ def update(exclude=[], pull=False, patch=False, build=False, bench=False, auto=F
print("This would take significant time to migrate and might break custom apps.") print("This would take significant time to migrate and might break custom apps.")
click.confirm('Do you want to continue?', abort=True) click.confirm('Do you want to continue?', abort=True)
_update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, force=force, reset=reset) _update(exclude, pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, force=force, reset=reset)
def _update(exclude=[], pull=False, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False, def _update(exclude=False, pull=False, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False,
requirements=False, no_backup=False, bench_path='.', force=False, reset=False): requirements=False, no_backup=False, bench_path='.', force=False, reset=False):
conf = get_config(bench_path=bench_path) conf = get_config(bench_path=bench_path)
version_upgrade = is_version_upgrade(bench_path=bench_path) version_upgrade = is_version_upgrade(bench_path=bench_path)

View File

@ -278,7 +278,7 @@ def update_bench():
# bench-repo folder # bench-repo folder
cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(cwd)
exec_cmd("git pull", cwd=cwd) exec_cmd("git pull", cwd=cwd)
def setup_sudoers(user): def setup_sudoers(user):