From 4bd793fb98790578f78ad5b8efa3cfd82f03d835 Mon Sep 17 00:00:00 2001 From: Alex Meadows Date: Sun, 23 Jun 2019 08:43:05 -0400 Subject: [PATCH] Trying for 0.4.3 Issue with config files and lambda remained. Trying another method to work with it. --- process_tracker/utilities/settings.py | 14 ++++++++------ tests/utilities/test_settings_manager.py | 3 --- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/process_tracker/utilities/settings.py b/process_tracker/utilities/settings.py index 6dad410..fdfc3a5 100644 --- a/process_tracker/utilities/settings.py +++ b/process_tracker/utilities/settings.py @@ -1,10 +1,10 @@ # Settings manager and configuration, both for initialization and reading. import configparser +import io import logging import os from pathlib import Path -import tempfile from process_tracker.utilities.aws_utilities import AwsUtilities @@ -68,6 +68,10 @@ def __init__(self, config_location=None): if exists: self.read_config_file() + else: + self.logger.info("Config file does not exist.") + if not cloud: + self.create_config_file() def create_config_file(self): """ @@ -100,17 +104,15 @@ def read_config_file(self): path=self.config_path ) and self.aws_utils.determine_s3_file_exists(path=self.config_file): - temp_file = tempfile.NamedTemporaryFile() bucket_name = self.aws_utils.determine_bucket_name(path=self.config_path) bucket = self.aws_utils.get_s3_bucket(bucket_name=bucket_name) key = self.aws_utils.determine_file_key(path=self.config_file) - bucket.download_file(key, temp_file.name) + cfg = bucket.Object(key).get() + cfg = io.TextIOWrapper(io.BytesIO(cfg["Body"].read())) - with open(temp_file.name, "r") as f: - self.config.readfp(f) - temp_file.close() + self.config.readfp(cfg) else: diff --git a/tests/utilities/test_settings_manager.py b/tests/utilities/test_settings_manager.py index 2c56264..941374d 100644 --- a/tests/utilities/test_settings_manager.py +++ b/tests/utilities/test_settings_manager.py @@ -17,7 +17,6 @@ def setUpClass(cls): cls.config = configparser.ConfigParser(allow_no_value=True) - @unittest.skip # Need to fix SettingsManager for this to work right. def test_config_location_set(self): """ Testing that if config_location is set that the path is used instead of setting to home directory. @@ -32,7 +31,6 @@ def test_config_location_set(self): self.assertEqual(expected_result, given_result) - @unittest.skip # Need to fix SettingsManager for this to work right. def test_config_location_s3(self): """ Testing that if config_location is set and the path is an s3 file/location, use that instead of the home @@ -46,7 +44,6 @@ def test_config_location_s3(self): self.assertEqual(expected_result, given_result) - @unittest.skip # Need to fix SettingsManager for this to work right. def test_create_config_file(self): """ Testing that if the config file does not exist, it is created.