Skip to content

Commit

Permalink
Trying for 0.4.3
Browse files Browse the repository at this point in the history
Issue with config files and lambda remained.  Trying another method to
work with it.
  • Loading branch information
OpenDataAlex committed Jun 23, 2019
1 parent c9ca5a9 commit 4bd793f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 8 additions & 6 deletions process_tracker/utilities/settings.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:

Expand Down
3 changes: 0 additions & 3 deletions tests/utilities/test_settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 4bd793f

Please sign in to comment.