From 028515439010416db6cf316ab8511211b50b9ad4 Mon Sep 17 00:00:00 2001 From: gshmu Date: Mon, 28 Aug 2017 14:02:31 +0800 Subject: [PATCH 1/2] update file exists --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 896fc0c0..6f5bc11c 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -46,7 +46,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, try: os.makedirs(os.path.join(path, dirname)) except OSError, e: - if e.errno != os.errno.EEXIST: + if e.errno == os.errno.EEXIST: pass setup_logging() From 7e2a36714a1a6e8500384ebb4544b3abe1190c25 Mon Sep 17 00:00:00 2001 From: gshmu Date: Mon, 28 Aug 2017 21:18:52 +0800 Subject: [PATCH 2/2] refine clone from --- bench/commands/make.py | 6 ++++-- bench/utils.py | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bench/commands/make.py b/bench/commands/make.py index 18a06c92..87ece24b 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -6,6 +6,7 @@ import click @click.option('--frappe-path', default=None, help="path to frappe repo") @click.option('--frappe-branch', default=None, help="path to frappe repo") @click.option('--clone-from', default=None, help="copy repos from path") +@click.option('--clone-without-update', is_flag=True, help="copy repos from path without update") @click.option('--no-procfile', is_flag=True, help="Pull changes in all the apps in bench") @click.option('--no-backups',is_flag=True, help="Run migrations for all sites in the bench") @click.option('--no-auto-update',is_flag=True, help="Build JS and CSS artifacts for the bench") @@ -13,12 +14,13 @@ import click @click.option('--skip-bench-mkdir', is_flag=True, help="Skip mkdir frappe-bench") @click.option('--skip-redis-config-generation', is_flag=True, help="Skip redis config generation if already specifying the common-site-config file") def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, - no_auto_update, clone_from, verbose, skip_bench_mkdir, skip_redis_config_generation): + no_auto_update, clone_from, verbose, skip_bench_mkdir, skip_redis_config_generation, clone_without_update): "Create a new bench" from bench.utils import init init(path, apps_path=apps_path, no_procfile=no_procfile, no_backups=no_backups, no_auto_update=no_auto_update, frappe_path=frappe_path, frappe_branch=frappe_branch, - verbose=verbose, clone_from=clone_from, skip_bench_mkdir=skip_bench_mkdir, skip_redis_config_generation=skip_redis_config_generation) + verbose=verbose, clone_from=clone_from, skip_bench_mkdir=skip_bench_mkdir, + skip_redis_config_generation=skip_redis_config_generation, clone_without_update=clone_without_update) click.echo('Bench {} initialized'.format(path)) diff --git a/bench/utils.py b/bench/utils.py index 6f5bc11c..d5485ff5 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -26,8 +26,9 @@ def get_env_cmd(cmd, bench_path='.'): return os.path.abspath(os.path.join(bench_path, 'env', 'bin', cmd)) def init(path, apps_path=None, no_procfile=False, no_backups=False, - no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, - verbose=False, clone_from=None, skip_bench_mkdir=False, skip_redis_config_generation=False): + no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, + verbose=False, clone_from=None, skip_bench_mkdir=False, skip_redis_config_generation=False, + clone_without_update=False): from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis @@ -56,7 +57,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, make_config(path) if clone_from: - clone_apps_from(bench_path=path, clone_from=clone_from) + clone_apps_from(bench_path=path, clone_from=clone_from, update_app=not clone_without_update) else: if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' @@ -84,33 +85,34 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, if not no_auto_update: setup_auto_update(bench_path=path) -def clone_apps_from(bench_path, clone_from): +def clone_apps_from(bench_path, clone_from, update_app=True): from .app import install_app print('Copying apps from {0}...'.format(clone_from)) subprocess.check_output(['cp', '-R', os.path.join(clone_from, 'apps'), bench_path]) - print('Copying node_modules from {0}...'.format(clone_from)) - subprocess.check_output(['cp', '-R', os.path.join(clone_from, 'node_modules'), bench_path]) + if os.path.exists(os.path.join(clone_from, 'node_modules')): + print('Copying node_modules from {0}...'.format(clone_from)) + subprocess.check_output(['cp', '-R', os.path.join(clone_from, 'node_modules'), bench_path]) def setup_app(app): # run git reset --hard in each branch, pull latest updates and install_app app_path = os.path.join(bench_path, 'apps', app) - if os.path.exists(os.path.join(app_path, '.git')): - print('Cleaning up {0}'.format(app)) - # remove .egg-ino - subprocess.check_output(['rm', '-rf', app + '.egg-info'], cwd=app_path) + # remove .egg-ino + subprocess.check_output(['rm', '-rf', app + '.egg-info'], cwd=app_path) + if update_app and os.path.exists(os.path.join(app_path, '.git')): remotes = subprocess.check_output(['git', 'remote'], cwd=app_path).strip().split() if 'upstream' in remotes: remote = 'upstream' else: remote = remotes[0] + print('Cleaning up {0}'.format(app)) branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=app_path).strip() subprocess.check_output(['git', 'reset', '--hard'], cwd=app_path) subprocess.check_output(['git', 'pull', '--rebase', remote, branch], cwd=app_path) - install_app(app, bench_path) + install_app(app, bench_path) with open(os.path.join(clone_from, 'sites', 'apps.txt'), 'r') as f: apps = f.read().splitlines()