diff --git a/bench/config/__init__.py b/bench/config/__init__.py index 301b515b..5a1b0c60 100644 --- a/bench/config/__init__.py +++ b/bench/config/__init__.py @@ -1,6 +1,7 @@ """Module for setting up system and respective bench configurations""" # imports - third party imports -from jinja2 import Environment, PackageLoader -env = Environment(loader=PackageLoader('bench.config')) +def env(): + from jinja2 import Environment, PackageLoader + return Environment(loader=PackageLoader('bench.config')) diff --git a/bench/config/lets_encrypt.py b/bench/config/lets_encrypt.py index 32ca3380..9f285199 100755 --- a/bench/config/lets_encrypt.py +++ b/bench/config/lets_encrypt.py @@ -48,7 +48,7 @@ def setup_letsencrypt(site, custom_domain, bench_path, interactive): def create_config(site, custom_domain): - config = bench.config.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 fbb73680..4ed4233d 100644 --- a/bench/config/nginx.py +++ b/bench/config/nginx.py @@ -20,7 +20,7 @@ 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 - template = bench.config.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") @@ -59,7 +59,7 @@ def make_bench_manager_nginx_conf(bench_path, yes=False, port=23624, domain=None from bench.config.site_config import get_site_config from bench.config.common_site_config import get_config - template = bench.config.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") diff --git a/bench/config/procfile.py b/bench/config/procfile.py index 1b3f20ed..e57e579d 100755 --- a/bench/config/procfile.py +++ b/bench/config/procfile.py @@ -18,7 +18,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.config.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 42005b07..9d8f3ee4 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.config.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 8788757f..8a3d07fa 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -22,7 +22,7 @@ def generate_supervisor_config(bench_path, user=None, yes=False): if not user: user = getpass.getuser() - template = bench.config.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 4a414825..574f857e 100644 --- a/bench/config/systemd.py +++ b/bench/config/systemd.py @@ -85,7 +85,7 @@ def setup_systemd_directory(bench_path): def setup_main_config(bench_info, bench_path): # Main config - bench_template = bench.config.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') @@ -94,11 +94,11 @@ def setup_main_config(bench_info, bench_path): def setup_workers_config(bench_info, bench_path): # Worker Group - 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_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) @@ -129,9 +129,9 @@ def setup_workers_config(bench_info, bench_path): def setup_web_config(bench_info, bench_path): # Web Group - 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_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) @@ -152,10 +152,10 @@ def setup_web_config(bench_info, bench_path): def setup_redis_config(bench_info, bench_path): # Redis Group - 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_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 7a08c346..4e7a24db 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -423,7 +423,7 @@ def setup_sudoers(user): if set_permissions: os.chmod('/etc/sudoers', 0o440) - template = bench.config.env.get_template('frappe_sudoers') + template = bench.config.env().get_template('frappe_sudoers') frappe_sudoers = template.render(**{ 'user': user, 'service': find_executable('service'),