From cf6e0b202ca9f82d68c20e90875b0194ef9d228f Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Tue, 2 Oct 2018 08:57:37 +0000
Subject: [PATCH] SW-415: do not overwrite file, but append to it if existing.
 Issue warning to fill in the new credentials

---
 LCS/PyCommon/dbcredentials.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/LCS/PyCommon/dbcredentials.py b/LCS/PyCommon/dbcredentials.py
index 8da2664132b..de825bd249b 100644
--- a/LCS/PyCommon/dbcredentials.py
+++ b/LCS/PyCommon/dbcredentials.py
@@ -189,10 +189,11 @@ class DBCredentials:
       new_path = os.path.join(user_info.pw_dir, '.lofar', 'dbcredentials', database+extension)
       if not os.path.exists(os.path.dirname(new_path)):
         os.makedirs(os.path.dirname(new_path))
-      with open(new_path, 'w') as new_file:
+      with open(new_path, 'w+') as new_file:
         new_file.write("[database:%s]\nhost=localhost\nuser=%s\npassword=unknown\ntype=unknown\nport=0\ndatabase=%s"
                        % (database,user_info.pw_name,database))
-      logger.info("created default dbcredentials file for database=%s at %s", database, new_path)
+      logger.info("Created default dbcredentials file for database=%s at %s", database, new_path)
+      logger.warning(" *** Please fill in the proper credentials for database=%s in new empty credentials file: '%s' ***", database, new_path)
 
   def get(self, database):
     """
-- 
GitLab