mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 00:37:51 +00:00
refactor: Exceptions, Setup & Styles
This commit is contained in:
parent
01442ba150
commit
c5a38b3647
15
bench/app.py
15
bench/app.py
@ -13,16 +13,13 @@ from setuptools.config import read_configuration
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.utils import CommandFailedError, build_assets, check_git_for_shallow_clone, exec_cmd, get_cmd_output, get_frappe, is_bench_directory, restart_supervisor_processes, restart_systemd_processes, run_frappe_cmd
|
||||
from bench.exceptions import InvalidRemoteException, InvalidBranchException, CommandFailedError
|
||||
from bench.utils import build_assets, check_git_for_shallow_clone, exec_cmd, get_cmd_output, is_bench_directory, restart_supervisor_processes, restart_systemd_processes, run_frappe_cmd
|
||||
|
||||
|
||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||
|
||||
|
||||
class InvalidBranchException(Exception): pass
|
||||
class InvalidRemoteException(Exception): pass
|
||||
|
||||
|
||||
def find_org(org_repo):
|
||||
import requests
|
||||
|
||||
@ -129,12 +126,6 @@ class App:
|
||||
return f"git@{self.remote_server}:{self.org}/{self.repo}.git"
|
||||
|
||||
|
||||
class MajorVersionUpgradeException(Exception):
|
||||
def __init__(self, message, upstream_version, local_version):
|
||||
super(MajorVersionUpgradeException, self).__init__(message)
|
||||
self.upstream_version = upstream_version
|
||||
self.local_version = local_version
|
||||
|
||||
def get_apps(bench_path='.'):
|
||||
try:
|
||||
with open(os.path.join(bench_path, 'sites', 'apps.txt')) as f:
|
||||
@ -594,7 +585,7 @@ def get_repo_dir(app, bench_path='.'):
|
||||
def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrade=True):
|
||||
import git
|
||||
import importlib
|
||||
from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, post_upgrade
|
||||
from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, post_upgrade
|
||||
|
||||
apps_dir = os.path.join(bench_path, 'apps')
|
||||
version_upgrade = (False,)
|
||||
|
@ -198,8 +198,8 @@ def setup_manager(yes=False, port=23624, domain=None):
|
||||
|
||||
@click.command("config", help="Generate or over-write sites/common_site_config.json")
|
||||
def setup_config():
|
||||
from bench.config.common_site_config import make_config
|
||||
make_config(".")
|
||||
from bench.config.common_site_config import setup_config
|
||||
setup_config(".")
|
||||
|
||||
|
||||
@click.command("add-domain", help="Add a custom domain to a particular site")
|
||||
|
@ -17,7 +17,7 @@ default_config = {
|
||||
'live_reload': True
|
||||
}
|
||||
|
||||
def make_config(bench_path):
|
||||
def setup_config(bench_path):
|
||||
make_pid_folder(bench_path)
|
||||
bench_config = get_config(bench_path)
|
||||
bench_config.update(default_config)
|
||||
|
@ -10,7 +10,8 @@ from bench.config.common_site_config import get_config
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
from bench.config.production_setup import service
|
||||
from bench.config.site_config import get_domains, remove_domain, update_site_config
|
||||
from bench.utils import CommandFailedError, exec_cmd, update_common_site_config
|
||||
from bench.utils import exec_cmd, update_common_site_config
|
||||
from bench.exceptions import CommandFailedError
|
||||
|
||||
|
||||
def setup_letsencrypt(site, custom_domain, bench_path, interactive):
|
||||
|
@ -9,8 +9,8 @@ from bench.config.common_site_config import get_config
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
from bench.config.supervisor import generate_supervisor_config, update_supervisord_config
|
||||
from bench.config.systemd import generate_systemd_config
|
||||
from bench.utils import CommandFailedError, exec_cmd, which, fix_prod_setup_perms, get_bench_name, get_cmd_output, log
|
||||
|
||||
from bench.utils import exec_cmd, which, fix_prod_setup_perms, get_bench_name, get_cmd_output, log
|
||||
from bench.exceptions import CommandFailedError
|
||||
|
||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||
|
||||
|
11
bench/exceptions.py
Normal file
11
bench/exceptions.py
Normal file
@ -0,0 +1,11 @@
|
||||
class InvalidBranchException(Exception):
|
||||
pass
|
||||
|
||||
class InvalidRemoteException(Exception):
|
||||
pass
|
||||
|
||||
class PatchError(Exception):
|
||||
pass
|
||||
|
||||
class CommandFailedError(Exception):
|
||||
pass
|
@ -16,14 +16,9 @@ import click
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.exceptions import PatchError
|
||||
|
||||
|
||||
class PatchError(Exception):
|
||||
pass
|
||||
|
||||
class CommandFailedError(Exception):
|
||||
pass
|
||||
|
||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||
bench_cache_file = '.bench.cmd'
|
||||
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
|
||||
@ -122,17 +117,7 @@ def pause_exec(seconds=10):
|
||||
print(" " * 40, end="\r")
|
||||
|
||||
|
||||
def init(path, apps_path=None, no_procfile=False, no_backups=False,
|
||||
frappe_path=None, frappe_branch=None, verbose=False, clone_from=None,
|
||||
skip_redis_config_generation=False, clone_without_update=False, ignore_exist=False, skip_assets=False,
|
||||
python='python3'):
|
||||
"""Initialize a new bench directory"""
|
||||
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
|
||||
|
||||
def setup_bench_directory(path, ignore_exist=False):
|
||||
if os.path.exists(path) and not ignore_exist:
|
||||
log(f'Path {path} already exists!')
|
||||
sys.exit(0)
|
||||
@ -149,11 +134,42 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
|
||||
|
||||
def init(path, apps_path=None, no_procfile=False, no_backups=False,
|
||||
frappe_path=None, frappe_branch=None, verbose=False, clone_from=None,
|
||||
skip_redis_config_generation=False, clone_without_update=False, ignore_exist=False, skip_assets=False,
|
||||
python='python3'):
|
||||
"""Initialize a new bench directory
|
||||
|
||||
1. create a bench directory in the given path
|
||||
2. setup logging for the bench
|
||||
3. setup env for the bench
|
||||
4. setup config for the bench
|
||||
5. clone frappe
|
||||
6. install python & node dependencies
|
||||
7. build assets
|
||||
8. setup redi
|
||||
9. setup procfile
|
||||
10. setup backups crontab
|
||||
11. setup patches.txt for bench
|
||||
"""
|
||||
|
||||
# Use print("\033c", end="") to clear entire screen after each step and re-render each list
|
||||
# another way => https://stackoverflow.com/a/44591228/10309266
|
||||
|
||||
from bench.app import get_app, install_apps_from_path
|
||||
from bench.config import redis
|
||||
from bench.config.common_site_config import setup_config
|
||||
from bench.config.procfile import setup_procfile
|
||||
from bench.patches import set_all_patches_executed
|
||||
|
||||
setup_bench_directory(path=path, ignore_exist=ignore_exist)
|
||||
|
||||
setup_logging(bench_path=path)
|
||||
|
||||
setup_env(bench_path=path, python=python)
|
||||
|
||||
make_config(path)
|
||||
setup_config(path)
|
||||
|
||||
if clone_from:
|
||||
clone_apps_from(bench_path=path, clone_from=clone_from, update_app=not clone_without_update)
|
||||
@ -177,6 +193,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
|
||||
|
||||
if not no_procfile:
|
||||
setup_procfile(path, skip_redis=skip_redis_config_generation)
|
||||
|
||||
if not no_backups:
|
||||
setup_backups(bench_path=path)
|
||||
|
||||
@ -283,8 +300,10 @@ To avoid seeing this warning, set shallow_clone to false in your common_site_con
|
||||
def copy_patches_txt(bench_path):
|
||||
import shutil
|
||||
|
||||
shutil.copy(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'patches', 'patches.txt'),
|
||||
os.path.join(bench_path, 'patches.txt'))
|
||||
shutil.copy(
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'patches', 'patches.txt'),
|
||||
os.path.join(bench_path, 'patches.txt')
|
||||
)
|
||||
|
||||
|
||||
def clone_apps_from(bench_path, clone_from, update_app=True):
|
||||
|
Loading…
Reference in New Issue
Block a user