From 4c0d3f8d203a83ddb1e9fb6cf943f3e54164a98c Mon Sep 17 00:00:00 2001
From: Marc Bonnici <marc.bonnici@arm.com>
Date: Tue, 15 Aug 2017 14:40:12 +0100
Subject: [PATCH] Bootstrap: Fixes not using newly created config files

If the $WA_USER_DIRECTORY folder is not present on the users
system it is automatically created and a default config.py file
created. Previously this newly created file would not be loaded into
WA causing it to crash.
---
 wlauto/core/bootstrap.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/wlauto/core/bootstrap.py b/wlauto/core/bootstrap.py
index e4f4b69f..05833e71 100644
--- a/wlauto/core/bootstrap.py
+++ b/wlauto/core/bootstrap.py
@@ -152,7 +152,8 @@ def init_environment(env_root, dep_dir, extension_paths, overwrite_existing=Fals
     os.makedirs(env_root)
     with open(os.path.join(_this_dir, '..', 'config_example.py')) as rf:
         text = re.sub(r'""".*?"""', '', rf.read(), 1, re.DOTALL)
-        with open(os.path.join(_env_root, 'config.py'), 'w') as wf:
+        config_path = os.path.join(env_root, 'config.py')
+        with open(config_path, 'w') as wf:
             wf.write(text)
 
     os.makedirs(dep_dir)
@@ -173,6 +174,7 @@ def init_environment(env_root, dep_dir, extension_paths, overwrite_existing=Fals
                     os.chown(os.path.join(root, d), uid, gid)
                 for f in files:  # pylint: disable=W0621
                     os.chown(os.path.join(root, f), uid, gid)
+    return config_path
 
 
 _env_root = os.getenv('WA_USER_DIRECTORY', os.path.join(_user_home, '.workload_automation'))
@@ -190,7 +192,8 @@ for filename in ['config.py', 'config.yaml']:
         _env_configs.append(filepath)
 
 if not os.path.isdir(_env_root):
-    init_environment(_env_root, _dep_dir, _extension_paths)
+    cfg_path = init_environment(_env_root, _dep_dir, _extension_paths)
+    _env_configs.append(cfg_path)
 elif not _env_configs:
     filepath = os.path.join(_env_root, 'config.py')
     with open(os.path.join(_this_dir, '..', 'config_example.py')) as f: