mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 16:36:25 +00:00
Merge pull request #884 from gavindsouza/bench-update
feat: Bench update
This commit is contained in:
commit
be162b542d
@ -5,7 +5,7 @@ from bench.config.common_site_config import get_config, update_config
|
|||||||
from bench.app import pull_all_apps, is_version_upgrade, validate_branch
|
from bench.app import pull_all_apps, is_version_upgrade, validate_branch
|
||||||
from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update,
|
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,
|
update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets,
|
||||||
restart_supervisor_processes, restart_systemd_processes)
|
restart_supervisor_processes, restart_systemd_processes, is_bench_directory)
|
||||||
from bench import patches
|
from bench import patches
|
||||||
from six.moves import reload_module
|
from six.moves import reload_module
|
||||||
|
|
||||||
@ -25,6 +25,11 @@ from six.moves import reload_module
|
|||||||
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, force=False, reset=False):
|
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, force=False, reset=False):
|
||||||
"Update bench"
|
"Update bench"
|
||||||
|
|
||||||
|
if not is_bench_directory():
|
||||||
|
"""Update only bench if bench update called from outside a bench"""
|
||||||
|
update_bench(bench_repo=True, requirements=True)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if not (pull or patch or build or bench or requirements):
|
if not (pull or patch or build or bench or requirements):
|
||||||
pull, patch, build, bench, requirements = True, True, True, True, True
|
pull, patch, build, bench, requirements = True, True, True, True, True
|
||||||
|
|
||||||
@ -35,7 +40,7 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
|
|||||||
conf = get_config(".")
|
conf = get_config(".")
|
||||||
|
|
||||||
if bench and conf.get('update_bench_on_update'):
|
if bench and conf.get('update_bench_on_update'):
|
||||||
update_bench()
|
update_bench(bench_repo=True, requirements=False)
|
||||||
restart_update({
|
restart_update({
|
||||||
'pull': pull,
|
'pull': pull,
|
||||||
'patch': patch,
|
'patch': patch,
|
||||||
|
@ -16,6 +16,18 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
|
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
|
||||||
|
|
||||||
|
|
||||||
|
def is_bench_directory():
|
||||||
|
cur_dir = os.path.curdir
|
||||||
|
is_bench = True
|
||||||
|
|
||||||
|
for folder in folders_in_bench:
|
||||||
|
path = os.path.join(cur_dir, folder)
|
||||||
|
is_bench = is_bench and os.path.exists(path)
|
||||||
|
|
||||||
|
return is_bench
|
||||||
|
|
||||||
|
|
||||||
def safe_decode(string, encoding = 'utf-8'):
|
def safe_decode(string, encoding = 'utf-8'):
|
||||||
try:
|
try:
|
||||||
string = string.decode(encoding)
|
string = string.decode(encoding)
|
||||||
@ -256,13 +268,23 @@ def read_crontab():
|
|||||||
s.stdout.close()
|
s.stdout.close()
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def update_bench():
|
def update_bench(bench_repo=True, requirements=True):
|
||||||
logger.info('updating bench')
|
logger.info("Updating bench")
|
||||||
|
|
||||||
# bench-repo folder
|
# bench-repo folder
|
||||||
cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
exec_cmd("git pull", cwd=cwd)
|
if bench_repo:
|
||||||
|
try:
|
||||||
|
exec_cmd("git pull", cwd=cwd)
|
||||||
|
except bench.utils.CommandFailedError:
|
||||||
|
exec_cmd("git stash", cwd=cwd)
|
||||||
|
logger.info("Stashing changes made at {}\nUse git stash apply to recover changes after the successful update!".format(cwd))
|
||||||
|
|
||||||
|
if requirements:
|
||||||
|
update_bench_requirements()
|
||||||
|
|
||||||
|
logger.info("Bench Updated!")
|
||||||
|
|
||||||
def setup_sudoers(user):
|
def setup_sudoers(user):
|
||||||
if not os.path.exists('/etc/sudoers.d'):
|
if not os.path.exists('/etc/sudoers.d'):
|
||||||
@ -424,19 +446,24 @@ def set_default_site(site, bench_path='.'):
|
|||||||
exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site),
|
exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site),
|
||||||
cwd=os.path.join(bench_path, 'sites'))
|
cwd=os.path.join(bench_path, 'sites'))
|
||||||
|
|
||||||
def update_requirements(bench_path='.'):
|
def update_bench_requirements():
|
||||||
print('Updating Python libraries...')
|
|
||||||
|
|
||||||
# update env pip
|
|
||||||
env_pip = os.path.join(bench_path, 'env', 'bin', 'pip')
|
|
||||||
exec_cmd("{pip} install -q -U pip".format(pip=env_pip))
|
|
||||||
|
|
||||||
# Update bench requirements (at user level)
|
|
||||||
bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt')
|
bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt')
|
||||||
user_pip = which("pip" if PY2 else "pip3")
|
user_pip = which("pip" if PY2 else "pip3")
|
||||||
install_requirements(user_pip, bench_req_file, user=True)
|
install_requirements(user_pip, bench_req_file, user=True)
|
||||||
|
|
||||||
|
def update_env_pip(bench_path):
|
||||||
|
env_pip = os.path.join(bench_path, 'env', 'bin', 'pip')
|
||||||
|
exec_cmd("{pip} install -q -U pip".format(pip=env_pip))
|
||||||
|
|
||||||
|
def update_requirements(bench_path='.'):
|
||||||
from bench.app import get_apps, install_app
|
from bench.app import get_apps, install_app
|
||||||
|
print('Updating Python libraries...')
|
||||||
|
|
||||||
|
# update env pip
|
||||||
|
update_env_pip(bench_path)
|
||||||
|
|
||||||
|
# Update bench requirements (at user level)
|
||||||
|
update_bench_requirements()
|
||||||
|
|
||||||
for app in get_apps():
|
for app in get_apps():
|
||||||
install_app(app, bench_path=bench_path)
|
install_app(app, bench_path=bench_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user