Skip to content

Commit

Permalink
Revert "fix: force use PYPI packaged bench"
Browse files Browse the repository at this point in the history
This reverts commit 74bb180.
  • Loading branch information
gavindsouza committed Mar 16, 2020
1 parent 5e7ad22 commit cdd7d34
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
10 changes: 8 additions & 2 deletions bench/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from bench.utils import install_checker
from jinja2 import Environment, PackageLoader

__version__ = "4.1.0"

env = Environment(loader=PackageLoader('bench.config'))
install_checker()

FRAPPE_VERSION = None

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)
8 changes: 7 additions & 1 deletion bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ def new_app(app, bench_path='.'):
app = app.lower().replace(" ", "_").replace("-", "_")
logger.info('creating new app {}'.format(app))
apps = os.path.abspath(os.path.join(bench_path, 'apps'))
run_frappe_cmd('make-app', apps, app, bench_path=bench_path)
bench.set_frappe_version(bench_path=bench_path)

if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --make_app {apps} {app}".format(frappe=get_frappe(bench_path=bench_path),
apps=apps, app=app))
else:
run_frappe_cmd('make-app', apps, app, bench_path=bench_path)
install_app(app, bench_path=bench_path)

def install_app(app, bench_path=".", verbose=False, no_cache=False):
Expand Down
1 change: 1 addition & 0 deletions bench/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def bench_command(bench_path='.'):
import bench
from bench.utils import setup_logging

bench.set_frappe_version(bench_path=bench_path)
setup_logging(bench_path=bench_path)


Expand Down
48 changes: 36 additions & 12 deletions bench/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from six.moves.urllib.parse import urlparse

import bench
from bench import env


class PatchError(Exception):
Expand Down Expand Up @@ -109,11 +110,15 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_upda
if apps_path:
install_apps_from_path(apps_path, bench_path=path)

if not skip_assets:
update_node_packages(bench_path=path)
build_assets(bench_path=path)

bench.set_frappe_version(bench_path=path)
if bench.FRAPPE_VERSION > 5:
if not skip_assets:
update_node_packages(bench_path=path)

set_all_patches_executed(bench_path=path)
if not skip_assets:
build_assets(bench_path=path)

if not skip_redis_config_generation:
redis.generate_config(path)
Expand Down Expand Up @@ -212,16 +217,26 @@ def setup_socketio(bench_path='.'):
babel-cli babel-preset-es2015 babel-preset-es2016 babel-preset-es2017 babel-preset-babili", cwd=bench_path)

def patch_sites(bench_path='.'):
bench.set_frappe_version(bench_path=bench_path)

try:
run_frappe_cmd('--site', 'all', 'migrate', bench_path=bench_path)
if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --latest all".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites'))
else:
run_frappe_cmd('--site', 'all', 'migrate', bench_path=bench_path)
except subprocess.CalledProcessError:
raise PatchError

def build_assets(bench_path='.', app=None):
command = 'bench build'
if app:
command += ' --app {}'.format(app)
exec_cmd(command, cwd=bench_path)
bench.set_frappe_version(bench_path=bench_path)

if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --build".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites'))
else:
command = 'bench build'
if app:
command += ' --app {}'.format(app)
exec_cmd(command, cwd=bench_path)

def get_sites(bench_path='.'):
sites_path = os.path.join(bench_path, 'sites')
Expand All @@ -240,7 +255,12 @@ def setup_auto_update(bench_path='.'):
def setup_backups(bench_path='.'):
logger.info('setting up backups')
bench_dir = get_bench_dir(bench_path=bench_path)
backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0])
bench.set_frappe_version(bench_path=bench_path)

if bench.FRAPPE_VERSION == 4:
backup_command = "cd {sites_dir} && {frappe} --backup all".format(frappe=get_frappe(bench_path=bench_path),)
else:
backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0])

add_to_crontab('0 */6 * * * {backup_command} >> {logfile} 2>&1'.format(backup_command=backup_command,
logfile=os.path.join(get_bench_dir(bench_path=bench_path), 'logs', 'backup.log')))
Expand Down Expand Up @@ -282,8 +302,6 @@ def update_bench(bench_repo=True, requirements=True):
logger.info("Bench Updated!")

def setup_sudoers(user):
from bench import env

if not os.path.exists('/etc/sudoers.d'):
os.makedirs('/etc/sudoers.d')

Expand Down Expand Up @@ -539,7 +557,13 @@ def install_requirements(req_file, user=False):
exec_cmd("{python} -m pip install {user_flag} -q -U -r {req_file}".format(python=python, user_flag=user_flag, req_file=req_file))

def backup_site(site, bench_path='.'):
run_frappe_cmd('--site', site, 'backup', bench_path=bench_path)
bench.set_frappe_version(bench_path=bench_path)

if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --backup {site}".format(frappe=get_frappe(bench_path=bench_path), site=site),
cwd=os.path.join(bench_path, 'sites'))
else:
run_frappe_cmd('--site', site, 'backup', bench_path=bench_path)

def backup_all_sites(bench_path='.'):
for site in get_sites(bench_path=bench_path):
Expand Down

0 comments on commit cdd7d34

Please sign in to comment.