mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 00:37:51 +00:00
refactor: bench update workflow
* Separate out branch validation logic * Add type hints * Raise named Exception "CannotUpdateReleaseBench" instead of SystemExit * Use "newer" APIs wherever possible
This commit is contained in:
parent
4655f6e785
commit
58e3d4931b
@ -13,7 +13,13 @@ import click
|
|||||||
import bench
|
import bench
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
from bench.utils import get_process_manager, which, log, exec_cmd, get_bench_name, get_cmd_output
|
from bench.utils import (
|
||||||
|
which,
|
||||||
|
log,
|
||||||
|
exec_cmd,
|
||||||
|
get_bench_name,
|
||||||
|
get_cmd_output,
|
||||||
|
)
|
||||||
from bench.exceptions import PatchError, ValidationError
|
from bench.exceptions import PatchError, ValidationError
|
||||||
|
|
||||||
|
|
||||||
@ -328,52 +334,8 @@ def build_assets(bench_path=".", app=None):
|
|||||||
exec_cmd(command, cwd=bench_path, env={"BENCH_DEVELOPER": "1"})
|
exec_cmd(command, cwd=bench_path, env={"BENCH_DEVELOPER": "1"})
|
||||||
|
|
||||||
|
|
||||||
def update(
|
def handle_version_upgrade(version_upgrade, bench_path, force, reset, conf):
|
||||||
pull=False,
|
from bench.utils import pause_exec, log
|
||||||
apps=None,
|
|
||||||
patch=False,
|
|
||||||
build=False,
|
|
||||||
requirements=False,
|
|
||||||
backup=True,
|
|
||||||
compile=True,
|
|
||||||
force=False,
|
|
||||||
reset=False,
|
|
||||||
restart_supervisor=False,
|
|
||||||
restart_systemd=False,
|
|
||||||
):
|
|
||||||
"""command: bench update"""
|
|
||||||
import re
|
|
||||||
from bench import patches
|
|
||||||
from bench.utils import clear_command_cache, pause_exec, log
|
|
||||||
from bench.utils.bench import (
|
|
||||||
restart_supervisor_processes,
|
|
||||||
restart_systemd_processes,
|
|
||||||
)
|
|
||||||
from bench.utils.system import backup_all_sites
|
|
||||||
from bench.app import pull_apps
|
|
||||||
from bench.utils.app import is_version_upgrade
|
|
||||||
from bench.config.common_site_config import update_config
|
|
||||||
from bench.bench import Bench
|
|
||||||
|
|
||||||
bench_path = os.path.abspath(".")
|
|
||||||
bench = Bench(bench_path)
|
|
||||||
patches.run(bench_path=bench_path)
|
|
||||||
conf = bench.conf
|
|
||||||
|
|
||||||
if apps and not pull:
|
|
||||||
apps = []
|
|
||||||
|
|
||||||
clear_command_cache(bench_path=".")
|
|
||||||
|
|
||||||
if conf.get("release_bench"):
|
|
||||||
print("Release bench detected, cannot update!")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not (pull or patch or build or requirements):
|
|
||||||
pull, patch, build, requirements = True, True, True, True
|
|
||||||
|
|
||||||
validate_branch()
|
|
||||||
version_upgrade = is_version_upgrade()
|
|
||||||
|
|
||||||
if version_upgrade[0]:
|
if version_upgrade[0]:
|
||||||
if force:
|
if force:
|
||||||
@ -404,6 +366,61 @@ To avoid seeing this warning, set shallow_clone to false in your common_site_con
|
|||||||
|
|
||||||
if version_upgrade[0] or (not version_upgrade[0] and force):
|
if version_upgrade[0] or (not version_upgrade[0] and force):
|
||||||
validate_upgrade(version_upgrade[1], version_upgrade[2], bench_path=bench_path)
|
validate_upgrade(version_upgrade[1], version_upgrade[2], bench_path=bench_path)
|
||||||
|
|
||||||
|
|
||||||
|
def update(
|
||||||
|
pull: bool = False,
|
||||||
|
apps: str = None,
|
||||||
|
patch: bool = False,
|
||||||
|
build: bool = False,
|
||||||
|
requirements: bool = False,
|
||||||
|
backup: bool = True,
|
||||||
|
compile: bool = True,
|
||||||
|
force: bool = False,
|
||||||
|
reset: bool = False,
|
||||||
|
restart_supervisor: bool = False,
|
||||||
|
restart_systemd: bool = False,
|
||||||
|
):
|
||||||
|
"""command: bench update"""
|
||||||
|
import re
|
||||||
|
from bench import patches
|
||||||
|
|
||||||
|
from bench.app import pull_apps
|
||||||
|
from bench.bench import Bench
|
||||||
|
from bench.config.common_site_config import update_config
|
||||||
|
from bench.exceptions import CannotUpdateReleaseBench
|
||||||
|
|
||||||
|
from bench.utils import clear_command_cache
|
||||||
|
from bench.utils.app import is_version_upgrade
|
||||||
|
from bench.utils.bench import (
|
||||||
|
restart_supervisor_processes,
|
||||||
|
restart_systemd_processes,
|
||||||
|
)
|
||||||
|
from bench.utils.system import backup_all_sites
|
||||||
|
|
||||||
|
bench_path = os.path.abspath(".")
|
||||||
|
bench = Bench(bench_path)
|
||||||
|
patches.run(bench_path=bench_path)
|
||||||
|
conf = bench.conf
|
||||||
|
|
||||||
|
clear_command_cache(bench_path=".")
|
||||||
|
|
||||||
|
if conf.get("release_bench"):
|
||||||
|
raise CannotUpdateReleaseBench("Release bench detected, cannot update!")
|
||||||
|
|
||||||
|
if not (pull or patch or build or requirements):
|
||||||
|
pull, patch, build, requirements = True, True, True, True
|
||||||
|
|
||||||
|
if apps and pull:
|
||||||
|
apps = [app.strip() for app in re.split(",| ", apps) if app]
|
||||||
|
else:
|
||||||
|
apps = []
|
||||||
|
|
||||||
|
validate_branch()
|
||||||
|
|
||||||
|
version_upgrade = is_version_upgrade()
|
||||||
|
handle_version_upgrade(version_upgrade, bench_path, force, reset, conf)
|
||||||
|
|
||||||
conf.update({"maintenance_mode": 1, "pause_scheduler": 1})
|
conf.update({"maintenance_mode": 1, "pause_scheduler": 1})
|
||||||
update_config(conf, bench_path=bench_path)
|
update_config(conf, bench_path=bench_path)
|
||||||
|
|
||||||
@ -411,9 +428,6 @@ To avoid seeing this warning, set shallow_clone to false in your common_site_con
|
|||||||
print("Backing up sites...")
|
print("Backing up sites...")
|
||||||
backup_all_sites(bench_path=bench_path)
|
backup_all_sites(bench_path=bench_path)
|
||||||
|
|
||||||
if apps:
|
|
||||||
apps = [app.strip() for app in re.split(",| ", apps) if app]
|
|
||||||
|
|
||||||
if pull:
|
if pull:
|
||||||
print("Updating apps source...")
|
print("Updating apps source...")
|
||||||
pull_apps(apps=apps, bench_path=bench_path, reset=reset)
|
pull_apps(apps=apps, bench_path=bench_path, reset=reset)
|
||||||
@ -428,7 +442,7 @@ To avoid seeing this warning, set shallow_clone to false in your common_site_con
|
|||||||
|
|
||||||
if build:
|
if build:
|
||||||
print("Building assets...")
|
print("Building assets...")
|
||||||
build_assets(bench_path=bench_path)
|
bench.build()
|
||||||
|
|
||||||
if version_upgrade[0] or (not version_upgrade[0] and force):
|
if version_upgrade[0] or (not version_upgrade[0] and force):
|
||||||
post_upgrade(version_upgrade[1], version_upgrade[2], bench_path=bench_path)
|
post_upgrade(version_upgrade[1], version_upgrade[2], bench_path=bench_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user