-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/ghi-#1-configuration-reader' into develop
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
import os.path | ||
|
||
|
||
class ConfigReader(object): | ||
""" | ||
Snowblock configuration file reader. | ||
""" | ||
def __init__(self, config_file_path): | ||
self._config = self._read(config_file_path) | ||
|
||
def _read(self, config_file_path): | ||
""" | ||
Reads the specified configuration file. | ||
:param config_file_path: The path to the configuration file to read | ||
:return: The read configuration data | ||
""" | ||
try: | ||
_, ext = os.path.splitext(config_file_path) | ||
with open(config_file_path) as fin: | ||
data = json.load(fin) | ||
return data | ||
except Exception as e: | ||
raise ReadingError('Could not read config file:\n{}'.format(e)) | ||
|
||
def get_config(self): | ||
""" | ||
Gets the snowblock configuration data. | ||
:return: The read snowblock configuration data | ||
""" | ||
return self._config | ||
|
||
|
||
class ReadingError(Exception): | ||
pass |