mirror of
https://github.com/frappe/bench.git
synced 2025-02-09 22:28:26 +00:00
Merge pull request #899 from gavindsouza/bench-cleanup
feat: rollback on bench init
This commit is contained in:
commit
f60466caaf
@ -118,7 +118,7 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal
|
||||
shallow_clone = '--depth 1' if check_git_for_shallow_clone() else ''
|
||||
branch = '--branch {branch}'.format(branch=branch) if branch else ''
|
||||
|
||||
exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format(
|
||||
exec_cmd("git clone -q {git_url} {branch} {shallow_clone} --origin upstream".format(
|
||||
git_url=git_url,
|
||||
shallow_clone=shallow_clone,
|
||||
branch=branch),
|
||||
|
@ -15,21 +15,42 @@ import click
|
||||
@click.option('--skip-redis-config-generation', is_flag=True, help="Skip redis config generation if already specifying the common-site-config file")
|
||||
@click.option('--skip-assets',is_flag=True, default=False, help="Do not build assets")
|
||||
@click.option('--verbose',is_flag=True, help="Verbose output during install")
|
||||
def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups,
|
||||
no_auto_update, clone_from, verbose, skip_redis_config_generation, clone_without_update,
|
||||
ignore_exist = False, skip_assets=False,
|
||||
python = 'python3'):
|
||||
def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, no_auto_update, clone_from, verbose, skip_redis_config_generation, clone_without_update, ignore_exist=False, skip_assets=False, python='python3'):
|
||||
'''
|
||||
Create a New Bench Instance.
|
||||
'''
|
||||
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_redis_config_generation=skip_redis_config_generation,
|
||||
from bench.utils import init, log
|
||||
|
||||
try:
|
||||
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_redis_config_generation=skip_redis_config_generation,
|
||||
clone_without_update=clone_without_update,
|
||||
ignore_exist = ignore_exist, skip_assets=skip_assets,
|
||||
python = python)
|
||||
click.echo('Bench {} initialized'.format(path))
|
||||
ignore_exist=ignore_exist,
|
||||
skip_assets=skip_assets,
|
||||
python=python,
|
||||
)
|
||||
log('Bench {} initialized'.format(path), level=1)
|
||||
except SystemExit:
|
||||
pass
|
||||
except:
|
||||
import os, shutil, time, six
|
||||
# add a sleep here so that the traceback of other processes doesnt overlap with the prompts
|
||||
time.sleep(1)
|
||||
log("There was a problem while creating {}".format(path), level=2)
|
||||
if six.moves.input("Do you want to rollback these changes? [Y/n]: ").lower() == "y":
|
||||
print('Rolling back Bench "{}"'.format(path))
|
||||
if os.path.exists(path):
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
@click.command('get-app')
|
||||
@click.argument('name', nargs=-1) # Dummy argument for backward compatibility
|
||||
|
@ -1,4 +1,5 @@
|
||||
from bench.utils import exec_cmd
|
||||
from six import PY3
|
||||
import click, sys, json
|
||||
import os
|
||||
|
||||
@ -57,7 +58,7 @@ def setup_production(user, yes=False):
|
||||
# Install prereqs for production
|
||||
from distutils.spawn import find_executable
|
||||
if not find_executable('ansible'):
|
||||
exec_cmd("sudo pip install ansible")
|
||||
exec_cmd("sudo {0} install ansible".format("pip3" if PY3 else "pip2"))
|
||||
if not find_executable('fail2ban-client'):
|
||||
exec_cmd("bench setup role fail2ban")
|
||||
if not find_executable('nginx'):
|
||||
|
@ -1,4 +1,4 @@
|
||||
import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob
|
||||
import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob, errno
|
||||
from distutils.spawn import find_executable
|
||||
import bench
|
||||
import semantic_version
|
||||
@ -17,6 +17,14 @@ logger = logging.getLogger(__name__)
|
||||
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
|
||||
|
||||
|
||||
class color:
|
||||
nc = '\033[0m'
|
||||
blue = '\033[94m'
|
||||
green = '\033[92m'
|
||||
yellow = '\033[93m'
|
||||
red = '\033[91m'
|
||||
|
||||
|
||||
def is_bench_directory(directory=os.path.curdir):
|
||||
is_bench = True
|
||||
|
||||
@ -29,12 +37,12 @@ def is_bench_directory(directory=os.path.curdir):
|
||||
|
||||
def log(message, level=0):
|
||||
levels = {
|
||||
0: '\033[94m', # normal
|
||||
1: '\033[92m', # success
|
||||
2: '\033[91mERROR: ', # fail
|
||||
3: '\033[93mWARN: ' # warn/suggest
|
||||
0: color.blue + 'LOG', # normal
|
||||
1: color.green + 'SUCCESS', # success
|
||||
2: color.red + 'ERROR', # fail
|
||||
3: color.yellow + 'WARN' # warn/suggest
|
||||
}
|
||||
start = levels.get(level) or ''
|
||||
start = (levels.get(level) + ': ') if level in levels else ''
|
||||
end = '\033[0m'
|
||||
|
||||
print(start + message + end)
|
||||
@ -57,23 +65,18 @@ def get_frappe(bench_path='.'):
|
||||
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_redis_config_generation=False,
|
||||
clone_without_update=False,
|
||||
ignore_exist = False, skip_assets=False,
|
||||
python = 'python3'): # Let's change when we're ready. - <achilles@frappe.io>
|
||||
from .app import get_app, install_apps_from_path
|
||||
from .config.common_site_config import make_config
|
||||
from .config import redis
|
||||
from .config.procfile import setup_procfile
|
||||
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_redis_config_generation=False, clone_without_update=False, ignore_exist = False, skip_assets=False, python='python3'):
|
||||
from bench.app import get_app, install_apps_from_path
|
||||
from bench.config import redis
|
||||
from bench.config.common_site_config import make_config
|
||||
from bench.config.procfile import setup_procfile
|
||||
from bench.patches import set_all_patches_executed
|
||||
|
||||
import os.path as osp
|
||||
|
||||
if osp.exists(path):
|
||||
if not ignore_exist:
|
||||
raise ValueError('Bench Instance {path} already exists.'.format(path = path))
|
||||
if os.path.exists(path) and not ignore_exist:
|
||||
log('Path {path} already exists!'.format(path=path))
|
||||
sys.exit(0)
|
||||
else:
|
||||
os.makedirs(path)
|
||||
|
||||
@ -81,12 +84,12 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
|
||||
try:
|
||||
os.makedirs(os.path.join(path, dirname))
|
||||
except OSError as e:
|
||||
if e.errno == os.errno.EEXIST:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
|
||||
setup_logging()
|
||||
|
||||
setup_env(bench_path=path, python = python)
|
||||
setup_env(bench_path=path, python=python)
|
||||
|
||||
make_config(path)
|
||||
|
||||
@ -200,9 +203,7 @@ def setup_env(bench_path='.', python = 'python3'):
|
||||
pip = os.path.join('env', 'bin', 'pip')
|
||||
|
||||
exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path)
|
||||
exec_cmd('{} -q install --upgrade pip'.format(pip), cwd=bench_path)
|
||||
exec_cmd('{} -q install wheel'.format(pip), cwd=bench_path)
|
||||
exec_cmd('{} -q install six'.format(pip), cwd=bench_path)
|
||||
exec_cmd('{} -q install -U pip wheel six'.format(pip), cwd=bench_path)
|
||||
exec_cmd('{} -q install -e git+https://github.com/frappe/python-pdfkit.git#egg=pdfkit'.format(pip), cwd=bench_path)
|
||||
|
||||
def setup_socketio(bench_path='.'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user