mirror of
https://github.com/frappe/bench.git
synced 2024-11-13 16:56:33 +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:
parent
2799a12b2c
commit
872460bb2f
33
bench/app.py
33
bench/app.py
@ -63,6 +63,23 @@ 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_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):
|
||||
# from bench.utils import check_url
|
||||
try:
|
||||
@ -162,16 +179,16 @@ def remove_app(app, 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'''
|
||||
rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else ''
|
||||
|
||||
print("Pull all apps {}".format(exclude))
|
||||
# chech for local changes
|
||||
if not reset:
|
||||
for app in get_apps(bench_path=bench_path):
|
||||
if app in exclude:
|
||||
print("Here")
|
||||
print("Skipping pull for app {}".format(app))
|
||||
excluded_apps = get_excluded_apps()
|
||||
if app in excluded_apps and exclude:
|
||||
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')):
|
||||
@ -192,6 +209,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 and exclude:
|
||||
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)
|
||||
@ -219,7 +240,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)
|
||||
|
||||
|
@ -181,4 +181,7 @@ def migrate_env(python, no_backup = False):
|
||||
log.debug('Migration Error')
|
||||
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)
|
||||
|
21
bench/commands/exclude_update.py
Normal file
21
bench/commands/exclude_update.py
Normal 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
|
@ -1,31 +1,30 @@
|
||||
import click
|
||||
import sys, os
|
||||
import ast
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.app import pull_all_apps, is_version_upgrade
|
||||
from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update,
|
||||
update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, restart_supervisor_processes)
|
||||
from bench import patches
|
||||
|
||||
#TODO: Not DRY
|
||||
# TODO: Not DRY
|
||||
|
||||
|
||||
@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('--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(exclude=[], pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, force=False, reset=False):
|
||||
"Update bench"
|
||||
print("Exclude {}".format(exclude))
|
||||
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"""
|
||||
if not (pull or patch or build or bench or requirements):
|
||||
pull, patch, build, bench, requirements = True, True, True, True, True
|
||||
exclude = ast.literal_eval(exclude)
|
||||
if auto:
|
||||
sys.exit(1)
|
||||
|
||||
@ -35,13 +34,14 @@ def update(exclude=[], pull=False, patch=False, build=False, bench=False, auto=F
|
||||
if bench and conf.get('update_bench_on_update'):
|
||||
update_bench()
|
||||
restart_update({
|
||||
'exclude': exclude,
|
||||
'pull': pull,
|
||||
'patch': patch,
|
||||
'build': build,
|
||||
'requirements': requirements,
|
||||
'no-backup': no_backup,
|
||||
'restart-supervisor': restart_supervisor,
|
||||
'reset':reset
|
||||
'reset': reset
|
||||
})
|
||||
|
||||
if conf.get('release_bench'):
|
||||
@ -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.")
|
||||
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):
|
||||
conf = get_config(bench_path=bench_path)
|
||||
version_upgrade = is_version_upgrade(bench_path=bench_path)
|
||||
|
@ -278,7 +278,7 @@ def update_bench():
|
||||
|
||||
# bench-repo folder
|
||||
cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
print(cwd)
|
||||
exec_cmd("git pull", cwd=cwd)
|
||||
|
||||
def setup_sudoers(user):
|
||||
|
Loading…
Reference in New Issue
Block a user