2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 00:06:36 +00:00

Merge pull request #921 from Thunderbottom/pull_specific_apps

feat(bench update): allow pull-only update on specified apps
This commit is contained in:
sahil28297 2020-04-19 13:30:59 +05:30 committed by GitHub
commit 771272f3c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 15 deletions

View File

@ -1,6 +1,6 @@
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
__version__ = "4.1.0" __version__ = "5.0.0"
env = Environment(loader=PackageLoader('bench.config')) env = Environment(loader=PackageLoader('bench.config'))

View File

@ -218,13 +218,14 @@ def remove_app(app, bench_path='.'):
if get_config(bench_path).get('restart_systemd_on_update'): if get_config(bench_path).get('restart_systemd_on_update'):
restart_systemd_processes(bench_path=bench_path) restart_systemd_processes(bench_path=bench_path)
def pull_all_apps(bench_path='.', reset=False): def pull_apps(apps=None, bench_path='.', reset=False):
'''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 ''
apps = apps or get_apps(bench_path=bench_path)
# 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 apps:
excluded_apps = get_excluded_apps() excluded_apps = get_excluded_apps()
if app in excluded_apps: if app in excluded_apps:
print("Skipping reset for app {}".format(app)) print("Skipping reset for app {}".format(app))
@ -248,7 +249,7 @@ Here are your choices:
sys.exit(1) sys.exit(1)
excluded_apps = get_excluded_apps() excluded_apps = get_excluded_apps()
for app in get_apps(bench_path=bench_path): for app in apps:
if app in excluded_apps: if app in excluded_apps:
print("Skipping pull for app {}".format(app)) print("Skipping pull for app {}".format(app))
continue continue

View File

@ -1,17 +1,14 @@
# imports - standard imports
import os
# imports - third party imports # imports - third party imports
import click import click
from six.moves import reload_module
# imports - module imports # imports - module imports
from bench.app import pull_all_apps from bench.app import pull_apps
from bench.utils import post_upgrade, patch_sites, build_assets from bench.utils import post_upgrade, patch_sites, build_assets
@click.command('update', help="Updates bench tool and if executed in a bench directory, without any flags will backup, pull, setup requirements, build, run patches and restart bench. Using specific flags will only do certain tasks instead of all") @click.command('update', help="Updates bench tool and if executed in a bench directory, without any flags will backup, pull, setup requirements, build, run patches and restart bench. Using specific flags will only do certain tasks instead of all")
@click.option('--pull', is_flag=True, help="Pull updates for all the apps in bench") @click.option('--pull', is_flag=True, help="Pull updates for all the apps in bench")
@click.option('--apps', type=str)
@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 assets for the bench") @click.option('--build', is_flag=True, help="Build JS and CSS assets for the bench")
@click.option('--requirements', is_flag=True, help="Update requirements. If run alone, equivalent to `bench setup requirements`") @click.option('--requirements', is_flag=True, help="Update requirements. If run alone, equivalent to `bench setup requirements`")
@ -20,15 +17,15 @@ from bench.utils import post_upgrade, patch_sites, build_assets
@click.option('--no-backup', is_flag=True, help="If this flag is set, sites won't be backed up prior to updates. Note: This is not recommended in production.") @click.option('--no-backup', is_flag=True, help="If this flag is set, sites won't be backed up prior to updates. Note: This is not recommended in production.")
@click.option('--force', is_flag=True, help="Forces major version upgrades") @click.option('--force', is_flag=True, help="Forces major version upgrades")
@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(pull, patch, build, requirements, restart_supervisor, restart_systemd, no_backup, force, reset): def update(pull, apps, patch, build, requirements, restart_supervisor, restart_systemd, no_backup, force, reset):
from bench.utils import update from bench.utils import update
update(pull=pull, patch=patch, build=build, requirements=requirements, restart_supervisor=restart_supervisor, restart_systemd=restart_systemd, backup=not no_backup, force=force, reset=reset) update(pull=pull, apps=apps, patch=patch, build=build, requirements=requirements, restart_supervisor=restart_supervisor, restart_systemd=restart_systemd, backup=not no_backup, force=force, reset=reset)
@click.command('retry-upgrade', help="Retry a failed upgrade") @click.command('retry-upgrade', help="Retry a failed upgrade")
@click.option('--version', default=5) @click.option('--version', default=5)
def retry_upgrade(version): def retry_upgrade(version):
pull_all_apps() pull_apps()
patch_sites() patch_sites()
build_assets() build_assets()
post_upgrade(version-1, version) post_upgrade(version-1, version)

View File

@ -177,17 +177,20 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
copy_patches_txt(path) copy_patches_txt(path)
def update(pull=False, patch=False, build=False, requirements=False, backup=True, force=False, reset=False, def update(pull=False, apps=apps, patch=False, build=False, requirements=False, backup=True, force=False, reset=False,
restart_supervisor=False, restart_systemd=False): restart_supervisor=False, restart_systemd=False):
"""command: bench update""" """command: bench update"""
from bench import patches from bench import patches
from bench.app import is_version_upgrade, pull_all_apps, validate_branch from bench.app import is_version_upgrade, pull_apps, validate_branch
from bench.config.common_site_config import get_config, update_config from bench.config.common_site_config import get_config, update_config
bench_path = os.path.abspath(".") bench_path = os.path.abspath(".")
patches.run(bench_path=bench_path) patches.run(bench_path=bench_path)
conf = get_config(bench_path) conf = get_config(bench_path)
if apps and not pull:
apps = []
clear_command_cache(bench_path='.') clear_command_cache(bench_path='.')
if conf.get('release_bench'): if conf.get('release_bench'):
@ -217,8 +220,11 @@ def update(pull=False, patch=False, build=False, requirements=False, backup=True
print('Backing up sites...') print('Backing up sites...')
backup_all_sites(bench_path=bench_path) backup_all_sites(bench_path=bench_path)
if apps:
apps = [app.strip() for app in re.split(",| ", apps) if app]
if pull: if pull:
pull_all_apps(bench_path=bench_path, reset=reset) pull_apps(apps=apps, bench_path=bench_path, reset=reset)
if requirements: if requirements:
update_requirements(bench_path=bench_path) update_requirements(bench_path=bench_path)