mirror of
https://github.com/frappe/bench.git
synced 2025-01-24 07:28:25 +00:00
Merge pull request #549 from achillesrasquinha/548
Create Bench Virtual Environments
This commit is contained in:
commit
025db09451
@ -10,4 +10,4 @@ def set_frappe_version(bench_path='.'):
|
||||
from .app import get_current_frappe_version
|
||||
global FRAPPE_VERSION
|
||||
if not FRAPPE_VERSION:
|
||||
FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path)
|
||||
FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path)
|
@ -95,7 +95,9 @@ def get_frappe_commands(bench_path='.'):
|
||||
if not os.path.exists(sites_path):
|
||||
return []
|
||||
try:
|
||||
return json.loads(get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path))
|
||||
output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)
|
||||
output = output.decode('utf-8')
|
||||
return json.loads(output)
|
||||
except subprocess.CalledProcessError:
|
||||
return []
|
||||
|
||||
|
@ -2,6 +2,8 @@ import click
|
||||
|
||||
@click.command()
|
||||
@click.argument('path')
|
||||
@click.option('--python', type = click.Choice(['python2', 'python3']), default = 'python2', help = 'Path to Python Executable.')
|
||||
@click.option('--ignore-exist', is_flag = True, default = False, help = "Ignore if Bench instance exists.")
|
||||
@click.option('--apps_path', default=None, help="path to json files with apps to install after init")
|
||||
@click.option('--frappe-path', default=None, help="path to frappe repo")
|
||||
@click.option('--frappe-branch', default=None, help="path to frappe repo")
|
||||
@ -9,19 +11,23 @@ import click
|
||||
@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")
|
||||
@click.option('--verbose',is_flag=True, help="Verbose output during install")
|
||||
@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")
|
||||
@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_bench_mkdir, skip_redis_config_generation):
|
||||
"Create a new bench"
|
||||
no_auto_update, clone_from, verbose, skip_redis_config_generation,
|
||||
ignore_exist = False,
|
||||
python = 'python2'): # Let's change we're ready. - <achilles@frappe.io>
|
||||
'''
|
||||
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_bench_mkdir=skip_bench_mkdir, skip_redis_config_generation=skip_redis_config_generation)
|
||||
verbose=verbose, clone_from=clone_from, skip_redis_config_generation=skip_redis_config_generation,
|
||||
ignore_exist = ignore_exist,
|
||||
python = python)
|
||||
click.echo('Bench {} initialized'.format(path))
|
||||
|
||||
|
||||
@click.command('get-app')
|
||||
@click.argument('name', nargs=-1) # Dummy argument for backward compatibility
|
||||
@click.argument('git-url')
|
||||
|
@ -4,8 +4,7 @@ import click, sys, json
|
||||
def setup():
|
||||
"Setup bench"
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@click.command('sudoers')
|
||||
@click.argument('user')
|
||||
def setup_sudoers(user):
|
||||
@ -13,7 +12,6 @@ def setup_sudoers(user):
|
||||
from bench.utils import setup_sudoers
|
||||
setup_sudoers(user)
|
||||
|
||||
|
||||
@click.command('nginx')
|
||||
@click.option('--yes', help='Yes to regeneration of nginx config file', default=False, is_flag=True)
|
||||
def setup_nginx(yes=False):
|
||||
|
@ -56,8 +56,8 @@ def write_redis_config(template_name, context, bench_path):
|
||||
f.write(template.render(**context))
|
||||
|
||||
def get_redis_version():
|
||||
version_string = subprocess.check_output('redis-server --version', shell=True).strip()
|
||||
|
||||
version_string = subprocess.check_output('redis-server --version', shell=True)
|
||||
version_string = version_string.decode('utf-8').strip()
|
||||
# extract version number from string
|
||||
version = re.findall("\d+\.\d+", version_string)
|
||||
if not version:
|
||||
|
@ -27,31 +27,33 @@ def get_env_cmd(cmd, bench_path='.'):
|
||||
|
||||
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):
|
||||
verbose=False, clone_from=None, skip_redis_config_generation=False,
|
||||
ignore_exist = False,
|
||||
python = 'python2'): # 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
|
||||
from bench.patches import set_all_patches_executed
|
||||
|
||||
if(skip_bench_mkdir):
|
||||
pass
|
||||
import os.path as osp
|
||||
|
||||
if osp.exists(path):
|
||||
if not ignore_exist:
|
||||
raise ValueError('Bench Instance {path} already exists.'.format(path = path))
|
||||
else:
|
||||
if os.path.exists(path):
|
||||
print('Directory {} already exists!'.format(path))
|
||||
raise Exception("Site directory already exists")
|
||||
os.makedirs(path)
|
||||
|
||||
for dirname in folders_in_bench:
|
||||
try:
|
||||
os.makedirs(os.path.join(path, dirname))
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != os.errno.EEXIST:
|
||||
pass
|
||||
|
||||
setup_logging()
|
||||
|
||||
setup_env(bench_path=path)
|
||||
setup_env(bench_path=path, python = python)
|
||||
|
||||
make_config(path)
|
||||
|
||||
@ -139,8 +141,21 @@ def exec_cmd(cmd, cwd='.'):
|
||||
if return_code > 0:
|
||||
raise CommandFailedError(cmd)
|
||||
|
||||
def setup_env(bench_path='.'):
|
||||
exec_cmd('virtualenv -q {} -p {}'.format('env', sys.executable), cwd=bench_path)
|
||||
def which(executable, raise_err = False):
|
||||
from distutils.spawn import find_executable
|
||||
exec_ = find_executable(executable)
|
||||
|
||||
if not exec_ and raise_err:
|
||||
raise ValueError('{executable} not found.'.format(
|
||||
executable = executable
|
||||
))
|
||||
|
||||
return exec_
|
||||
|
||||
def setup_env(bench_path='.', python = 'python2'):
|
||||
python = which(python, raise_err = True)
|
||||
|
||||
exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path)
|
||||
exec_cmd('./env/bin/pip -q install --upgrade pip', cwd=bench_path)
|
||||
exec_cmd('./env/bin/pip -q install wheel', cwd=bench_path)
|
||||
# exec_cmd('./env/bin/pip -q install https://github.com/frappe/MySQLdb1/archive/MySQLdb-1.2.5-patched.tar.gz', cwd=bench_path)
|
||||
@ -232,13 +247,14 @@ def setup_backups(bench_path='.'):
|
||||
|
||||
def add_to_crontab(line):
|
||||
current_crontab = read_crontab()
|
||||
line = str.encode(line)
|
||||
if not line in current_crontab:
|
||||
cmd = ["crontab"]
|
||||
if platform.system() == 'FreeBSD':
|
||||
cmd = ["crontab", "-"]
|
||||
s = subprocess.Popen(cmd, stdin=subprocess.PIPE)
|
||||
s.stdin.write(current_crontab)
|
||||
s.stdin.write(line + '\n')
|
||||
s.stdin.write(line + b'\n')
|
||||
s.stdin.close()
|
||||
|
||||
def read_crontab():
|
||||
@ -331,7 +347,9 @@ def check_cmd(cmd, cwd='.'):
|
||||
def get_git_version():
|
||||
'''returns git version from `git --version`
|
||||
extracts version number from string `get version 1.9.1` etc'''
|
||||
version = get_cmd_output("git --version").strip().split()[2]
|
||||
version = get_cmd_output("git --version")
|
||||
version = version.decode('utf-8')
|
||||
version = version.strip().split()[2]
|
||||
version = '.'.join(version.split('.')[0:2])
|
||||
return float(version)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user