Skip to content

Commit 01997d9

Browse files
committed
Rewrote config loader as a class
1 parent d1ceba1 commit 01997d9

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

config_loader/__init__.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
import json
33

44

5-
def get(variable):
6-
try:
7-
with io.open('config.json', "r", encoding='UTF-8') as file:
8-
keys = json.load(file)
9-
if variable in keys:
10-
return keys[variable]
5+
class ConfigLoaderException(Exception):
6+
"""Custom docstring"""
7+
8+
9+
class ConfigLoader:
10+
def __init__(self, config_file):
11+
self.config_file = config_file
12+
self.variables = self.load_variables()
13+
14+
def load_variables(self):
15+
try:
16+
with io.open(self.config_file, "r", encoding='UTF-8') as file:
17+
keys = json.load(file)
18+
return keys
19+
except FileNotFoundError:
20+
raise ConfigLoaderException('No configuration file found.')
21+
22+
def get(self, variable):
23+
if variable in self.variables:
24+
return self.variables[variable]
25+
else:
1126
return None
12-
except FileNotFoundError:
13-
return None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='packages',
4-
version='1.0',
4+
version='1.1',
55
description='Python module for Jönköping University Librarys various helper packages',
66
url='https://github.com/JonkopingUniversityLibrary/python_packages',
77
author='Gustav Lindqvist',

0 commit comments

Comments
 (0)