From 68cd3465bc275f54ee80761a8d8ad2ea549a8860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 23 Jan 2018 11:04:26 +0100 Subject: [PATCH] avocado.settings: Don't fail when user can't write user-config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The user-config location ("~/.config/avocado.conf") might not be writable by users (usually when executing in docker without user home-dir). Let's use the file if available, but don't fail in case we fail to produce it. Signed-off-by: Lukáš Doktor --- avocado/core/settings.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/avocado/core/settings.py b/avocado/core/settings.py index 6de72463..ddbf53dd 100644 --- a/avocado/core/settings.py +++ b/avocado/core/settings.py @@ -198,10 +198,16 @@ class Settings(object): for extra_file in glob.glob(os.path.join(_config_dir_system_extra, '*.conf')): self.process_config_path(extra_file) if not config_local: - path.init_dir(_config_dir_local) - with open(config_path_local, 'w') as config_local_fileobj: - config_local_fileobj.write('# You can use this file to override configuration values from ' - '%s and %s\n' % (config_path_system, _config_dir_system_extra)) + try: + path.init_dir(_config_dir_local) + with open(config_path_local, 'w') as config_local_fileobj: + content = ("# You can use this file to override " + "configuration values from '%s and %s\n" + % (config_path_system, + _config_dir_system_extra)) + config_local_fileobj.write(content) + except IOError: # Some users can't write it (docker) + pass else: self.process_config_path(config_path_local) else: -- GitLab