diff --git a/bench/__init__.py b/bench/__init__.py index 8f1ef651..12060392 100644 --- a/bench/__init__.py +++ b/bench/__init__.py @@ -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='.'): diff --git a/bench/config/__init__.py b/bench/config/__init__.py index e69de29b..5b6b5bcb 100644 --- a/bench/config/__init__.py +++ b/bench/config/__init__.py @@ -0,0 +1,2 @@ +from jinja2 import Environment, PackageLoader +env = Environment(loader=PackageLoader('bench.config')) diff --git a/bench/config/lets_encrypt.py b/bench/config/lets_encrypt.py index 4beac157..17f35dd0 100755 --- a/bench/config/lets_encrypt.py +++ b/bench/config/lets_encrypt.py @@ -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) diff --git a/bench/config/nginx.py b/bench/config/nginx.py index 9f10c6f7..d2154112 100644 --- a/bench/config/nginx.py +++ b/bench/config/nginx.py @@ -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"]) diff --git a/bench/config/procfile.py b/bench/config/procfile.py index a6982c83..cf3899b6 100755 --- a/bench/config/procfile.py +++ b/bench/config/procfile.py @@ -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'), diff --git a/bench/config/redis.py b/bench/config/redis.py index ae9b5b0f..42005b07 100644 --- a/bench/config/redis.py +++ b/bench/config/redis.py @@ -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")) diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index 43560cf0..9e9b7a89 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -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) diff --git a/bench/config/systemd.py b/bench/config/systemd.py index 72bed1f2..dbf28c06 100644 --- a/bench/config/systemd.py +++ b/bench/config/systemd.py @@ -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) diff --git a/bench/utils.py b/bench/utils.py index 1e4faf33..750f6a71 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -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'),