forked from noxlesh/pingmon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigmanager.py
More file actions
28 lines (22 loc) · 1000 Bytes
/
configmanager.py
File metadata and controls
28 lines (22 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import json
class PMConfig(object):
def __init__(self, config_filename="config.json"):
self.working_dir = os.path.dirname(os.path.abspath(__file__))
self.conf_file_path = '{}/{}'.format(self.working_dir, config_filename)
if os.path.exists(self.conf_file_path):
with open(self.conf_file_path, 'r') as config_file:
self.props = json.load(config_file)
else:
raise Exception('Can\'t open config file!')
def save(self):
with open(self.conf_file_path, 'w') as config_file:
config = json.dumps(self.props,
ensure_ascii=False, # It makes human readable a non-ascii str of the config
indent=2,
sort_keys=True)
config_file.write(config)
def get_pm_address(self):
return self.props['address'], self.props['port']
def get_db_config(self):
return self.props['db']