From 3bef843d65f519661fed960bbfeb12c11e69d2eb Mon Sep 17 00:00:00 2001
From: dobli <dobler.alex@gmail.com>
Date: Mon, 15 Apr 2019 13:15:29 +0200
Subject: [PATCH] use fixed template folder

---
 building_manager.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/building_manager.py b/building_manager.py
index 0bb4f6d..5a44062 100755
--- a/building_manager.py
+++ b/building_manager.py
@@ -35,6 +35,7 @@ st = Style([
     ('instruction', '')               # user instructions for selections
 ])
 
+
 # ******************************
 # Constants <<<
 # ******************************
@@ -109,6 +110,14 @@ class Service(ServiceBody, Enum):
 # >>>
 
 
+# ******************************
+# State Variables <<<
+# ******************************
+base_dir = sys.path[0]
+template_path = f'{base_dir}/{TEMPLATE_DIR}'
+# >>>
+
+
 # ******************************
 # Compose file functions <<<
 # ******************************
@@ -119,10 +128,9 @@ def generate_initial_compose(base_dir):
 
     :base_dir: Folder to place configuration files into
     """
-    base_path = base_dir + '/' + CUSTOM_DIR
-    template_path = base_dir + '/' + TEMPLATE_DIR
+    custom_path = base_dir + '/' + CUSTOM_DIR
     # compose file
-    compose = base_path + '/' + COMPOSE_NAME
+    compose = custom_path + '/' + COMPOSE_NAME
     # skeleton file
     skeleton = template_path + '/' + SKELETON_NAME
 
@@ -515,7 +523,6 @@ def get_service_template(base_dir, service_name):
 
     :return: yaml entry of a service
     """
-    template_path = base_dir + '/' + TEMPLATE_DIR
     templates = template_path + '/' + TEMPLATES_NAME
 
     with open(templates, 'r') as templates_file:
@@ -682,10 +689,10 @@ def copy_template_config(base_dir, config_path):
     :config_path: relative path of config to copy from template
     """
     custom_path = base_dir + '/' + CUSTOM_DIR + "/" + config_path
-    template_path = base_dir + '/' + TEMPLATE_DIR + "/" + config_path
+    template_config = f"{template_path}/{config_path}"
 
-    logging.info(f'Copy {config_path} from {custom_path} to {template_path}')
-    copy2(template_path, custom_path)
+    logging.info(f'Copy {config_path} from {template_config} to {custom_path}')
+    copy2(template_config, custom_path)
 
 
 def generate_mosquitto_user_line(username, password):
-- 
GitLab