mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
fix: move bench.env to bench.config.env
changed namespace to allow usage of __init__ file without checking for jinja2 dependencies
This commit is contained in:
parent
e218a7aa09
commit
1f4994d434
@ -1,10 +1,7 @@
|
||||
from jinja2 import Environment, PackageLoader
|
||||
|
||||
VERSION = "5.0.0"
|
||||
PROJECT_NAME = "frappe-bench"
|
||||
FRAPPE_VERSION = None
|
||||
__version__ = VERSION
|
||||
env = Environment(loader=PackageLoader('bench.config'))
|
||||
|
||||
|
||||
def set_frappe_version(bench_path='.'):
|
||||
|
@ -0,0 +1,2 @@
|
||||
from jinja2 import Environment, PackageLoader
|
||||
env = Environment(loader=PackageLoader('bench.config'))
|
@ -44,7 +44,7 @@ def setup_letsencrypt(site, custom_domain, bench_path, interactive):
|
||||
|
||||
|
||||
def create_config(site, custom_domain):
|
||||
config = bench.env.get_template('letsencrypt.cfg').render(domain=custom_domain or site)
|
||||
config = bench.config.env.get_template('letsencrypt.cfg').render(domain=custom_domain or site)
|
||||
config_path = '/etc/letsencrypt/configs/{site}.cfg'.format(site=custom_domain or site)
|
||||
create_dir_if_missing(config_path)
|
||||
|
||||
|
@ -9,6 +9,7 @@ import click
|
||||
from six import string_types
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.utils import get_bench_name, get_sites
|
||||
|
||||
|
||||
@ -19,14 +20,11 @@ def make_nginx_conf(bench_path, yes=False):
|
||||
if not click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?'):
|
||||
return
|
||||
|
||||
from bench import env
|
||||
from bench.config.common_site_config import get_config
|
||||
|
||||
template = env.get_template('nginx.conf')
|
||||
template = bench.config.env.get_template('nginx.conf')
|
||||
bench_path = os.path.abspath(bench_path)
|
||||
sites_path = os.path.join(bench_path, "sites")
|
||||
|
||||
config = get_config(bench_path)
|
||||
config = bench.config.common_site_config.get_config(bench_path)
|
||||
sites = prepare_sites(config, bench_path)
|
||||
bench_name = get_bench_name(bench_path)
|
||||
|
||||
@ -58,17 +56,15 @@ def make_nginx_conf(bench_path, yes=False):
|
||||
f.write(nginx_conf)
|
||||
|
||||
def make_bench_manager_nginx_conf(bench_path, yes=False, port=23624, domain=None):
|
||||
from bench import env
|
||||
from bench.config.site_config import get_site_config
|
||||
from bench.config.common_site_config import get_config
|
||||
|
||||
template = env.get_template('bench_manager_nginx.conf')
|
||||
template = bench.config.env.get_template('bench_manager_nginx.conf')
|
||||
bench_path = os.path.abspath(bench_path)
|
||||
sites_path = os.path.join(bench_path, "sites")
|
||||
|
||||
config = get_config(bench_path)
|
||||
site_config = get_site_config(domain, bench_path=bench_path)
|
||||
sites = prepare_sites(config, bench_path)
|
||||
bench_name = get_bench_name(bench_path)
|
||||
|
||||
template_vars = {
|
||||
@ -153,9 +149,6 @@ def prepare_sites(config, bench_path):
|
||||
while site["port"] in ports_in_use:
|
||||
site["port"] += 1
|
||||
|
||||
# if site["port"] in ports_in_use:
|
||||
# raise Exception("Port {0} is being used by another site {1}".format(site["port"], ports_in_use[site["port"]]))
|
||||
|
||||
if site["port"] in ports_in_use and not site["name"] in ports_in_use[site["port"]]:
|
||||
shared_port_exception_found = True
|
||||
ports_in_use[site["port"]].append(site["name"])
|
||||
|
@ -10,7 +10,7 @@ def setup_procfile(bench_path, yes=False, skip_redis=False):
|
||||
click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?',
|
||||
abort=True)
|
||||
|
||||
procfile = bench.env.get_template('Procfile').render(
|
||||
procfile = bench.config.env.get_template('Procfile').render(
|
||||
node=find_executable("node") or find_executable("nodejs"),
|
||||
use_rq=use_rq(bench_path),
|
||||
webserver_port=config.get('webserver_port'),
|
||||
|
@ -52,7 +52,7 @@ def generate_config(bench_path):
|
||||
os.makedirs(pid_path)
|
||||
|
||||
def write_redis_config(template_name, context, bench_path):
|
||||
template = bench.env.get_template(template_name)
|
||||
template = bench.config.env.get_template(template_name)
|
||||
|
||||
if "pid_path" not in context:
|
||||
context["pid_path"] = os.path.abspath(os.path.join(bench_path, "config", "pids"))
|
||||
|
@ -20,7 +20,7 @@ def generate_supervisor_config(bench_path, user=None, yes=False):
|
||||
|
||||
update_supervisord_conf(user=user)
|
||||
|
||||
template = bench.env.get_template('supervisor.conf')
|
||||
template = bench.config.env.get_template('supervisor.conf')
|
||||
config = get_config(bench_path=bench_path)
|
||||
bench_dir = os.path.abspath(bench_path)
|
||||
|
||||
|
@ -78,7 +78,7 @@ def setup_systemd_directory(bench_path):
|
||||
|
||||
def setup_main_config(bench_info, bench_path):
|
||||
# Main config
|
||||
bench_template = bench.env.get_template('systemd/frappe-bench.target')
|
||||
bench_template = bench.config.env.get_template('systemd/frappe-bench.target')
|
||||
bench_config = bench_template.render(**bench_info)
|
||||
bench_config_path = os.path.join(bench_path, 'config', 'systemd' , bench_info.get("bench_name") + '.target')
|
||||
|
||||
@ -87,11 +87,11 @@ def setup_main_config(bench_info, bench_path):
|
||||
|
||||
def setup_workers_config(bench_info, bench_path):
|
||||
# Worker Group
|
||||
bench_workers_target_template = bench.env.get_template('systemd/frappe-bench-workers.target')
|
||||
bench_default_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-default-worker.service')
|
||||
bench_short_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-short-worker.service')
|
||||
bench_long_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-long-worker.service')
|
||||
bench_schedule_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-schedule.service')
|
||||
bench_workers_target_template = bench.config.env.get_template('systemd/frappe-bench-workers.target')
|
||||
bench_default_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-default-worker.service')
|
||||
bench_short_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-short-worker.service')
|
||||
bench_long_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-long-worker.service')
|
||||
bench_schedule_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-schedule.service')
|
||||
|
||||
bench_workers_target_config = bench_workers_target_template.render(**bench_info)
|
||||
bench_default_worker_config = bench_default_worker_template.render(**bench_info)
|
||||
@ -122,9 +122,9 @@ def setup_workers_config(bench_info, bench_path):
|
||||
|
||||
def setup_web_config(bench_info, bench_path):
|
||||
# Web Group
|
||||
bench_web_target_template = bench.env.get_template('systemd/frappe-bench-web.target')
|
||||
bench_web_service_template = bench.env.get_template('systemd/frappe-bench-frappe-web.service')
|
||||
bench_node_socketio_template = bench.env.get_template('systemd/frappe-bench-node-socketio.service')
|
||||
bench_web_target_template = bench.config.env.get_template('systemd/frappe-bench-web.target')
|
||||
bench_web_service_template = bench.config.env.get_template('systemd/frappe-bench-frappe-web.service')
|
||||
bench_node_socketio_template = bench.config.env.get_template('systemd/frappe-bench-node-socketio.service')
|
||||
|
||||
bench_web_target_config = bench_web_target_template.render(**bench_info)
|
||||
bench_web_service_config = bench_web_service_template.render(**bench_info)
|
||||
@ -145,10 +145,10 @@ def setup_web_config(bench_info, bench_path):
|
||||
|
||||
def setup_redis_config(bench_info, bench_path):
|
||||
# Redis Group
|
||||
bench_redis_target_template = bench.env.get_template('systemd/frappe-bench-redis.target')
|
||||
bench_redis_cache_template = bench.env.get_template('systemd/frappe-bench-redis-cache.service')
|
||||
bench_redis_queue_template = bench.env.get_template('systemd/frappe-bench-redis-queue.service')
|
||||
bench_redis_socketio_template = bench.env.get_template('systemd/frappe-bench-redis-socketio.service')
|
||||
bench_redis_target_template = bench.config.env.get_template('systemd/frappe-bench-redis.target')
|
||||
bench_redis_cache_template = bench.config.env.get_template('systemd/frappe-bench-redis-cache.service')
|
||||
bench_redis_queue_template = bench.config.env.get_template('systemd/frappe-bench-redis-queue.service')
|
||||
bench_redis_socketio_template = bench.config.env.get_template('systemd/frappe-bench-redis-socketio.service')
|
||||
|
||||
bench_redis_target_config = bench_redis_target_template.render(**bench_info)
|
||||
bench_redis_cache_config = bench_redis_cache_template.render(**bench_info)
|
||||
|
@ -379,8 +379,6 @@ def read_crontab():
|
||||
|
||||
|
||||
def setup_sudoers(user):
|
||||
from bench import env
|
||||
|
||||
if not os.path.exists('/etc/sudoers.d'):
|
||||
os.makedirs('/etc/sudoers.d')
|
||||
|
||||
@ -394,7 +392,7 @@ def setup_sudoers(user):
|
||||
if set_permissions:
|
||||
os.chmod('/etc/sudoers', 0o440)
|
||||
|
||||
template = env.get_template('frappe_sudoers')
|
||||
template = bench.config.env.get_template('frappe_sudoers')
|
||||
frappe_sudoers = template.render(**{
|
||||
'user': user,
|
||||
'service': find_executable('service'),
|
||||
|
Loading…
Reference in New Issue
Block a user