Skip to content

Commit 4bd793f

Browse files
committed
Trying for 0.4.3
Issue with config files and lambda remained. Trying another method to work with it.
1 parent c9ca5a9 commit 4bd793f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

process_tracker/utilities/settings.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Settings manager and configuration, both for initialization and reading.
22

33
import configparser
4+
import io
45
import logging
56
import os
67
from pathlib import Path
7-
import tempfile
88

99
from process_tracker.utilities.aws_utilities import AwsUtilities
1010

@@ -68,6 +68,10 @@ def __init__(self, config_location=None):
6868

6969
if exists:
7070
self.read_config_file()
71+
else:
72+
self.logger.info("Config file does not exist.")
73+
if not cloud:
74+
self.create_config_file()
7175

7276
def create_config_file(self):
7377
"""
@@ -100,17 +104,15 @@ def read_config_file(self):
100104
path=self.config_path
101105
) and self.aws_utils.determine_s3_file_exists(path=self.config_file):
102106

103-
temp_file = tempfile.NamedTemporaryFile()
104107
bucket_name = self.aws_utils.determine_bucket_name(path=self.config_path)
105108

106109
bucket = self.aws_utils.get_s3_bucket(bucket_name=bucket_name)
107110
key = self.aws_utils.determine_file_key(path=self.config_file)
108111

109-
bucket.download_file(key, temp_file.name)
112+
cfg = bucket.Object(key).get()
113+
cfg = io.TextIOWrapper(io.BytesIO(cfg["Body"].read()))
110114

111-
with open(temp_file.name, "r") as f:
112-
self.config.readfp(f)
113-
temp_file.close()
115+
self.config.readfp(cfg)
114116

115117
else:
116118

tests/utilities/test_settings_manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def setUpClass(cls):
1717

1818
cls.config = configparser.ConfigParser(allow_no_value=True)
1919

20-
@unittest.skip # Need to fix SettingsManager for this to work right.
2120
def test_config_location_set(self):
2221
"""
2322
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):
3231

3332
self.assertEqual(expected_result, given_result)
3433

35-
@unittest.skip # Need to fix SettingsManager for this to work right.
3634
def test_config_location_s3(self):
3735
"""
3836
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):
4644

4745
self.assertEqual(expected_result, given_result)
4846

49-
@unittest.skip # Need to fix SettingsManager for this to work right.
5047
def test_create_config_file(self):
5148
"""
5249
Testing that if the config file does not exist, it is created.

0 commit comments

Comments
 (0)